OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/component_updater/component_updater_configurator.h" | 5 #include "chrome/browser/component_updater/component_updater_configurator.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
14 #include "base/win/windows_version.h" | 14 #include "base/win/windows_version.h" |
15 #include "build/build_config.h" | 15 #include "build/build_config.h" |
16 #include "chrome/browser/component_updater/component_patcher.h" | 16 #include "chrome/browser/component_updater/component_patcher.h" |
17 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
18 #include "net/url_request/url_request_context_getter.h" | 18 #include "net/url_request/url_request_context_getter.h" |
19 | 19 |
20 #if defined(OS_WIN) | |
21 #include "chrome/browser/component_updater/component_patcher_win.h" | |
22 #endif | |
23 | |
24 namespace component_updater { | 20 namespace component_updater { |
25 | 21 |
26 namespace { | 22 namespace { |
27 | 23 |
28 // Default time constants. | 24 // Default time constants. |
29 const int kDelayOneMinute = 60; | 25 const int kDelayOneMinute = 60; |
30 const int kDelayOneHour = kDelayOneMinute * 60; | 26 const int kDelayOneHour = kDelayOneMinute * 60; |
31 | 27 |
32 // Debug values you can pass to --component-updater=value1,value2. | 28 // Debug values you can pass to --component-updater=value1,value2. |
33 // Speed up component checking. | 29 // Speed up component checking. |
(...skipping 12 matching lines...) Expand all Loading... |
46 #define COMPONENT_UPDATER_SERVICE_ENDPOINT \ | 42 #define COMPONENT_UPDATER_SERVICE_ENDPOINT \ |
47 "//clients2.google.com/service/update2" | 43 "//clients2.google.com/service/update2" |
48 | 44 |
49 // The default url for the v3 protocol service endpoint. Can be | 45 // The default url for the v3 protocol service endpoint. Can be |
50 // overridden with --component-updater=url-source=someurl. | 46 // overridden with --component-updater=url-source=someurl. |
51 const char kDefaultUrlSource[] = "https:" COMPONENT_UPDATER_SERVICE_ENDPOINT; | 47 const char kDefaultUrlSource[] = "https:" COMPONENT_UPDATER_SERVICE_ENDPOINT; |
52 | 48 |
53 // The url to send the pings to. | 49 // The url to send the pings to. |
54 const char kPingUrl[] = "http:" COMPONENT_UPDATER_SERVICE_ENDPOINT; | 50 const char kPingUrl[] = "http:" COMPONENT_UPDATER_SERVICE_ENDPOINT; |
55 | 51 |
56 #if defined(OS_WIN) | |
57 // Disables differential updates. | 52 // Disables differential updates. |
58 const char kSwitchDisableDeltaUpdates[] = "disable-delta-updates"; | 53 const char kSwitchDisableDeltaUpdates[] = "disable-delta-updates"; |
| 54 |
| 55 #if defined(OS_WIN) |
59 // Disables background downloads. | 56 // Disables background downloads. |
60 const char kSwitchDisableBackgroundDownloads[] = "disable-background-downloads"; | 57 const char kSwitchDisableBackgroundDownloads[] = "disable-background-downloads"; |
61 #endif // defined(OS_WIN) | 58 #endif // defined(OS_WIN) |
62 | 59 |
63 // Returns true if and only if |test| is contained in |vec|. | 60 // Returns true if and only if |test| is contained in |vec|. |
64 bool HasSwitchValue(const std::vector<std::string>& vec, const char* test) { | 61 bool HasSwitchValue(const std::vector<std::string>& vec, const char* test) { |
65 if (vec.empty()) | 62 if (vec.empty()) |
66 return 0; | 63 return 0; |
67 return (std::find(vec.begin(), vec.end(), test) != vec.end()); | 64 return (std::find(vec.begin(), vec.end(), test) != vec.end()); |
68 } | 65 } |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 virtual int StepDelay() OVERRIDE; | 99 virtual int StepDelay() OVERRIDE; |
103 virtual int StepDelayMedium() OVERRIDE; | 100 virtual int StepDelayMedium() OVERRIDE; |
104 virtual int MinimumReCheckWait() OVERRIDE; | 101 virtual int MinimumReCheckWait() OVERRIDE; |
105 virtual int OnDemandDelay() OVERRIDE; | 102 virtual int OnDemandDelay() OVERRIDE; |
106 virtual GURL UpdateUrl() OVERRIDE; | 103 virtual GURL UpdateUrl() OVERRIDE; |
107 virtual GURL PingUrl() OVERRIDE; | 104 virtual GURL PingUrl() OVERRIDE; |
108 virtual std::string ExtraRequestParams() OVERRIDE; | 105 virtual std::string ExtraRequestParams() OVERRIDE; |
109 virtual size_t UrlSizeLimit() OVERRIDE; | 106 virtual size_t UrlSizeLimit() OVERRIDE; |
110 virtual net::URLRequestContextGetter* RequestContext() OVERRIDE; | 107 virtual net::URLRequestContextGetter* RequestContext() OVERRIDE; |
111 virtual bool InProcess() OVERRIDE; | 108 virtual bool InProcess() OVERRIDE; |
112 virtual ComponentPatcher* CreateComponentPatcher() OVERRIDE; | |
113 virtual bool DeltasEnabled() const OVERRIDE; | 109 virtual bool DeltasEnabled() const OVERRIDE; |
114 virtual bool UseBackgroundDownloader() const OVERRIDE; | 110 virtual bool UseBackgroundDownloader() const OVERRIDE; |
115 | 111 |
116 private: | 112 private: |
117 net::URLRequestContextGetter* url_request_getter_; | 113 net::URLRequestContextGetter* url_request_getter_; |
118 std::string extra_info_; | 114 std::string extra_info_; |
119 std::string url_source_; | 115 std::string url_source_; |
120 bool fast_update_; | 116 bool fast_update_; |
121 bool pings_enabled_; | 117 bool pings_enabled_; |
122 bool deltas_enabled_; | 118 bool deltas_enabled_; |
123 bool background_downloads_enabled_; | 119 bool background_downloads_enabled_; |
124 }; | 120 }; |
125 | 121 |
126 ChromeConfigurator::ChromeConfigurator(const CommandLine* cmdline, | 122 ChromeConfigurator::ChromeConfigurator(const CommandLine* cmdline, |
127 net::URLRequestContextGetter* url_request_getter) | 123 net::URLRequestContextGetter* url_request_getter) |
128 : url_request_getter_(url_request_getter), | 124 : url_request_getter_(url_request_getter), |
129 fast_update_(false), | 125 fast_update_(false), |
130 pings_enabled_(false), | 126 pings_enabled_(false), |
131 deltas_enabled_(false), | 127 deltas_enabled_(false), |
132 background_downloads_enabled_(false) { | 128 background_downloads_enabled_(false) { |
133 // Parse comma-delimited debug flags. | 129 // Parse comma-delimited debug flags. |
134 std::vector<std::string> switch_values; | 130 std::vector<std::string> switch_values; |
135 Tokenize(cmdline->GetSwitchValueASCII(switches::kComponentUpdater), | 131 Tokenize(cmdline->GetSwitchValueASCII(switches::kComponentUpdater), |
136 ",", &switch_values); | 132 ",", &switch_values); |
137 fast_update_ = HasSwitchValue(switch_values, kSwitchFastUpdate); | 133 fast_update_ = HasSwitchValue(switch_values, kSwitchFastUpdate); |
138 pings_enabled_ = !HasSwitchValue(switch_values, kSwitchDisablePings); | 134 pings_enabled_ = !HasSwitchValue(switch_values, kSwitchDisablePings); |
| 135 deltas_enabled_ = !HasSwitchValue(switch_values, kSwitchDisableDeltaUpdates); |
| 136 |
139 #if defined(OS_WIN) | 137 #if defined(OS_WIN) |
140 deltas_enabled_ = !HasSwitchValue(switch_values, kSwitchDisableDeltaUpdates); | |
141 background_downloads_enabled_ = | 138 background_downloads_enabled_ = |
142 !HasSwitchValue(switch_values, kSwitchDisableBackgroundDownloads); | 139 !HasSwitchValue(switch_values, kSwitchDisableBackgroundDownloads); |
143 #else | 140 #else |
144 deltas_enabled_ = false; | |
145 background_downloads_enabled_ = false; | 141 background_downloads_enabled_ = false; |
146 #endif | 142 #endif |
147 | 143 |
148 url_source_ = GetSwitchArgument(switch_values, kSwitchUrlSource); | 144 url_source_ = GetSwitchArgument(switch_values, kSwitchUrlSource); |
149 if (url_source_.empty()) { | 145 if (url_source_.empty()) { |
150 url_source_ = kDefaultUrlSource; | 146 url_source_ = kDefaultUrlSource; |
151 } | 147 } |
152 | 148 |
153 if (HasSwitchValue(switch_values, kSwitchRequestParam)) | 149 if (HasSwitchValue(switch_values, kSwitchRequestParam)) |
154 extra_info_ += "testrequest=\"1\""; | 150 extra_info_ += "testrequest=\"1\""; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 } | 191 } |
196 | 192 |
197 net::URLRequestContextGetter* ChromeConfigurator::RequestContext() { | 193 net::URLRequestContextGetter* ChromeConfigurator::RequestContext() { |
198 return url_request_getter_; | 194 return url_request_getter_; |
199 } | 195 } |
200 | 196 |
201 bool ChromeConfigurator::InProcess() { | 197 bool ChromeConfigurator::InProcess() { |
202 return false; | 198 return false; |
203 } | 199 } |
204 | 200 |
205 ComponentPatcher* ChromeConfigurator::CreateComponentPatcher() { | |
206 #if defined(OS_WIN) | |
207 return new ComponentPatcherWin(); | |
208 #else | |
209 return new ComponentPatcherCrossPlatform(); | |
210 #endif | |
211 } | |
212 | |
213 bool ChromeConfigurator::DeltasEnabled() const { | 201 bool ChromeConfigurator::DeltasEnabled() const { |
214 return deltas_enabled_; | 202 return deltas_enabled_; |
215 } | 203 } |
216 | 204 |
217 bool ChromeConfigurator::UseBackgroundDownloader() const { | 205 bool ChromeConfigurator::UseBackgroundDownloader() const { |
218 return background_downloads_enabled_; | 206 return background_downloads_enabled_; |
219 } | 207 } |
220 | 208 |
221 ComponentUpdateService::Configurator* MakeChromeComponentUpdaterConfigurator( | 209 ComponentUpdateService::Configurator* MakeChromeComponentUpdaterConfigurator( |
222 const CommandLine* cmdline, net::URLRequestContextGetter* context_getter) { | 210 const CommandLine* cmdline, net::URLRequestContextGetter* context_getter) { |
223 return new ChromeConfigurator(cmdline, context_getter); | 211 return new ChromeConfigurator(cmdline, context_getter); |
224 } | 212 } |
225 | 213 |
226 } // namespace component_updater | 214 } // namespace component_updater |
OLD | NEW |