| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef SYNC_INTERNAL_API_PUBLIC_HTTP_BRIDGE_H_ | 5 #ifndef SYNC_INTERNAL_API_PUBLIC_HTTP_BRIDGE_H_ |
| 6 #define SYNC_INTERNAL_API_PUBLIC_HTTP_BRIDGE_H_ | 6 #define SYNC_INTERNAL_API_PUBLIC_HTTP_BRIDGE_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 | 30 |
| 31 namespace syncer { | 31 namespace syncer { |
| 32 | 32 |
| 33 // A bridge between the syncer and Chromium HTTP layers. | 33 // A bridge between the syncer and Chromium HTTP layers. |
| 34 // Provides a way for the sync backend to use Chromium directly for HTTP | 34 // Provides a way for the sync backend to use Chromium directly for HTTP |
| 35 // requests rather than depending on a third party provider (e.g libcurl). | 35 // requests rather than depending on a third party provider (e.g libcurl). |
| 36 // This is a one-time use bridge. Create one for each request you want to make. | 36 // This is a one-time use bridge. Create one for each request you want to make. |
| 37 // It is RefCountedThreadSafe because it can PostTask to the io loop, and thus | 37 // It is RefCountedThreadSafe because it can PostTask to the io loop, and thus |
| 38 // needs to stick around across context switches, etc. | 38 // needs to stick around across context switches, etc. |
| 39 class HttpBridge : public base::RefCountedThreadSafe<HttpBridge>, | 39 class HttpBridge : public base::RefCountedThreadSafe<HttpBridge>, |
| 40 public syncer::HttpPostProviderInterface, | 40 public HttpPostProviderInterface, |
| 41 public net::URLFetcherDelegate { | 41 public net::URLFetcherDelegate { |
| 42 public: | 42 public: |
| 43 // A request context used for HTTP requests bridged from the sync backend. | 43 // A request context used for HTTP requests bridged from the sync backend. |
| 44 // A bridged RequestContext has a dedicated in-memory cookie store and does | 44 // A bridged RequestContext has a dedicated in-memory cookie store and does |
| 45 // not use a cache. Thus the same type can be used for incognito mode. | 45 // not use a cache. Thus the same type can be used for incognito mode. |
| 46 class RequestContext : public net::URLRequestContext { | 46 class RequestContext : public net::URLRequestContext { |
| 47 public: | 47 public: |
| 48 // |baseline_context| is used to obtain the accept-language, | 48 // |baseline_context| is used to obtain the accept-language, |
| 49 // accept-charsets, and proxy service information for bridged requests. | 49 // accept-charsets, and proxy service information for bridged requests. |
| 50 // Typically |baseline_context| should be the net::URLRequestContext of the | 50 // Typically |baseline_context| should be the net::URLRequestContext of the |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 const std::string user_agent_; | 90 const std::string user_agent_; |
| 91 | 91 |
| 92 // Lazily initialized by GetURLRequestContext(). | 92 // Lazily initialized by GetURLRequestContext(). |
| 93 scoped_ptr<RequestContext> context_; | 93 scoped_ptr<RequestContext> context_; |
| 94 | 94 |
| 95 DISALLOW_COPY_AND_ASSIGN(RequestContextGetter); | 95 DISALLOW_COPY_AND_ASSIGN(RequestContextGetter); |
| 96 }; | 96 }; |
| 97 | 97 |
| 98 explicit HttpBridge(RequestContextGetter* context); | 98 explicit HttpBridge(RequestContextGetter* context); |
| 99 | 99 |
| 100 // syncer::HttpPostProvider implementation. | 100 // HttpPostProvider implementation. |
| 101 virtual void SetExtraRequestHeaders(const char* headers) OVERRIDE; | 101 virtual void SetExtraRequestHeaders(const char* headers) OVERRIDE; |
| 102 virtual void SetURL(const char* url, int port) OVERRIDE; | 102 virtual void SetURL(const char* url, int port) OVERRIDE; |
| 103 virtual void SetPostPayload(const char* content_type, int content_length, | 103 virtual void SetPostPayload(const char* content_type, int content_length, |
| 104 const char* content) OVERRIDE; | 104 const char* content) OVERRIDE; |
| 105 virtual bool MakeSynchronousPost(int* error_code, | 105 virtual bool MakeSynchronousPost(int* error_code, |
| 106 int* response_code) OVERRIDE; | 106 int* response_code) OVERRIDE; |
| 107 virtual void Abort() OVERRIDE; | 107 virtual void Abort() OVERRIDE; |
| 108 | 108 |
| 109 // WARNING: these response content methods are used to extract plain old data | 109 // WARNING: these response content methods are used to extract plain old data |
| 110 // and not null terminated strings, so you should make sure you have read | 110 // and not null terminated strings, so you should make sure you have read |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 // This lock synchronizes use of state involved in the flow to fetch a URL | 197 // This lock synchronizes use of state involved in the flow to fetch a URL |
| 198 // using URLFetcher. Because we can Abort() from any thread, for example, | 198 // using URLFetcher. Because we can Abort() from any thread, for example, |
| 199 // this flow needs to be synchronized to gracefully clean up URLFetcher and | 199 // this flow needs to be synchronized to gracefully clean up URLFetcher and |
| 200 // return appropriate values in |error_code|. | 200 // return appropriate values in |error_code|. |
| 201 mutable base::Lock fetch_state_lock_; | 201 mutable base::Lock fetch_state_lock_; |
| 202 URLFetchState fetch_state_; | 202 URLFetchState fetch_state_; |
| 203 | 203 |
| 204 DISALLOW_COPY_AND_ASSIGN(HttpBridge); | 204 DISALLOW_COPY_AND_ASSIGN(HttpBridge); |
| 205 }; | 205 }; |
| 206 | 206 |
| 207 class HttpBridgeFactory : public syncer::HttpPostProviderFactory { | 207 class HttpBridgeFactory : public HttpPostProviderFactory { |
| 208 public: | 208 public: |
| 209 HttpBridgeFactory( | 209 HttpBridgeFactory( |
| 210 net::URLRequestContextGetter* baseline_context_getter, | 210 net::URLRequestContextGetter* baseline_context_getter, |
| 211 const std::string& user_agent); | 211 const std::string& user_agent); |
| 212 virtual ~HttpBridgeFactory(); | 212 virtual ~HttpBridgeFactory(); |
| 213 | 213 |
| 214 // syncer::HttpPostProviderFactory: | 214 // HttpPostProviderFactory: |
| 215 virtual syncer::HttpPostProviderInterface* Create() OVERRIDE; | 215 virtual HttpPostProviderInterface* Create() OVERRIDE; |
| 216 virtual void Destroy(syncer::HttpPostProviderInterface* http) OVERRIDE; | 216 virtual void Destroy(HttpPostProviderInterface* http) OVERRIDE; |
| 217 | 217 |
| 218 private: | 218 private: |
| 219 // This request context is built on top of the baseline context and shares | 219 // This request context is built on top of the baseline context and shares |
| 220 // common components. | 220 // common components. |
| 221 HttpBridge::RequestContextGetter* GetRequestContextGetter(); | 221 HttpBridge::RequestContextGetter* GetRequestContextGetter(); |
| 222 | 222 |
| 223 const scoped_refptr<HttpBridge::RequestContextGetter> | 223 const scoped_refptr<HttpBridge::RequestContextGetter> |
| 224 request_context_getter_; | 224 request_context_getter_; |
| 225 | 225 |
| 226 DISALLOW_COPY_AND_ASSIGN(HttpBridgeFactory); | 226 DISALLOW_COPY_AND_ASSIGN(HttpBridgeFactory); |
| 227 }; | 227 }; |
| 228 | 228 |
| 229 } // namespace syncer | 229 } // namespace syncer |
| 230 | 230 |
| 231 #endif // SYNC_INTERNAL_API_PUBLIC_HTTP_BRIDGE_H_ | 231 #endif // SYNC_INTERNAL_API_PUBLIC_HTTP_BRIDGE_H_ |
| OLD | NEW |