| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #if defined(BROWSER_SYNC) | 5 #if defined(BROWSER_SYNC) |
| 6 | 6 |
| 7 #ifndef CHROME_BROWSER_SYNC_GLUE_HTTP_BRIDGE_H_ | 7 #ifndef CHROME_BROWSER_SYNC_GLUE_HTTP_BRIDGE_H_ |
| 8 #define CHROME_BROWSER_SYNC_GLUE_HTTP_BRIDGE_H_ | 8 #define CHROME_BROWSER_SYNC_GLUE_HTTP_BRIDGE_H_ |
| 9 | 9 |
| 10 #include <string> | 10 #include <string> |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 std::string user_agent_; | 90 std::string user_agent_; |
| 91 | 91 |
| 92 scoped_refptr<URLRequestContextGetter> baseline_context_getter_; | 92 scoped_refptr<URLRequestContextGetter> baseline_context_getter_; |
| 93 | 93 |
| 94 // Lazily initialized by GetURLRequestContext(). | 94 // Lazily initialized by GetURLRequestContext(). |
| 95 scoped_refptr<RequestContext> context_; | 95 scoped_refptr<RequestContext> context_; |
| 96 | 96 |
| 97 DISALLOW_COPY_AND_ASSIGN(RequestContextGetter); | 97 DISALLOW_COPY_AND_ASSIGN(RequestContextGetter); |
| 98 }; | 98 }; |
| 99 | 99 |
| 100 HttpBridge(RequestContextGetter* context, MessageLoop* io_loop); | 100 HttpBridge(RequestContextGetter* context); |
| 101 virtual ~HttpBridge(); | 101 virtual ~HttpBridge(); |
| 102 | 102 |
| 103 // sync_api::HttpPostProvider implementation. | 103 // sync_api::HttpPostProvider implementation. |
| 104 virtual void SetUserAgent(const char* user_agent); | 104 virtual void SetUserAgent(const char* user_agent); |
| 105 virtual void SetExtraRequestHeaders(const char* headers); | 105 virtual void SetExtraRequestHeaders(const char* headers); |
| 106 virtual void SetURL(const char* url, int port); | 106 virtual void SetURL(const char* url, int port); |
| 107 virtual void SetPostPayload(const char* content_type, int content_length, | 107 virtual void SetPostPayload(const char* content_type, int content_length, |
| 108 const char* content); | 108 const char* content); |
| 109 virtual bool MakeSynchronousPost(int* os_error_code, int* response_code); | 109 virtual bool MakeSynchronousPost(int* os_error_code, int* response_code); |
| 110 | 110 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 128 } | 128 } |
| 129 #endif | 129 #endif |
| 130 | 130 |
| 131 protected: | 131 protected: |
| 132 // Protected virtual so the unit test can override to shunt network requests. | 132 // Protected virtual so the unit test can override to shunt network requests. |
| 133 virtual void MakeAsynchronousPost(); | 133 virtual void MakeAsynchronousPost(); |
| 134 | 134 |
| 135 private: | 135 private: |
| 136 friend class ::HttpBridgeTest; | 136 friend class ::HttpBridgeTest; |
| 137 | 137 |
| 138 // Called on the io_loop_ to issue the network request. The extra level | 138 // Called on the IO loop to issue the network request. The extra level |
| 139 // of indirection is so that the unit test can override this behavior but we | 139 // of indirection is so that the unit test can override this behavior but we |
| 140 // still have a function to statically pass to PostTask. | 140 // still have a function to statically pass to PostTask. |
| 141 void CallMakeAsynchronousPost() { MakeAsynchronousPost(); } | 141 void CallMakeAsynchronousPost() { MakeAsynchronousPost(); } |
| 142 | 142 |
| 143 // Gets a customized URLRequestContext for bridged requests. See | 143 // Gets a customized URLRequestContext for bridged requests. See |
| 144 // RequestContext definition for details. | 144 // RequestContext definition for details. |
| 145 RequestContextGetter* context_getter_for_request_; | 145 RequestContextGetter* context_getter_for_request_; |
| 146 | 146 |
| 147 // Our hook into the network layer is a URLFetcher. USED ONLY ON THE IO LOOP, | 147 // Our hook into the network layer is a URLFetcher. USED ONLY ON THE IO LOOP, |
| 148 // so we can block created_on_loop_ while the fetch is in progress. | 148 // so we can block created_on_loop_ while the fetch is in progress. |
| 149 // NOTE: This is not a scoped_ptr for a reason. It must be deleted on the same | 149 // NOTE: This is not a scoped_ptr for a reason. It must be deleted on the same |
| 150 // thread that created it, which isn't the same thread |this| gets deleted on. | 150 // thread that created it, which isn't the same thread |this| gets deleted on. |
| 151 // We must manually delete url_poster_ on the io_loop_. | 151 // We must manually delete url_poster_ on the IO loop. |
| 152 URLFetcher* url_poster_; | 152 URLFetcher* url_poster_; |
| 153 | 153 |
| 154 // The message loop of the thread we were created on. This is the thread that | 154 // The message loop of the thread we were created on. This is the thread that |
| 155 // will block on MakeSynchronousPost while the IO thread fetches data from | 155 // will block on MakeSynchronousPost while the IO thread fetches data from |
| 156 // the network. | 156 // the network. |
| 157 // This should be the main syncer thread (SyncerThread) which is what blocks | 157 // This should be the main syncer thread (SyncerThread) which is what blocks |
| 158 // on network IO through curl_easy_perform. | 158 // on network IO through curl_easy_perform. |
| 159 MessageLoop* const created_on_loop_; | 159 MessageLoop* const created_on_loop_; |
| 160 | 160 |
| 161 // Member variable for the IO loop instead of asking ChromeThread directly, | |
| 162 // done this way for testability. | |
| 163 MessageLoop* const io_loop_; | |
| 164 | |
| 165 // The URL to POST to. | 161 // The URL to POST to. |
| 166 GURL url_for_request_; | 162 GURL url_for_request_; |
| 167 | 163 |
| 168 // POST payload information. | 164 // POST payload information. |
| 169 std::string content_type_; | 165 std::string content_type_; |
| 170 std::string request_content_; | 166 std::string request_content_; |
| 171 std::string extra_headers_; | 167 std::string extra_headers_; |
| 172 | 168 |
| 173 // Cached response data. | 169 // Cached response data. |
| 174 bool request_completed_; | 170 bool request_completed_; |
| 175 bool request_succeeded_; | 171 bool request_succeeded_; |
| 176 int http_response_code_; | 172 int http_response_code_; |
| 177 int os_error_code_; | 173 int os_error_code_; |
| 178 std::string response_content_; | 174 std::string response_content_; |
| 179 | 175 |
| 180 // A waitable event we use to provide blocking semantics to | 176 // A waitable event we use to provide blocking semantics to |
| 181 // MakeSynchronousPost. We block created_on_loop_ while the io_loop_ fetches | 177 // MakeSynchronousPost. We block created_on_loop_ while the IO loop fetches |
| 182 // network request. | 178 // network request. |
| 183 base::WaitableEvent http_post_completed_; | 179 base::WaitableEvent http_post_completed_; |
| 184 | 180 |
| 185 // This is here so that the unit test subclass can force our URLFetcher to | |
| 186 // use the io_loop_ passed on construction for network requests, rather than | |
| 187 // ChromeThread::IO's message loop (which won't exist in testing). | |
| 188 bool use_io_loop_for_testing_; | |
| 189 | |
| 190 DISALLOW_COPY_AND_ASSIGN(HttpBridge); | 181 DISALLOW_COPY_AND_ASSIGN(HttpBridge); |
| 191 }; | 182 }; |
| 192 | 183 |
| 193 class HttpBridgeFactory | 184 class HttpBridgeFactory |
| 194 : public sync_api::HttpPostProviderFactory { | 185 : public sync_api::HttpPostProviderFactory { |
| 195 public: | 186 public: |
| 196 explicit HttpBridgeFactory(URLRequestContextGetter* baseline_context_getter); | 187 explicit HttpBridgeFactory(URLRequestContextGetter* baseline_context_getter); |
| 197 virtual ~HttpBridgeFactory(); | 188 virtual ~HttpBridgeFactory(); |
| 198 virtual sync_api::HttpPostProviderInterface* Create(); | 189 virtual sync_api::HttpPostProviderInterface* Create(); |
| 199 virtual void Destroy(sync_api::HttpPostProviderInterface* http); | 190 virtual void Destroy(sync_api::HttpPostProviderInterface* http); |
| 200 private: | 191 private: |
| 201 // This request context is built on top of the baseline context and shares | 192 // This request context is built on top of the baseline context and shares |
| 202 // common components. | 193 // common components. |
| 203 HttpBridge::RequestContextGetter* GetRequestContextGetter(); | 194 HttpBridge::RequestContextGetter* GetRequestContextGetter(); |
| 204 // We must Release() this from the IO thread. | 195 // We must Release() this from the IO thread. |
| 205 HttpBridge::RequestContextGetter* request_context_getter_; | 196 HttpBridge::RequestContextGetter* request_context_getter_; |
| 206 DISALLOW_COPY_AND_ASSIGN(HttpBridgeFactory); | 197 DISALLOW_COPY_AND_ASSIGN(HttpBridgeFactory); |
| 207 }; | 198 }; |
| 208 | 199 |
| 209 } // namespace browser_sync | 200 } // namespace browser_sync |
| 210 | 201 |
| 211 #endif // CHROME_BROWSER_SYNC_GLUE_HTTP_BRIDGE_H_ | 202 #endif // CHROME_BROWSER_SYNC_GLUE_HTTP_BRIDGE_H_ |
| 212 | 203 |
| 213 #endif // defined(BROWSER_SYNC) | 204 #endif // defined(BROWSER_SYNC) |
| OLD | NEW |