| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_AUTH_REQUES
T_HANDLER_H_ | 5 #ifndef COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_AUTH_REQUES
T_HANDLER_H_ |
| 6 #define COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_AUTH_REQUES
T_HANDLER_H_ | 6 #define COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_AUTH_REQUES
T_HANDLER_H_ |
| 7 | 7 |
| 8 #include "base/gtest_prod_util.h" | 8 #include "base/gtest_prod_util.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
| 11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
| 12 #include "url/gurl.h" | 12 #include "url/gurl.h" |
| 13 | 13 |
| 14 namespace base { |
| 15 class SingleThreadTaskRunner; |
| 16 } |
| 17 |
| 14 namespace net { | 18 namespace net { |
| 15 class HttpRequestHeaders; | 19 class HttpRequestHeaders; |
| 16 class HttpResponseHeaders; | 20 class HttpResponseHeaders; |
| 17 class ProxyServer; | 21 class ProxyServer; |
| 18 class URLRequest; | 22 class URLRequest; |
| 19 } | 23 } |
| 20 | 24 |
| 21 namespace data_reduction_proxy { | 25 namespace data_reduction_proxy { |
| 22 | 26 |
| 23 #if defined(OS_ANDROID) | 27 #if defined(OS_ANDROID) |
| 24 extern const char kAndroidWebViewProtocolVersion[]; | 28 extern const char kAndroidWebViewProtocolVersion[]; |
| 25 #endif | 29 #endif |
| 26 | 30 |
| 27 extern const char kClientAndroidWebview[]; | 31 extern const char kClientAndroidWebview[]; |
| 28 extern const char kClientChromeAndroid[]; | 32 extern const char kClientChromeAndroid[]; |
| 29 extern const char kClientChromeIOS[]; | 33 extern const char kClientChromeIOS[]; |
| 30 | 34 |
| 31 class DataReductionProxyParams; | 35 class DataReductionProxyParams; |
| 32 | 36 |
| 33 class DataReductionProxyAuthRequestHandler { | 37 class DataReductionProxyAuthRequestHandler { |
| 34 public: | 38 public: |
| 35 static bool IsKeySetOnCommandLine(); | 39 static bool IsKeySetOnCommandLine(); |
| 36 | 40 |
| 37 // Constructs an authentication request handler. Client is the canonical name | |
| 38 // for the client. Client names should be defined in this file as one of | |
| 39 // |kClient...|. Version is the authentication protocol version that the | |
| 40 // client uses, which should be |kProtocolVersion| unless the client expects | |
| 41 // to be handled differently from the standard behavior. | |
| 42 DataReductionProxyAuthRequestHandler( | 41 DataReductionProxyAuthRequestHandler( |
| 43 const std::string& client, | 42 const std::string& client, |
| 44 const std::string& version, | 43 const std::string& version, |
| 45 DataReductionProxyParams* params); | 44 DataReductionProxyParams* params, |
| 45 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner); |
| 46 | 46 |
| 47 virtual ~DataReductionProxyAuthRequestHandler(); | 47 virtual ~DataReductionProxyAuthRequestHandler(); |
| 48 | 48 |
| 49 // Adds a 'Chrome-Proxy' header to |request_headers| with the data reduction | 49 // Adds a 'Chrome-Proxy' header to |request_headers| with the data reduction |
| 50 // proxy authentication credentials. Only adds this header if the provided | 50 // proxy authentication credentials. Only adds this header if the provided |
| 51 // |proxy_server| is a data reduction proxy. | 51 // |proxy_server| is a data reduction proxy. Must be called on the IO thread. |
| 52 void MaybeAddRequestHeader(net::URLRequest* request, | 52 void MaybeAddRequestHeader(net::URLRequest* request, |
| 53 const net::ProxyServer& proxy_server, | 53 const net::ProxyServer& proxy_server, |
| 54 net::HttpRequestHeaders* request_headers); | 54 net::HttpRequestHeaders* request_headers); |
| 55 | 55 |
| 56 // Sets a new authentication key. This must be called for platforms that do | 56 // Sets a new authentication key. This must be called for platforms that do |
| 57 // not have a default key defined. See the constructor implementation for | 57 // not have a default key defined. See the constructor implementation for |
| 58 // those platforms. | 58 // those platforms. Must be called on the UI thread. |
| 59 void SetKey(const std::string& key); | 59 void SetKeyOnUI(const std::string& key); |
| 60 | 60 |
| 61 protected: | 61 protected: |
| 62 void Init(); | 62 void Init(); |
| 63 void InitAuthentication(const std::string& key); | 63 void InitAuthenticationOnUI(const std::string& key); |
| 64 | 64 |
| 65 void AddAuthorizationHeader(net::HttpRequestHeaders* headers); | 65 void AddAuthorizationHeader(net::HttpRequestHeaders* headers); |
| 66 | 66 |
| 67 // Returns a UTF16 string that's the hash of the configured authentication | 67 // Returns a UTF16 string that's the hash of the configured authentication |
| 68 // |key| and |salt|. Returns an empty UTF16 string if no key is configured or | 68 // |key| and |salt|. Returns an empty UTF16 string if no key is configured or |
| 69 // the data reduction proxy feature isn't available. | 69 // the data reduction proxy feature isn't available. |
| 70 static base::string16 AuthHashForSalt(int64 salt, | 70 static base::string16 AuthHashForSalt(int64 salt, |
| 71 const std::string& key); | 71 const std::string& key); |
| 72 // Visible for testing. | 72 // Visible for testing. |
| 73 virtual base::Time Now() const; | 73 virtual base::Time Now() const; |
| 74 virtual void RandBytes(void* output, size_t length); | 74 virtual void RandBytes(void* output, size_t length); |
| 75 | 75 |
| 76 // Visible for testing. | 76 // Visible for testing. |
| 77 virtual std::string GetDefaultKey() const; | 77 virtual std::string GetDefaultKey() const; |
| 78 | 78 |
| 79 private: | 79 private: |
| 80 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyAuthRequestHandlerTest, | 80 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyAuthRequestHandlerTest, |
| 81 Authorization); | 81 Authorization); |
| 82 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyAuthRequestHandlerTest, | 82 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyAuthRequestHandlerTest, |
| 83 AuthHashForSalt); | 83 AuthHashForSalt); |
| 84 | 84 |
| 85 void InitAuthentication( |
| 86 const std::string& session, |
| 87 const std::string& credentials); |
| 88 |
| 85 // Authentication state. | 89 // Authentication state. |
| 86 std::string key_; | 90 std::string key_; |
| 91 |
| 92 // Lives on the IO thread. |
| 87 std::string session_; | 93 std::string session_; |
| 88 std::string credentials_; | 94 std::string credentials_; |
| 89 | 95 |
| 90 // Name of the client and version of the data reduction proxy protocol to use. | 96 // Name of the client and version of the data reduction proxy protocol to use. |
| 97 // Both live on the IO thread. |
| 91 std::string client_; | 98 std::string client_; |
| 92 std::string version_; | 99 std::string version_; |
| 93 | 100 |
| 94 DataReductionProxyParams* data_reduction_proxy_params_; | 101 DataReductionProxyParams* data_reduction_proxy_params_; |
| 95 | 102 |
| 103 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; |
| 104 |
| 96 DISALLOW_COPY_AND_ASSIGN(DataReductionProxyAuthRequestHandler); | 105 DISALLOW_COPY_AND_ASSIGN(DataReductionProxyAuthRequestHandler); |
| 97 }; | 106 }; |
| 98 | 107 |
| 99 } // namespace data_reduction_proxy | 108 } // namespace data_reduction_proxy |
| 100 #endif // COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_AUTH_REQ
UEST_HANDLER_H_ | 109 #endif // COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_AUTH_REQ
UEST_HANDLER_H_ |
| OLD | NEW |