| 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" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 extern const char kClientAndroidWebview[]; | 31 extern const char kClientAndroidWebview[]; |
| 32 extern const char kClientChromeAndroid[]; | 32 extern const char kClientChromeAndroid[]; |
| 33 extern const char kClientChromeIOS[]; | 33 extern const char kClientChromeIOS[]; |
| 34 | 34 |
| 35 class DataReductionProxyParams; | 35 class DataReductionProxyParams; |
| 36 | 36 |
| 37 class DataReductionProxyAuthRequestHandler { | 37 class DataReductionProxyAuthRequestHandler { |
| 38 public: | 38 public: |
| 39 static bool IsKeySetOnCommandLine(); | 39 static bool IsKeySetOnCommandLine(); |
| 40 | 40 |
| 41 // Constructs a DataReductionProxyAuthRequestHandler object with the given |
| 42 // client, version, params, and network task runner. The Chromium |version| is |
| 43 // expected to be of the form "xx.xx.xx.xx". If it isn't of this form, |
| 44 // |build_number_| and |patch_number_| are set to empty strings and not |
| 45 // included in the header. http://crbug.com/410127 will change this so that |
| 46 // the version is retrieved inside this constructor. |
| 41 DataReductionProxyAuthRequestHandler( | 47 DataReductionProxyAuthRequestHandler( |
| 42 const std::string& client, | 48 const std::string& client, |
| 43 const std::string& version, | 49 const std::string& version, |
| 44 DataReductionProxyParams* params, | 50 DataReductionProxyParams* params, |
| 45 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner); | 51 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner); |
| 46 | 52 |
| 47 virtual ~DataReductionProxyAuthRequestHandler(); | 53 virtual ~DataReductionProxyAuthRequestHandler(); |
| 48 | 54 |
| 49 // Adds a 'Chrome-Proxy' header to |request_headers| with the data reduction | 55 // Adds a 'Chrome-Proxy' header to |request_headers| with the data reduction |
| 50 // proxy authentication credentials. Only adds this header if the provided | 56 // proxy authentication credentials. Only adds this header if the provided |
| (...skipping 22 matching lines...) Expand all Loading... |
| 73 virtual base::Time Now() const; | 79 virtual base::Time Now() const; |
| 74 virtual void RandBytes(void* output, size_t length); | 80 virtual void RandBytes(void* output, size_t length); |
| 75 | 81 |
| 76 // Visible for testing. | 82 // Visible for testing. |
| 77 virtual std::string GetDefaultKey() const; | 83 virtual std::string GetDefaultKey() const; |
| 78 | 84 |
| 79 private: | 85 private: |
| 80 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyAuthRequestHandlerTest, | 86 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyAuthRequestHandlerTest, |
| 81 Authorization); | 87 Authorization); |
| 82 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyAuthRequestHandlerTest, | 88 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyAuthRequestHandlerTest, |
| 89 AuthorizationBogusVersion); |
| 90 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyAuthRequestHandlerTest, |
| 83 AuthHashForSalt); | 91 AuthHashForSalt); |
| 84 | 92 |
| 93 // Returns the build and patch numbers of |version|. If |version| isn't of the |
| 94 // form xx.xx.xx.xx build and patch are not modified. |
| 95 void GetChromiumBuildAndPatch(const std::string& version, |
| 96 std::string* build, |
| 97 std::string* patch); |
| 98 |
| 85 // Stores the supplied key and sets up credentials suitable for authenticating | 99 // Stores the supplied key and sets up credentials suitable for authenticating |
| 86 // with the data reduction proxy. | 100 // with the data reduction proxy. |
| 87 void InitAuthentication(const std::string& key); | 101 void InitAuthentication(const std::string& key); |
| 88 | 102 |
| 89 // Generates a session ID and credentials suitable for authenticating with | 103 // Generates a session ID and credentials suitable for authenticating with |
| 90 // the data reduction proxy. | 104 // the data reduction proxy. |
| 91 void ComputeCredentials(const base::Time& now, | 105 void ComputeCredentials(const base::Time& now, |
| 92 std::string* session, | 106 std::string* session, |
| 93 std::string* credentials); | 107 std::string* credentials); |
| 94 | 108 |
| 95 // Authentication state. | 109 // Authentication state. |
| 96 std::string key_; | 110 std::string key_; |
| 97 | 111 |
| 98 // Lives on the IO thread. | 112 // Lives on the IO thread. |
| 99 std::string session_; | 113 std::string session_; |
| 100 std::string credentials_; | 114 std::string credentials_; |
| 101 | 115 |
| 102 // Name of the client and version of the data reduction proxy protocol to use. | 116 // Name of the client and version of the data reduction proxy protocol to use. |
| 103 // Both live on the IO thread. | 117 // Both live on the IO thread. |
| 104 std::string client_; | 118 std::string client_; |
| 105 std::string version_; | 119 std::string build_number_; |
| 120 std::string patch_number_; |
| 106 | 121 |
| 107 // The last time the session was updated. Used to ensure that a session is | 122 // The last time the session was updated. Used to ensure that a session is |
| 108 // never used for more than twenty-four hours. | 123 // never used for more than twenty-four hours. |
| 109 base::Time last_update_time_; | 124 base::Time last_update_time_; |
| 110 | 125 |
| 111 DataReductionProxyParams* data_reduction_proxy_params_; | 126 DataReductionProxyParams* data_reduction_proxy_params_; |
| 112 | 127 |
| 113 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; | 128 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; |
| 114 | 129 |
| 115 DISALLOW_COPY_AND_ASSIGN(DataReductionProxyAuthRequestHandler); | 130 DISALLOW_COPY_AND_ASSIGN(DataReductionProxyAuthRequestHandler); |
| 116 }; | 131 }; |
| 117 | 132 |
| 118 } // namespace data_reduction_proxy | 133 } // namespace data_reduction_proxy |
| 119 #endif // COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_AUTH_REQ
UEST_HANDLER_H_ | 134 #endif // COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_AUTH_REQ
UEST_HANDLER_H_ |
| OLD | NEW |