| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 CHROME_BROWSER_SYNC_GLUE_HTTP_BRIDGE_H_ | 5 #ifndef CHROME_BROWSER_SYNC_GLUE_HTTP_BRIDGE_H_ |
| 6 #define CHROME_BROWSER_SYNC_GLUE_HTTP_BRIDGE_H_ | 6 #define CHROME_BROWSER_SYNC_GLUE_HTTP_BRIDGE_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 }; | 96 }; |
| 97 | 97 |
| 98 explicit HttpBridge(RequestContextGetter* context); | 98 explicit HttpBridge(RequestContextGetter* context); |
| 99 | 99 |
| 100 // sync_api::HttpPostProvider implementation. | 100 // sync_api::HttpPostProvider implementation. |
| 101 virtual void SetUserAgent(const char* user_agent); | 101 virtual void SetUserAgent(const char* user_agent); |
| 102 virtual void SetExtraRequestHeaders(const char* headers); | 102 virtual void SetExtraRequestHeaders(const char* headers); |
| 103 virtual void SetURL(const char* url, int port); | 103 virtual void SetURL(const char* url, int port); |
| 104 virtual void SetPostPayload(const char* content_type, int content_length, | 104 virtual void SetPostPayload(const char* content_type, int content_length, |
| 105 const char* content); | 105 const char* content); |
| 106 virtual bool MakeSynchronousPost(int* os_error_code, int* response_code); | 106 virtual bool MakeSynchronousPost(int* error_code, int* response_code); |
| 107 virtual void Abort(); | 107 virtual void Abort(); |
| 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 |
| 111 // GetResponseContentLength() characters when using GetResponseContent. e.g | 111 // GetResponseContentLength() characters when using GetResponseContent. e.g |
| 112 // string r(b->GetResponseContent(), b->GetResponseContentLength()). | 112 // string r(b->GetResponseContent(), b->GetResponseContentLength()). |
| 113 virtual int GetResponseContentLength() const; | 113 virtual int GetResponseContentLength() const; |
| 114 virtual const char* GetResponseContent() const; | 114 virtual const char* GetResponseContent() const; |
| 115 virtual const std::string GetResponseHeaderValue( | 115 virtual const std::string GetResponseHeaderValue( |
| 116 const std::string& name) const; | 116 const std::string& name) const; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 // deleted on. We must manually delete url_poster_ on the IO loop. | 179 // deleted on. We must manually delete url_poster_ on the IO loop. |
| 180 URLFetcher* url_poster; | 180 URLFetcher* url_poster; |
| 181 | 181 |
| 182 // Used to support 'Abort' functionality. | 182 // Used to support 'Abort' functionality. |
| 183 bool aborted; | 183 bool aborted; |
| 184 | 184 |
| 185 // Cached response data. | 185 // Cached response data. |
| 186 bool request_completed; | 186 bool request_completed; |
| 187 bool request_succeeded; | 187 bool request_succeeded; |
| 188 int http_response_code; | 188 int http_response_code; |
| 189 int os_error_code; | 189 int error_code; |
| 190 std::string response_content; | 190 std::string response_content; |
| 191 scoped_refptr<net::HttpResponseHeaders> response_headers; | 191 scoped_refptr<net::HttpResponseHeaders> response_headers; |
| 192 }; | 192 }; |
| 193 | 193 |
| 194 // This lock synchronizes use of state involved in the flow to fetch a URL | 194 // This lock synchronizes use of state involved in the flow to fetch a URL |
| 195 // using URLFetcher. Because we can Abort() from any thread, for example, | 195 // using URLFetcher. Because we can Abort() from any thread, for example, |
| 196 // this flow needs to be synchronized to gracefully clean up URLFetcher and | 196 // this flow needs to be synchronized to gracefully clean up URLFetcher and |
| 197 // return appropriate values in os_error_code. | 197 // return appropriate values in |error_code|. |
| 198 mutable base::Lock fetch_state_lock_; | 198 mutable base::Lock fetch_state_lock_; |
| 199 URLFetchState fetch_state_; | 199 URLFetchState fetch_state_; |
| 200 | 200 |
| 201 DISALLOW_COPY_AND_ASSIGN(HttpBridge); | 201 DISALLOW_COPY_AND_ASSIGN(HttpBridge); |
| 202 }; | 202 }; |
| 203 | 203 |
| 204 class HttpBridgeFactory : public sync_api::HttpPostProviderFactory { | 204 class HttpBridgeFactory : public sync_api::HttpPostProviderFactory { |
| 205 public: | 205 public: |
| 206 explicit HttpBridgeFactory( | 206 explicit HttpBridgeFactory( |
| 207 net::URLRequestContextGetter* baseline_context_getter); | 207 net::URLRequestContextGetter* baseline_context_getter); |
| 208 virtual ~HttpBridgeFactory(); | 208 virtual ~HttpBridgeFactory(); |
| 209 | 209 |
| 210 // sync_api::HttpPostProviderFactory: | 210 // sync_api::HttpPostProviderFactory: |
| 211 virtual sync_api::HttpPostProviderInterface* Create() OVERRIDE; | 211 virtual sync_api::HttpPostProviderInterface* Create() OVERRIDE; |
| 212 virtual void Destroy(sync_api::HttpPostProviderInterface* http) OVERRIDE; | 212 virtual void Destroy(sync_api::HttpPostProviderInterface* http) OVERRIDE; |
| 213 | 213 |
| 214 private: | 214 private: |
| 215 // This request context is built on top of the baseline context and shares | 215 // This request context is built on top of the baseline context and shares |
| 216 // common components. | 216 // common components. |
| 217 HttpBridge::RequestContextGetter* GetRequestContextGetter(); | 217 HttpBridge::RequestContextGetter* GetRequestContextGetter(); |
| 218 | 218 |
| 219 scoped_refptr<HttpBridge::RequestContextGetter> request_context_getter_; | 219 scoped_refptr<HttpBridge::RequestContextGetter> request_context_getter_; |
| 220 | 220 |
| 221 DISALLOW_COPY_AND_ASSIGN(HttpBridgeFactory); | 221 DISALLOW_COPY_AND_ASSIGN(HttpBridgeFactory); |
| 222 }; | 222 }; |
| 223 | 223 |
| 224 } // namespace browser_sync | 224 } // namespace browser_sync |
| 225 | 225 |
| 226 #endif // CHROME_BROWSER_SYNC_GLUE_HTTP_BRIDGE_H_ | 226 #endif // CHROME_BROWSER_SYNC_GLUE_HTTP_BRIDGE_H_ |
| OLD | NEW |