What's new? | Help | Directory | Sign in
Google
             
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
// Copyright 2006, Google Inc.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// 3. Neither the name of Google Inc. nor the names of its contributors may be
// used to endorse or promote products derived from this software without
// specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#ifndef GEARS_LOCALSERVER_IE_ASYNC_TASK_IE_H__
#define GEARS_LOCALSERVER_IE_ASYNC_TASK_IE_H__

#include <atlsync.h>
#include <vector>
#include "gears/base/common/browsing_context.h"
#include "gears/base/common/string16.h"
#include "gears/base/ie/atl_headers.h" // include this before other ATL headers
#include "gears/localserver/common/critical_section.h"
#include "gears/localserver/common/http_request.h"
#include "gears/localserver/common/resource_store.h"

class BlobInterface;

//------------------------------------------------------------------------------
// AsyncTask
//------------------------------------------------------------------------------
class AsyncTask : protected HttpRequest::HttpListener {
public:
// Starts a worker thread which will call the Run method
bool Start();

// Gracefully aborts a worker thread that was previously started
void Abort();

// Instructs the AsyncTask to delete itself when the worker thread terminates
void DeleteWhenDone();

// IE specific API
// Sets where notification messages will be sent.
void SetListenerWindow(HWND listener_window, int listener_message_base);

protected:
// Members that derived classes in common code depend on
// TODO(michaeln): perhaps define these in a interface IAsyncTask

static const char16 *kCookieRequiredErrorMessage;

AsyncTask(BrowsingContext *browsing_context);
virtual ~AsyncTask();

bool Init();
virtual void Run() = 0;

// Posts a message to our listener_window
void NotifyListener(int code, int param);

// Synchronously fetches a url on the worker thread. This should only
// be called on the Run method's thread of control.
//
// If 'is_capturing' is true, the custom "X-Gears-Google" header is
// added, and redirects will not be followed, rather the 30x response
// will be directly returned.
//
// If 'if_mode_since_date' is not null and not an empty string, the
// request will be a conditional HTTP GET.
//
// If 'required_cookie' is not null or empty, the presense of the
// cookie is tested prior to issueing the request. If the test fails
// the return value is false and 'error_message' will contain
// kCookieRequiredErrorMessage.
//
// Upon successful return, the 'payload' structure will contain the
// response. If redirection was followed, 'was_redirected' will be set
// to true, 'full_redirect_url' will contain the final location in
// the chain of redirects, and the 'payload' will contain the response
// for the final location. The 'was_redirected', 'full_redirect_url',
// and 'error_message' parameters may be null.
//
// If Abort() is called from another thread of control while a request
// is pending, the request is cancelled and HttpGet will return
// shortly thereafter.

// 'payload.data' will not be initialized upon return. Instead, the
// response body will be contained by the 'payload_data' Blob.
// TODO(andreip): remove payload_data argument once
// WebCacheDB::PayloadInfo.data is a Blob.
bool HttpGet(const char16 *full_url,
bool is_capturing,
const char16 *reason_header_value,
const char16 *if_mod_since_date,
const char16 *required_cookie,
WebCacheDB::PayloadInfo *payload,
scoped_refptr<BlobInterface> *payload_data,
bool *was_redirected,
std::string16 *full_redirect_url,
std::string16 *error_message);

// As HttpGet, but for POST.
bool HttpPost(const char16 *full_url,
bool is_capturing,
const char16 *reason_header_value,
const char16 *if_mod_since_date,
const char16 *required_cookie,
bool disable_browser_cookies,
BlobInterface *post_body,
WebCacheDB::PayloadInfo *payload,
scoped_refptr<BlobInterface> *payload_data,
bool *was_redirected,
std::string16 *full_redirect_url,
std::string16 *error_message);

CriticalSection lock_;
bool is_aborted_;
bool is_initialized_;
scoped_refptr<BrowsingContext> browsing_context_;

private:
// Implementation of HttpGet and HttpPost.
bool MakeHttpRequest(const char16 *method,
const char16 *full_url,
bool is_capturing,
const char16 *reason_header_value,
const char16 *if_mod_since_date,
const char16 *required_cookie,
bool disable_browser_cookies,
BlobInterface *post_body,
WebCacheDB::PayloadInfo *payload,
scoped_refptr<BlobInterface> *payload_data,
bool *was_redirected,
std::string16 *full_redirect_url,
std::string16 *error_message);

// An HttpRequest listener callback
void ReadyStateChanged(HttpRequest *source);

static unsigned int _stdcall ThreadMain(void *self);

bool delete_when_done_;
HWND listener_window_;
int listener_message_base_;
HANDLE thread_;
CEvent abort_event_;
CEvent ready_state_changed_event_;
};

#endif // GEARS_LOCALSERVER_IE_ASYNC_TASK_IE_H__
Show details Hide details

Change log

r2577 by gears.daemon on Aug 04, 2008   Diff
[Author: steveblock]

Adds to HttpRequest and
AsyncTask::HttpPost the ability to disable
sending browser cookies with the request.
This option is not exposed through
AsyncTask::HttpGet simply to avoid code
churn at call sites, but could eaily be
exposed there too.

R=andreip
CC=gears-eng@googlegroups.com
...
Go to: 
Project members, sign in to write a code review

Older revisions

r2369 by gears.daemon on Jul 15, 2008   Diff
[Author: andreip]

AsyncTask returns the response body as
a BlobInterface.

...
r1936 by gears.daemon on Jun 11, 2008   Diff
[Author: fry]

make blob support official!

PRESUBMIT=passed
...
r1814 by gears.daemon on May 30, 2008   Diff
[Author: mpcomplete]

Add BrowsingContext to associate with
network requests.

...
All revisions of this file

File info

Size: 6774 bytes, 162 lines