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 MessageLoopProxy; | |
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 extern const char kProtocolVersion[]; | 27 extern const char kProtocolVersion[]; |
24 | 28 |
25 extern const char kClientAndroidWebview[]; | 29 extern const char kClientAndroidWebview[]; |
26 extern const char kClientChromeAndroid[]; | 30 extern const char kClientChromeAndroid[]; |
27 extern const char kClientChromeIOS[]; | 31 extern const char kClientChromeIOS[]; |
28 | 32 |
29 class DataReductionProxyParams; | 33 class DataReductionProxyParams; |
30 | 34 |
31 class DataReductionProxyAuthRequestHandler { | 35 class DataReductionProxyAuthRequestHandler { |
32 public: | 36 public: |
33 static bool IsKeySetOnCommandLine(); | 37 static bool IsKeySetOnCommandLine(); |
34 | 38 |
35 // Constructs an authentication request handler. | 39 // Constructs an authentication request handler. |
36 explicit DataReductionProxyAuthRequestHandler( | 40 explicit DataReductionProxyAuthRequestHandler( |
37 DataReductionProxyParams* params); | 41 DataReductionProxyParams* params, |
42 base::MessageLoopProxy* io_thread_proxy); | |
willchan no longer on Chromium
2014/07/31 22:31:35
Please use SingleThreadTaskRunner instead. MLP is
bengr
2014/08/02 01:10:32
Done.
| |
38 | 43 |
39 virtual ~DataReductionProxyAuthRequestHandler(); | 44 virtual ~DataReductionProxyAuthRequestHandler(); |
40 | 45 |
41 // Adds a 'Chrome-Proxy' header to |request_headers| with the data reduction | 46 // Adds a 'Chrome-Proxy' header to |request_headers| with the data reduction |
42 // proxy authentication credentials. Only adds this header if the provided | 47 // proxy authentication credentials. Only adds this header if the provided |
43 // |proxy_server| is a data reduction proxy. | 48 // |proxy_server| is a data reduction proxy. Must be called on the IO thread. |
44 void MaybeAddRequestHeader(net::URLRequest* request, | 49 void MaybeAddRequestHeader(net::URLRequest* request, |
45 const net::ProxyServer& proxy_server, | 50 const net::ProxyServer& proxy_server, |
46 net::HttpRequestHeaders* request_headers); | 51 net::HttpRequestHeaders* request_headers); |
47 | 52 |
48 // Sets a new authentication key. This must be called for platforms that do | 53 // Sets a new authentication key. This must be called for platforms that do |
49 // not have a default key defined. See the constructor implementation for | 54 // not have a default key defined. See the constructor implementation for |
50 // those platforms. Client is the canonical name for the client. Client names | 55 // those platforms. Client is the canonical name for the client. Client names |
51 // should be defined in this file as one of |kClient...|. Version is the | 56 // should be defined in this file as one of |kClient...|. Version is the |
52 // authentication protocol version that the client uses, which should be | 57 // authentication protocol version that the client uses, which should be |
53 // |kProtocolVersion| unless the client expects to be handled differently from | 58 // |kProtocolVersion| unless the client expects to be handled differently from |
54 // the standard behavior. | 59 // the standard behavior. Must be called on the UI Thread. |
willchan no longer on Chromium
2014/07/31 22:31:35
Since this object primarily lives on the IO thread
bengr
2014/08/02 01:10:32
Done.
| |
55 void SetKey(const std::string& key, | 60 void SetKey(const std::string& key, |
56 const std::string& client, | 61 const std::string& client, |
57 const std::string& version); | 62 const std::string& version); |
58 | 63 |
59 protected: | 64 protected: |
60 void Init(); | 65 void Init(); |
61 void InitAuthentication(const std::string& key); | 66 void InitAuthentication(const std::string& key, |
67 const std::string& client, | |
68 const std::string& version); | |
62 | 69 |
63 void AddAuthorizationHeader(net::HttpRequestHeaders* headers); | 70 void AddAuthorizationHeader(net::HttpRequestHeaders* headers); |
64 | 71 |
65 // Returns a UTF16 string that's the hash of the configured authentication | 72 // Returns a UTF16 string that's the hash of the configured authentication |
66 // |key| and |salt|. Returns an empty UTF16 string if no key is configured or | 73 // |key| and |salt|. Returns an empty UTF16 string if no key is configured or |
67 // the data reduction proxy feature isn't available. | 74 // the data reduction proxy feature isn't available. |
68 static base::string16 AuthHashForSalt(int64 salt, | 75 static base::string16 AuthHashForSalt(int64 salt, |
69 const std::string& key); | 76 const std::string& key); |
70 // Visible for testing. | 77 // Visible for testing. |
71 virtual base::Time Now() const; | 78 virtual base::Time Now() const; |
72 virtual void RandBytes(void* output, size_t length); | 79 virtual void RandBytes(void* output, size_t length); |
73 | 80 |
74 // Visible for testing. | 81 // Visible for testing. |
75 virtual std::string GetDefaultKey() const; | 82 virtual std::string GetDefaultKey() const; |
76 | 83 |
77 private: | 84 private: |
78 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyAuthRequestHandlerTest, | 85 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyAuthRequestHandlerTest, |
79 Authorization); | 86 Authorization); |
80 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyAuthRequestHandlerTest, | 87 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyAuthRequestHandlerTest, |
81 AuthHashForSalt); | 88 AuthHashForSalt); |
82 | 89 |
90 void InitAuthenticationOnIOThread( | |
marq (ping after 24h)
2014/07/31 23:54:32
Symmetrically with Will's comments, if this is pri
bengr
2014/08/02 01:10:32
Done.
| |
91 const std::string& session, | |
92 const std::string& credentials, | |
93 const std::string& client, | |
94 const std::string& version); | |
95 | |
83 // Authentication state. | 96 // Authentication state. |
84 std::string key_; | 97 std::string key_; |
98 | |
99 // Lives on the IO thread. | |
85 std::string session_; | 100 std::string session_; |
86 std::string credentials_; | 101 std::string credentials_; |
87 | 102 |
88 // Name of the client and version of the data reduction proxy protocol to use. | 103 // Name of the client and version of the data reduction proxy protocol to use. |
104 // Both live on the IO thread. | |
89 std::string client_; | 105 std::string client_; |
90 std::string version_; | 106 std::string version_; |
91 | 107 |
92 DataReductionProxyParams* data_reduction_proxy_params_; | 108 DataReductionProxyParams* data_reduction_proxy_params_; |
93 | 109 |
110 base::MessageLoopProxy* io_thread_proxy_; | |
111 | |
94 DISALLOW_COPY_AND_ASSIGN(DataReductionProxyAuthRequestHandler); | 112 DISALLOW_COPY_AND_ASSIGN(DataReductionProxyAuthRequestHandler); |
95 }; | 113 }; |
96 | 114 |
97 } // namespace data_reduction_proxy | 115 } // namespace data_reduction_proxy |
98 #endif // COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_AUTH_REQ UEST_HANDLER_H_ | 116 #endif // COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_AUTH_REQ UEST_HANDLER_H_ |
OLD | NEW |