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