| 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 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/synchronization/lock.h" | 14 #include "base/synchronization/lock.h" |
| 15 #include "base/synchronization/waitable_event.h" | 15 #include "base/synchronization/waitable_event.h" |
| 16 #include "chrome/browser/sync/internal_api/http_post_provider_factory.h" | 16 #include "chrome/browser/sync/internal_api/http_post_provider_factory.h" |
| 17 #include "chrome/browser/sync/internal_api/http_post_provider_interface.h" | 17 #include "chrome/browser/sync/internal_api/http_post_provider_interface.h" |
| 18 #include "content/common/net/url_fetcher.h" | 18 #include "content/public/common/url_fetcher_delegate.h" |
| 19 #include "googleurl/src/gurl.h" | 19 #include "googleurl/src/gurl.h" |
| 20 #include "net/url_request/url_request_context_getter.h" | 20 #include "net/url_request/url_request_context_getter.h" |
| 21 #include "net/url_request/url_request_context.h" | 21 #include "net/url_request/url_request_context.h" |
| 22 #include "testing/gtest/include/gtest/gtest_prod.h" | 22 #include "testing/gtest/include/gtest/gtest_prod.h" |
| 23 | 23 |
| 24 class MessageLoop; | 24 class MessageLoop; |
| 25 class HttpBridgeTest; | 25 class HttpBridgeTest; |
| 26 | 26 |
| 27 namespace net { |
| 28 class HttpResponseHeaders; |
| 29 } |
| 30 |
| 27 namespace browser_sync { | 31 namespace browser_sync { |
| 28 | 32 |
| 29 // A bridge between the syncer and Chromium HTTP layers. | 33 // A bridge between the syncer and Chromium HTTP layers. |
| 30 // 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 |
| 31 // 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). |
| 32 // 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. |
| 33 // 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 |
| 34 // needs to stick around across context switches, etc. | 38 // needs to stick around across context switches, etc. |
| 35 class HttpBridge : public base::RefCountedThreadSafe<HttpBridge>, | 39 class HttpBridge : public base::RefCountedThreadSafe<HttpBridge>, |
| 36 public sync_api::HttpPostProviderInterface, | 40 public sync_api::HttpPostProviderInterface, |
| 37 public URLFetcher::Delegate { | 41 public content::URLFetcherDelegate { |
| 38 public: | 42 public: |
| 39 // 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. |
| 40 // 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 |
| 41 // 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. |
| 42 class RequestContext : public net::URLRequestContext { | 46 class RequestContext : public net::URLRequestContext { |
| 43 public: | 47 public: |
| 44 // |baseline_context| is used to obtain the accept-language, | 48 // |baseline_context| is used to obtain the accept-language, |
| 45 // accept-charsets, and proxy service information for bridged requests. | 49 // accept-charsets, and proxy service information for bridged requests. |
| 46 // Typically |baseline_context| should be the net::URLRequestContext of the | 50 // Typically |baseline_context| should be the net::URLRequestContext of the |
| 47 // currently active profile. | 51 // currently active profile. |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 | 112 |
| 109 // WARNING: these response content methods are used to extract plain old data | 113 // 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 | 114 // and not null terminated strings, so you should make sure you have read |
| 111 // GetResponseContentLength() characters when using GetResponseContent. e.g | 115 // GetResponseContentLength() characters when using GetResponseContent. e.g |
| 112 // string r(b->GetResponseContent(), b->GetResponseContentLength()). | 116 // string r(b->GetResponseContent(), b->GetResponseContentLength()). |
| 113 virtual int GetResponseContentLength() const; | 117 virtual int GetResponseContentLength() const; |
| 114 virtual const char* GetResponseContent() const; | 118 virtual const char* GetResponseContent() const; |
| 115 virtual const std::string GetResponseHeaderValue( | 119 virtual const std::string GetResponseHeaderValue( |
| 116 const std::string& name) const; | 120 const std::string& name) const; |
| 117 | 121 |
| 118 // URLFetcher::Delegate implementation. | 122 // content::URLFetcherDelegate implementation. |
| 119 virtual void OnURLFetchComplete(const URLFetcher* source, | 123 virtual void OnURLFetchComplete(const URLFetcher* source); |
| 120 const GURL& url, | |
| 121 const net::URLRequestStatus& status, | |
| 122 int response_code, | |
| 123 const net::ResponseCookies& cookies, | |
| 124 const std::string& data); | |
| 125 | 124 |
| 126 #if defined(UNIT_TEST) | 125 #if defined(UNIT_TEST) |
| 127 net::URLRequestContextGetter* GetRequestContextGetter() const { | 126 net::URLRequestContextGetter* GetRequestContextGetter() const { |
| 128 return context_getter_for_request_; | 127 return context_getter_for_request_; |
| 129 } | 128 } |
| 130 #endif | 129 #endif |
| 131 | 130 |
| 132 protected: | 131 protected: |
| 133 friend class base::RefCountedThreadSafe<HttpBridge>; | 132 friend class base::RefCountedThreadSafe<HttpBridge>; |
| 134 | 133 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 HttpBridge::RequestContextGetter* GetRequestContextGetter(); | 216 HttpBridge::RequestContextGetter* GetRequestContextGetter(); |
| 218 | 217 |
| 219 scoped_refptr<HttpBridge::RequestContextGetter> request_context_getter_; | 218 scoped_refptr<HttpBridge::RequestContextGetter> request_context_getter_; |
| 220 | 219 |
| 221 DISALLOW_COPY_AND_ASSIGN(HttpBridgeFactory); | 220 DISALLOW_COPY_AND_ASSIGN(HttpBridgeFactory); |
| 222 }; | 221 }; |
| 223 | 222 |
| 224 } // namespace browser_sync | 223 } // namespace browser_sync |
| 225 | 224 |
| 226 #endif // CHROME_BROWSER_SYNC_GLUE_HTTP_BRIDGE_H_ | 225 #endif // CHROME_BROWSER_SYNC_GLUE_HTTP_BRIDGE_H_ |
| OLD | NEW |