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 #include "components/data_reduction_proxy/browser/data_reduction_proxy_auth_requ est_handler.h" | 5 #include "components/data_reduction_proxy/browser/data_reduction_proxy_auth_requ est_handler.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
10 #include "base/strings/string_split.h" | |
10 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
11 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
12 #include "base/time/time.h" | 13 #include "base/time/time.h" |
13 #include "components/data_reduction_proxy/browser/data_reduction_proxy_params.h" | 14 #include "components/data_reduction_proxy/browser/data_reduction_proxy_params.h" |
14 #include "components/data_reduction_proxy/browser/data_reduction_proxy_protocol. h" | 15 #include "components/data_reduction_proxy/browser/data_reduction_proxy_protocol. h" |
15 #include "components/data_reduction_proxy/browser/data_reduction_proxy_settings. h" | 16 #include "components/data_reduction_proxy/browser/data_reduction_proxy_settings. h" |
16 #include "components/data_reduction_proxy/common/data_reduction_proxy_headers.h" | 17 #include "components/data_reduction_proxy/common/data_reduction_proxy_headers.h" |
17 #include "components/data_reduction_proxy/common/data_reduction_proxy_switches.h " | 18 #include "components/data_reduction_proxy/common/data_reduction_proxy_switches.h " |
18 #include "crypto/random.h" | 19 #include "crypto/random.h" |
19 #include "net/proxy/proxy_server.h" | 20 #include "net/proxy/proxy_server.h" |
20 #include "net/url_request/url_request.h" | 21 #include "net/url_request/url_request.h" |
21 #include "url/gurl.h" | 22 #include "url/gurl.h" |
22 | 23 |
23 namespace data_reduction_proxy { | 24 namespace data_reduction_proxy { |
24 | 25 |
25 // The empty version for the authentication protocol. Currently used by | 26 // The empty version for the authentication protocol. Currently used by |
26 // Android webview. | 27 // Android webview. |
27 #if defined(OS_ANDROID) | 28 #if defined(OS_ANDROID) |
28 const char kAndroidWebViewProtocolVersion[] = "0"; | 29 const char kAndroidWebViewProtocolVersion[] = ""; |
bengr
2014/09/04 19:22:52
Add:
// TODO(bengr): Remove when this class determ
| |
29 #endif | 30 #endif |
30 | 31 |
31 // The clients supported by the data reduction proxy. | 32 // The clients supported by the data reduction proxy. |
32 const char kClientAndroidWebview[] = "webview"; | 33 const char kClientAndroidWebview[] = "webview"; |
33 const char kClientChromeAndroid[] = "android"; | 34 const char kClientChromeAndroid[] = "android"; |
34 const char kClientChromeIOS[] = "ios"; | 35 const char kClientChromeIOS[] = "ios"; |
35 | 36 |
36 // static | 37 // static |
37 bool DataReductionProxyAuthRequestHandler::IsKeySetOnCommandLine() { | 38 bool DataReductionProxyAuthRequestHandler::IsKeySetOnCommandLine() { |
38 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 39 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
39 return command_line.HasSwitch( | 40 return command_line.HasSwitch( |
40 data_reduction_proxy::switches::kDataReductionProxyKey); | 41 data_reduction_proxy::switches::kDataReductionProxyKey); |
41 } | 42 } |
42 | 43 |
43 DataReductionProxyAuthRequestHandler::DataReductionProxyAuthRequestHandler( | 44 DataReductionProxyAuthRequestHandler::DataReductionProxyAuthRequestHandler( |
44 const std::string& client, | 45 const std::string& client, |
45 const std::string& version, | 46 const std::string& version, |
46 DataReductionProxyParams* params, | 47 DataReductionProxyParams* params, |
47 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner) | 48 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner) |
48 : data_reduction_proxy_params_(params), | 49 : data_reduction_proxy_params_(params), |
49 network_task_runner_(network_task_runner) { | 50 network_task_runner_(network_task_runner) { |
50 client_ = client; | 51 client_ = client; |
51 version_ = version; | 52 build_number_ = GetChromiumVersionComponent(version, 2); |
53 patch_number_ = GetChromiumVersionComponent(version, 3); | |
bengr
2014/09/04 19:22:52
Since you are doing the same work twice, why not h
megjablon
2014/09/04 20:30:35
Done.
| |
52 Init(); | 54 Init(); |
53 } | 55 } |
54 | 56 |
57 std::string DataReductionProxyAuthRequestHandler::GetChromiumVersionComponent( | |
58 std::string version, int index) { | |
bengr
2014/09/04 19:22:52
use const std::string version&
megjablon
2014/09/04 20:30:35
Done.
| |
59 std::vector<std::string> version_parts; | |
60 base::SplitString(version, '.', &version_parts); | |
61 if (version_parts.size() != 4) | |
62 return std::string(); | |
63 return version_parts[index]; | |
64 } | |
65 | |
55 void DataReductionProxyAuthRequestHandler::Init() { | 66 void DataReductionProxyAuthRequestHandler::Init() { |
56 InitAuthenticationOnUI(GetDefaultKey()); | 67 InitAuthenticationOnUI(GetDefaultKey()); |
57 } | 68 } |
58 | 69 |
59 | 70 |
60 DataReductionProxyAuthRequestHandler::~DataReductionProxyAuthRequestHandler() { | 71 DataReductionProxyAuthRequestHandler::~DataReductionProxyAuthRequestHandler() { |
61 } | 72 } |
62 | 73 |
63 // static | 74 // static |
64 base::string16 DataReductionProxyAuthRequestHandler::AuthHashForSalt( | 75 base::string16 DataReductionProxyAuthRequestHandler::AuthHashForSalt( |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
105 ComputeCredentials(last_update_time_, &session_, &credentials_); | 116 ComputeCredentials(last_update_time_, &session_, &credentials_); |
106 } | 117 } |
107 const char kChromeProxyHeader[] = "Chrome-Proxy"; | 118 const char kChromeProxyHeader[] = "Chrome-Proxy"; |
108 std::string header_value; | 119 std::string header_value; |
109 if (headers->HasHeader(kChromeProxyHeader)) { | 120 if (headers->HasHeader(kChromeProxyHeader)) { |
110 headers->GetHeader(kChromeProxyHeader, &header_value); | 121 headers->GetHeader(kChromeProxyHeader, &header_value); |
111 headers->RemoveHeader(kChromeProxyHeader); | 122 headers->RemoveHeader(kChromeProxyHeader); |
112 header_value += ", "; | 123 header_value += ", "; |
113 } | 124 } |
114 header_value += | 125 header_value += |
115 "ps=" + session_ + ", sid=" + credentials_ + ", v=" + version_; | 126 "ps=" + session_ + ", sid=" + credentials_; |
127 if (!build_number_.empty() && !patch_number_.empty()) | |
128 header_value += ", b=" + build_number_ + ", p=" + patch_number_; | |
bengr
2014/09/04 19:22:52
indent only 2 from the 'if'
| |
116 if (!client_.empty()) | 129 if (!client_.empty()) |
117 header_value += ", c=" + client_; | 130 header_value += ", c=" + client_; |
118 headers->SetHeader(kChromeProxyHeader, header_value); | 131 headers->SetHeader(kChromeProxyHeader, header_value); |
119 } | 132 } |
120 | 133 |
121 void DataReductionProxyAuthRequestHandler::InitAuthenticationOnUI( | 134 void DataReductionProxyAuthRequestHandler::InitAuthenticationOnUI( |
122 const std::string& key) { | 135 const std::string& key) { |
123 network_task_runner_->PostTask(FROM_HERE, base::Bind( | 136 network_task_runner_->PostTask(FROM_HERE, base::Bind( |
124 &DataReductionProxyAuthRequestHandler::InitAuthentication, | 137 &DataReductionProxyAuthRequestHandler::InitAuthentication, |
125 base::Unretained(this), | 138 base::Unretained(this), |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
167 std::string key = | 180 std::string key = |
168 command_line.GetSwitchValueASCII(switches::kDataReductionProxyKey); | 181 command_line.GetSwitchValueASCII(switches::kDataReductionProxyKey); |
169 #if defined(SPDY_PROXY_AUTH_VALUE) | 182 #if defined(SPDY_PROXY_AUTH_VALUE) |
170 if (key.empty()) | 183 if (key.empty()) |
171 key = SPDY_PROXY_AUTH_VALUE; | 184 key = SPDY_PROXY_AUTH_VALUE; |
172 #endif | 185 #endif |
173 return key; | 186 return key; |
174 } | 187 } |
175 | 188 |
176 } // namespace data_reduction_proxy | 189 } // namespace data_reduction_proxy |
OLD | NEW |