| 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 "chrome/browser/component_updater/chrome_component_updater_configurator
.h" | 5 #include "components/component_updater/default_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_split.h" | 13 #include "base/strings/string_split.h" |
| 14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
| 15 #include "base/version.h" | 15 #include "base/version.h" |
| 16 #include "build/build_config.h" | 16 #include "build/build_config.h" |
| 17 #include "chrome/browser/component_updater/component_patcher_operation_out_of_pr
ocess.h" | |
| 18 #include "chrome/browser/component_updater/component_updater_url_constants.h" | |
| 19 #include "chrome/browser/update_client/chrome_update_query_params_delegate.h" | |
| 20 #include "components/component_updater/component_updater_switches.h" | 17 #include "components/component_updater/component_updater_switches.h" |
| 21 #include "components/update_client/configurator.h" | 18 #include "components/update_client/configurator.h" |
| 22 #include "components/version_info/version_info.h" | 19 #include "components/version_info/version_info.h" |
| 23 #include "content/public/browser/browser_thread.h" | |
| 24 #include "net/url_request/url_request_context_getter.h" | |
| 25 #include "url/gurl.h" | |
| 26 | 20 |
| 27 #if defined(OS_WIN) | 21 #if defined(OS_WIN) |
| 28 #include "base/win/win_util.h" | 22 #include "base/win/win_util.h" |
| 29 #endif // OS_WIN | 23 #endif // OS_WIN |
| 30 | 24 |
| 31 using update_client::Configurator; | |
| 32 using update_client::OutOfProcessPatcher; | |
| 33 | |
| 34 namespace component_updater { | 25 namespace component_updater { |
| 35 | 26 |
| 36 namespace { | 27 namespace { |
| 37 | |
| 38 // Default time constants. | 28 // Default time constants. |
| 39 const int kDelayOneMinute = 60; | 29 const int kDelayOneMinute = 60; |
| 40 const int kDelayOneHour = kDelayOneMinute * 60; | 30 const int kDelayOneHour = kDelayOneMinute * 60; |
| 41 | 31 |
| 42 // Debug values you can pass to --component-updater=value1,value2. | 32 // Debug values you can pass to --component-updater=value1,value2. |
| 43 // Speed up component checking. | 33 // Speed up component checking. |
| 44 const char kSwitchFastUpdate[] = "fast-update"; | 34 const char kSwitchFastUpdate[] = "fast-update"; |
| 45 | 35 |
| 46 // Add "testrequest=1" attribute to the update check request. | 36 // Add "testrequest=1" attribute to the update check request. |
| 47 const char kSwitchRequestParam[] = "test-request"; | 37 const char kSwitchRequestParam[] = "test-request"; |
| 48 | 38 |
| 49 // Disables pings. Pings are the requests sent to the update server that report | 39 // Disables pings. Pings are the requests sent to the update server that report |
| 50 // the success or the failure of component install or update attempts. | 40 // the success or the failure of component install or update attempts. |
| 51 extern const char kSwitchDisablePings[] = "disable-pings"; | 41 extern const char kSwitchDisablePings[] = "disable-pings"; |
| 52 | 42 |
| 53 // Sets the URL for updates. | 43 // Sets the URL for updates. |
| 54 const char kSwitchUrlSource[] = "url-source"; | 44 const char kSwitchUrlSource[] = "url-source"; |
| 55 | 45 |
| 56 // Disables differential updates. | 46 // Disables differential updates. |
| 57 const char kSwitchDisableDeltaUpdates[] = "disable-delta-updates"; | 47 const char kSwitchDisableDeltaUpdates[] = "disable-delta-updates"; |
| 58 | 48 |
| 49 // The alternative URL for the v3 protocol service endpoint. |
| 50 const char kUpdaterAltUrl[] = "http://clients2.google.com/service/update2"; |
| 51 |
| 52 // The default URL for the v3 protocol service endpoint. In some cases, the |
| 53 // component updater is allowed to fall back to and alternate URL source, if |
| 54 // the request to the default URL source fails. |
| 55 // The value of |kDefaultUrlSource| can be overridden with |
| 56 // --component-updater=url-source=someurl. |
| 57 const char kUpdaterDefaultUrl[] = "https://clients2.google.com/service/update2"; |
| 58 |
| 59 #if defined(OS_WIN) | 59 #if defined(OS_WIN) |
| 60 // Disables background downloads. | 60 // Disables background downloads. |
| 61 const char kSwitchDisableBackgroundDownloads[] = "disable-background-downloads"; | 61 const char kSwitchDisableBackgroundDownloads[] = "disable-background-downloads"; |
| 62 #endif // defined(OS_WIN) | 62 #endif // defined(OS_WIN) |
| 63 | 63 |
| 64 // Returns true if and only if |test| is contained in |vec|. | 64 // Returns true if and only if |test| is contained in |vec|. |
| 65 bool HasSwitchValue(const std::vector<std::string>& vec, const char* test) { | 65 bool HasSwitchValue(const std::vector<std::string>& vec, const char* test) { |
| 66 if (vec.empty()) | 66 if (vec.empty()) |
| 67 return 0; | 67 return 0; |
| 68 return (std::find(vec.begin(), vec.end(), test) != vec.end()); | 68 return (std::find(vec.begin(), vec.end(), test) != vec.end()); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 83 | 83 |
| 84 // If there is an element of |vec| of the form |test|=.*, returns the right- | 84 // If there is an element of |vec| of the form |test|=.*, returns the right- |
| 85 // hand side of that assignment. Otherwise, returns an empty string. | 85 // hand side of that assignment. Otherwise, returns an empty string. |
| 86 // The right-hand side may contain additional '=' characters, allowing for | 86 // The right-hand side may contain additional '=' characters, allowing for |
| 87 // further nesting of switch arguments. | 87 // further nesting of switch arguments. |
| 88 std::string GetSwitchArgument(const std::vector<std::string>& vec, | 88 std::string GetSwitchArgument(const std::vector<std::string>& vec, |
| 89 const char* test) { | 89 const char* test) { |
| 90 if (vec.empty()) | 90 if (vec.empty()) |
| 91 return std::string(); | 91 return std::string(); |
| 92 for (std::vector<std::string>::const_iterator it = vec.begin(); | 92 for (std::vector<std::string>::const_iterator it = vec.begin(); |
| 93 it != vec.end(); | 93 it != vec.end(); ++it) { |
| 94 ++it) { | |
| 95 const std::size_t found = it->find("="); | 94 const std::size_t found = it->find("="); |
| 96 if (found != std::string::npos) { | 95 if (found != std::string::npos) { |
| 97 if (it->substr(0, found) == test) { | 96 if (it->substr(0, found) == test) { |
| 98 return it->substr(found + 1); | 97 return it->substr(found + 1); |
| 99 } | 98 } |
| 100 } | 99 } |
| 101 } | 100 } |
| 102 return std::string(); | 101 return std::string(); |
| 103 } | 102 } |
| 104 | 103 |
| 105 class ChromeConfigurator : public Configurator { | 104 } // namespace |
| 106 public: | |
| 107 ChromeConfigurator(const base::CommandLine* cmdline, | |
| 108 net::URLRequestContextGetter* url_request_getter); | |
| 109 | 105 |
| 110 int InitialDelay() const override; | 106 DefaultConfigurator::DefaultConfigurator( |
| 111 int NextCheckDelay() const override; | |
| 112 int StepDelay() const override; | |
| 113 int OnDemandDelay() const override; | |
| 114 int UpdateDelay() const override; | |
| 115 std::vector<GURL> UpdateUrl() const override; | |
| 116 std::vector<GURL> PingUrl() const override; | |
| 117 base::Version GetBrowserVersion() const override; | |
| 118 std::string GetChannel() const override; | |
| 119 std::string GetLang() const override; | |
| 120 std::string GetOSLongName() const override; | |
| 121 std::string ExtraRequestParams() const override; | |
| 122 net::URLRequestContextGetter* RequestContext() const override; | |
| 123 scoped_refptr<OutOfProcessPatcher> CreateOutOfProcessPatcher() const override; | |
| 124 bool DeltasEnabled() const override; | |
| 125 bool UseBackgroundDownloader() const override; | |
| 126 scoped_refptr<base::SequencedTaskRunner> GetSequencedTaskRunner() | |
| 127 const override; | |
| 128 scoped_refptr<base::SingleThreadTaskRunner> GetSingleThreadTaskRunner() | |
| 129 const override; | |
| 130 | |
| 131 private: | |
| 132 friend class base::RefCountedThreadSafe<ChromeConfigurator>; | |
| 133 | |
| 134 ~ChromeConfigurator() override {} | |
| 135 | |
| 136 net::URLRequestContextGetter* url_request_getter_; | |
| 137 std::string extra_info_; | |
| 138 GURL url_source_override_; | |
| 139 bool fast_update_; | |
| 140 bool pings_enabled_; | |
| 141 bool deltas_enabled_; | |
| 142 bool background_downloads_enabled_; | |
| 143 bool fallback_to_alt_source_url_enabled_; | |
| 144 }; | |
| 145 | |
| 146 ChromeConfigurator::ChromeConfigurator( | |
| 147 const base::CommandLine* cmdline, | 107 const base::CommandLine* cmdline, |
| 148 net::URLRequestContextGetter* url_request_getter) | 108 net::URLRequestContextGetter* url_request_getter) |
| 149 : url_request_getter_(url_request_getter), | 109 : url_request_getter_(url_request_getter), |
| 150 fast_update_(false), | 110 fast_update_(false), |
| 151 pings_enabled_(false), | 111 pings_enabled_(false), |
| 152 deltas_enabled_(false), | 112 deltas_enabled_(false), |
| 153 background_downloads_enabled_(false), | 113 background_downloads_enabled_(false), |
| 154 fallback_to_alt_source_url_enabled_(false) { | 114 fallback_to_alt_source_url_enabled_(false) { |
| 155 // Parse comma-delimited debug flags. | 115 // Parse comma-delimited debug flags. |
| 156 std::vector<std::string> switch_values = base::SplitString( | 116 std::vector<std::string> switch_values = base::SplitString( |
| 157 cmdline->GetSwitchValueASCII(switches::kComponentUpdater), | 117 cmdline->GetSwitchValueASCII(switches::kComponentUpdater), ",", |
| 158 ",", base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY); | 118 base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY); |
| 159 fast_update_ = HasSwitchValue(switch_values, kSwitchFastUpdate); | 119 fast_update_ = HasSwitchValue(switch_values, kSwitchFastUpdate); |
| 160 pings_enabled_ = !HasSwitchValue(switch_values, kSwitchDisablePings); | 120 pings_enabled_ = !HasSwitchValue(switch_values, kSwitchDisablePings); |
| 161 deltas_enabled_ = !HasSwitchValue(switch_values, kSwitchDisableDeltaUpdates); | 121 deltas_enabled_ = !HasSwitchValue(switch_values, kSwitchDisableDeltaUpdates); |
| 162 | 122 |
| 163 #if defined(OS_WIN) | 123 #if defined(OS_WIN) |
| 164 background_downloads_enabled_ = | 124 background_downloads_enabled_ = |
| 165 !HasSwitchValue(switch_values, kSwitchDisableBackgroundDownloads); | 125 !HasSwitchValue(switch_values, kSwitchDisableBackgroundDownloads); |
| 166 #else | 126 #else |
| 167 background_downloads_enabled_ = false; | 127 background_downloads_enabled_ = false; |
| 168 #endif | 128 #endif |
| 169 | 129 |
| 170 const std::string switch_url_source = | 130 const std::string switch_url_source = |
| 171 GetSwitchArgument(switch_values, kSwitchUrlSource); | 131 GetSwitchArgument(switch_values, kSwitchUrlSource); |
| 172 if (!switch_url_source.empty()) { | 132 if (!switch_url_source.empty()) { |
| 173 url_source_override_ = GURL(switch_url_source); | 133 url_source_override_ = GURL(switch_url_source); |
| 174 DCHECK(url_source_override_.is_valid()); | 134 DCHECK(url_source_override_.is_valid()); |
| 175 } | 135 } |
| 176 | 136 |
| 177 if (HasSwitchValue(switch_values, kSwitchRequestParam)) | 137 if (HasSwitchValue(switch_values, kSwitchRequestParam)) |
| 178 extra_info_ += "testrequest=\"1\""; | 138 extra_info_ += "testrequest=\"1\""; |
| 179 | 139 |
| 180 fallback_to_alt_source_url_enabled_ = CanUseAltUrlSource(); | 140 fallback_to_alt_source_url_enabled_ = CanUseAltUrlSource(); |
| 181 } | 141 } |
| 182 | 142 |
| 183 int ChromeConfigurator::InitialDelay() const { | 143 int DefaultConfigurator::InitialDelay() const { |
| 184 return fast_update_ ? 10 : (6 * kDelayOneMinute); | 144 return fast_update_ ? 10 : (6 * kDelayOneMinute); |
| 185 } | 145 } |
| 186 | 146 |
| 187 int ChromeConfigurator::NextCheckDelay() const { | 147 int DefaultConfigurator::NextCheckDelay() const { |
| 188 return fast_update_ ? 60 : (6 * kDelayOneHour); | 148 return fast_update_ ? 60 : (6 * kDelayOneHour); |
| 189 } | 149 } |
| 190 | 150 |
| 191 int ChromeConfigurator::StepDelay() const { | 151 int DefaultConfigurator::StepDelay() const { |
| 192 return fast_update_ ? 1 : 1; | 152 return fast_update_ ? 1 : 1; |
| 193 } | 153 } |
| 194 | 154 |
| 195 int ChromeConfigurator::OnDemandDelay() const { | 155 int DefaultConfigurator::OnDemandDelay() const { |
| 196 return fast_update_ ? 2 : (30 * kDelayOneMinute); | 156 return fast_update_ ? 2 : (30 * kDelayOneMinute); |
| 197 } | 157 } |
| 198 | 158 |
| 199 int ChromeConfigurator::UpdateDelay() const { | 159 int DefaultConfigurator::UpdateDelay() const { |
| 200 return fast_update_ ? 10 : (15 * kDelayOneMinute); | 160 return fast_update_ ? 10 : (15 * kDelayOneMinute); |
| 201 } | 161 } |
| 202 | 162 |
| 203 std::vector<GURL> ChromeConfigurator::UpdateUrl() const { | 163 std::vector<GURL> DefaultConfigurator::UpdateUrl() const { |
| 204 std::vector<GURL> urls; | 164 std::vector<GURL> urls; |
| 205 if (url_source_override_.is_valid()) { | 165 if (url_source_override_.is_valid()) { |
| 206 urls.push_back(GURL(url_source_override_)); | 166 urls.push_back(GURL(url_source_override_)); |
| 207 } else { | 167 } else { |
| 208 urls.push_back(GURL(kUpdaterDefaultUrl)); | 168 urls.push_back(GURL(kUpdaterDefaultUrl)); |
| 209 if (fallback_to_alt_source_url_enabled_) { | 169 if (fallback_to_alt_source_url_enabled_) { |
| 210 urls.push_back(GURL(kUpdaterAltUrl)); | 170 urls.push_back(GURL(kUpdaterAltUrl)); |
| 211 } | 171 } |
| 212 } | 172 } |
| 213 return urls; | 173 return urls; |
| 214 } | 174 } |
| 215 | 175 |
| 216 std::vector<GURL> ChromeConfigurator::PingUrl() const { | 176 std::vector<GURL> DefaultConfigurator::PingUrl() const { |
| 217 return pings_enabled_ ? UpdateUrl() : std::vector<GURL>(); | 177 return pings_enabled_ ? UpdateUrl() : std::vector<GURL>(); |
| 218 } | 178 } |
| 219 | 179 |
| 220 base::Version ChromeConfigurator::GetBrowserVersion() const { | 180 base::Version DefaultConfigurator::GetBrowserVersion() const { |
| 221 return base::Version(version_info::GetVersionNumber()); | 181 return base::Version(version_info::GetVersionNumber()); |
| 222 } | 182 } |
| 223 | 183 |
| 224 std::string ChromeConfigurator::GetChannel() const { | 184 std::string DefaultConfigurator::GetOSLongName() const { |
| 225 return ChromeUpdateQueryParamsDelegate::GetChannelString(); | |
| 226 } | |
| 227 | |
| 228 std::string ChromeConfigurator::GetLang() const { | |
| 229 return ChromeUpdateQueryParamsDelegate::GetLang(); | |
| 230 } | |
| 231 | |
| 232 std::string ChromeConfigurator::GetOSLongName() const { | |
| 233 return version_info::GetOSType(); | 185 return version_info::GetOSType(); |
| 234 } | 186 } |
| 235 | 187 |
| 236 std::string ChromeConfigurator::ExtraRequestParams() const { | 188 std::string DefaultConfigurator::ExtraRequestParams() const { |
| 237 return extra_info_; | 189 return extra_info_; |
| 238 } | 190 } |
| 239 | 191 |
| 240 net::URLRequestContextGetter* ChromeConfigurator::RequestContext() const { | 192 net::URLRequestContextGetter* DefaultConfigurator::RequestContext() const { |
| 241 return url_request_getter_; | 193 return url_request_getter_; |
| 242 } | 194 } |
| 243 | 195 |
| 244 scoped_refptr<OutOfProcessPatcher> | 196 bool DefaultConfigurator::DeltasEnabled() const { |
| 245 ChromeConfigurator::CreateOutOfProcessPatcher() const { | |
| 246 return make_scoped_refptr(new ChromeOutOfProcessPatcher); | |
| 247 } | |
| 248 | |
| 249 bool ChromeConfigurator::DeltasEnabled() const { | |
| 250 return deltas_enabled_; | 197 return deltas_enabled_; |
| 251 } | 198 } |
| 252 | 199 |
| 253 bool ChromeConfigurator::UseBackgroundDownloader() const { | 200 bool DefaultConfigurator::UseBackgroundDownloader() const { |
| 254 return background_downloads_enabled_; | 201 return background_downloads_enabled_; |
| 255 } | 202 } |
| 256 | 203 |
| 257 scoped_refptr<base::SequencedTaskRunner> | |
| 258 ChromeConfigurator::GetSequencedTaskRunner() const { | |
| 259 return content::BrowserThread::GetBlockingPool() | |
| 260 ->GetSequencedTaskRunnerWithShutdownBehavior( | |
| 261 content::BrowserThread::GetBlockingPool()->GetSequenceToken(), | |
| 262 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); | |
| 263 } | |
| 264 | |
| 265 scoped_refptr<base::SingleThreadTaskRunner> | |
| 266 ChromeConfigurator::GetSingleThreadTaskRunner() const { | |
| 267 return content::BrowserThread::GetMessageLoopProxyForThread( | |
| 268 content::BrowserThread::FILE); | |
| 269 } | |
| 270 | |
| 271 } // namespace | |
| 272 | |
| 273 scoped_refptr<update_client::Configurator> | |
| 274 MakeChromeComponentUpdaterConfigurator( | |
| 275 const base::CommandLine* cmdline, | |
| 276 net::URLRequestContextGetter* context_getter) { | |
| 277 return new ChromeConfigurator(cmdline, context_getter); | |
| 278 } | |
| 279 | |
| 280 } // namespace component_updater | 204 } // namespace component_updater |
| OLD | NEW |