103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#include "chrome/browser/component_updater/chrome_component_updater_configurator.h"
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <algorithm>
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <string>
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <vector>
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/command_line.h"
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/compiler_specific.h"
13868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/string_util.h"
14116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "base/version.h"
151320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#if defined(OS_WIN)
161320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "base/win/win_util.h"
171320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#endif  // OS_WIN
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "build/build_config.h"
195f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "chrome/browser/component_updater/component_patcher_operation_out_of_process.h"
20116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "chrome/browser/omaha_query_params/chrome_omaha_query_params_delegate.h"
21116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "chrome/common/chrome_version_info.h"
2203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#include "components/component_updater/component_updater_configurator.h"
23116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "components/component_updater/component_updater_switches.h"
245f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "content/public/browser/browser_thread.h"
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/url_request/url_request_context_getter.h"
26116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "url/gurl.h"
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)namespace component_updater {
295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace {
31eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Default time constants.
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const int kDelayOneMinute = 60;
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const int kDelayOneHour = kDelayOneMinute * 60;
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
36eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// Debug values you can pass to --component-updater=value1,value2.
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Speed up component checking.
38eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochconst char kSwitchFastUpdate[] = "fast-update";
395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Add "testrequest=1" attribute to the update check request.
41eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochconst char kSwitchRequestParam[] = "test-request";
425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
43ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch// Disables pings. Pings are the requests sent to the update server that report
44ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch// the success or the failure of component install or update attempts.
45ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdochextern const char kSwitchDisablePings[] = "disable-pings";
46ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
47eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// Sets the URL for updates.
48eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochconst char kSwitchUrlSource[] = "url-source";
49eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
50f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#define COMPONENT_UPDATER_SERVICE_ENDPOINT \
51010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  "//clients2.google.com/service/update2"
52f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
531320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// The default URL for the v3 protocol service endpoint. In some cases, the
541320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// component updater is allowed to fall back to and alternate URL source, if
551320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// the request to the default URL source fails.
561320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// The value of |kDefaultUrlSource| can be overridden with
571320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// --component-updater=url-source=someurl.
58f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)const char kDefaultUrlSource[] = "https:" COMPONENT_UPDATER_SERVICE_ENDPOINT;
591320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciconst char kAltUrlSource[] = "http:" COMPONENT_UPDATER_SERVICE_ENDPOINT;
60ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
6168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)// Disables differential updates.
6268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)const char kSwitchDisableDeltaUpdates[] = "disable-delta-updates";
63effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch
64effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#if defined(OS_WIN)
655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Disables background downloads.
665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)const char kSwitchDisableBackgroundDownloads[] = "disable-background-downloads";
6768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)#endif  // defined(OS_WIN)
6868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)
69eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// Returns true if and only if |test| is contained in |vec|.
70eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochbool HasSwitchValue(const std::vector<std::string>& vec, const char* test) {
715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (vec.empty())
725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return 0;
735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return (std::find(vec.begin(), vec.end(), test) != vec.end());
745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
761320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// Returns true if falling back on an alternate, unsafe, service URL is
771320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// allowed. In the fallback case, the security of the component update relies
781320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// only on the integrity of the CRX payloads, which is self-validating.
791320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// This is allowed only for some of the pre-Windows Vista versions not including
801320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// Windows XP SP3. As a side note, pings could be sent to the alternate URL too.
811320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccibool CanUseAltUrlSource() {
821320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#if defined(OS_WIN)
831320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  return !base::win::MaybeHasSHA256Support();
841320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#else
851320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  return false;
861320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#endif  // OS_WIN
871320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci}
881320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
89eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// If there is an element of |vec| of the form |test|=.*, returns the right-
90eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// hand side of that assignment. Otherwise, returns an empty string.
91eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// The right-hand side may contain additional '=' characters, allowing for
92eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// further nesting of switch arguments.
93eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochstd::string GetSwitchArgument(const std::vector<std::string>& vec,
94eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch                              const char* test) {
95eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  if (vec.empty())
96eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    return std::string();
97eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  for (std::vector<std::string>::const_iterator it = vec.begin();
98010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)       it != vec.end();
99010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)       ++it) {
100eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    const std::size_t found = it->find("=");
101eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    if (found != std::string::npos) {
102eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      if (it->substr(0, found) == test) {
103eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch        return it->substr(found + 1);
104eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      }
105eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    }
106eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  }
107eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  return std::string();
108eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch}
109eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
110116680a4aac90f2aa7413d9095a592090648e557Ben Murdochclass ChromeConfigurator : public Configurator {
1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ChromeConfigurator(const CommandLine* cmdline,
1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                     net::URLRequestContextGetter* url_request_getter);
1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual ~ChromeConfigurator() {}
1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
117116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  virtual int InitialDelay() const OVERRIDE;
1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual int NextCheckDelay() OVERRIDE;
119116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  virtual int StepDelay() const OVERRIDE;
1203551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  virtual int StepDelayMedium() OVERRIDE;
121116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  virtual int MinimumReCheckWait() const OVERRIDE;
122116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  virtual int OnDemandDelay() const OVERRIDE;
1231320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  virtual std::vector<GURL> UpdateUrl() const OVERRIDE;
1241320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  virtual std::vector<GURL> PingUrl() const OVERRIDE;
125116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  virtual base::Version GetBrowserVersion() const OVERRIDE;
126116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  virtual std::string GetChannel() const OVERRIDE;
127116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  virtual std::string GetLang() const OVERRIDE;
128116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  virtual std::string GetOSLongName() const OVERRIDE;
129116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  virtual std::string ExtraRequestParams() const OVERRIDE;
130116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  virtual size_t UrlSizeLimit() const OVERRIDE;
131116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  virtual net::URLRequestContextGetter* RequestContext() const OVERRIDE;
1325f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  virtual scoped_refptr<OutOfProcessPatcher> CreateOutOfProcessPatcher()
1335f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)      const OVERRIDE;
134eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  virtual bool DeltasEnabled() const OVERRIDE;
135a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  virtual bool UseBackgroundDownloader() const OVERRIDE;
1365f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  virtual scoped_refptr<base::SequencedTaskRunner> GetSequencedTaskRunner()
1375f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)      const OVERRIDE;
1385f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  virtual scoped_refptr<base::SingleThreadTaskRunner>
1395f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)      GetSingleThreadTaskRunner() const OVERRIDE;
1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  net::URLRequestContextGetter* url_request_getter_;
1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  std::string extra_info_;
1441320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  GURL url_source_override_;
1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool fast_update_;
146ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  bool pings_enabled_;
147eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  bool deltas_enabled_;
148a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  bool background_downloads_enabled_;
1491320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  bool fallback_to_alt_source_url_enabled_;
1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
152010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)ChromeConfigurator::ChromeConfigurator(
153010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    const CommandLine* cmdline,
1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    net::URLRequestContextGetter* url_request_getter)
155010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    : url_request_getter_(url_request_getter),
156010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      fast_update_(false),
157010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      pings_enabled_(false),
158010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      deltas_enabled_(false),
1591320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      background_downloads_enabled_(false),
1601320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      fallback_to_alt_source_url_enabled_(false) {
1615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Parse comma-delimited debug flags.
162eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  std::vector<std::string> switch_values;
163eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  Tokenize(cmdline->GetSwitchValueASCII(switches::kComponentUpdater),
164010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)           ",",
165010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)           &switch_values);
166eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  fast_update_ = HasSwitchValue(switch_values, kSwitchFastUpdate);
167ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  pings_enabled_ = !HasSwitchValue(switch_values, kSwitchDisablePings);
168eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  deltas_enabled_ = !HasSwitchValue(switch_values, kSwitchDisableDeltaUpdates);
169effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch
170effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#if defined(OS_WIN)
171a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  background_downloads_enabled_ =
1725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      !HasSwitchValue(switch_values, kSwitchDisableBackgroundDownloads);
173eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#else
1745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  background_downloads_enabled_ = false;
175eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#endif
176eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
1771320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  const std::string switch_url_source =
1781320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      GetSwitchArgument(switch_values, kSwitchUrlSource);
1791320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  if (!switch_url_source.empty()) {
1801320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    url_source_override_ = GURL(switch_url_source);
1811320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    DCHECK(url_source_override_.is_valid());
182eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  }
1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
184eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  if (HasSwitchValue(switch_values, kSwitchRequestParam))
1855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    extra_info_ += "testrequest=\"1\"";
1861320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
1871320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  fallback_to_alt_source_url_enabled_ = CanUseAltUrlSource();
1885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
190116680a4aac90f2aa7413d9095a592090648e557Ben Murdochint ChromeConfigurator::InitialDelay() const {
1912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return fast_update_ ? 1 : (6 * kDelayOneMinute);
1925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int ChromeConfigurator::NextCheckDelay() {
195a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  return fast_update_ ? 3 : (6 * kDelayOneHour);
1965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1983551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)int ChromeConfigurator::StepDelayMedium() {
1993551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  return fast_update_ ? 3 : (15 * kDelayOneMinute);
2003551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)}
2013551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
202116680a4aac90f2aa7413d9095a592090648e557Ben Murdochint ChromeConfigurator::StepDelay() const {
203f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  return fast_update_ ? 1 : 1;
2045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
206116680a4aac90f2aa7413d9095a592090648e557Ben Murdochint ChromeConfigurator::MinimumReCheckWait() const {
2075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return fast_update_ ? 30 : (6 * kDelayOneHour);
2085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
210116680a4aac90f2aa7413d9095a592090648e557Ben Murdochint ChromeConfigurator::OnDemandDelay() const {
2112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return fast_update_ ? 2 : (30 * kDelayOneMinute);
2122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
2132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2141320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccistd::vector<GURL> ChromeConfigurator::UpdateUrl() const {
2151320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  std::vector<GURL> urls;
2161320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  if (url_source_override_.is_valid()) {
2171320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    urls.push_back(GURL(url_source_override_));
2181320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  } else {
2191320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    urls.push_back(GURL(kDefaultUrlSource));
2201320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    if (fallback_to_alt_source_url_enabled_) {
2211320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      urls.push_back(GURL(kAltUrlSource));
2221320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    }
2231320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  }
2241320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  return urls;
2255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2271320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccistd::vector<GURL> ChromeConfigurator::PingUrl() const {
2281320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  return pings_enabled_ ? UpdateUrl() : std::vector<GURL>();
229ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch}
230ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
231116680a4aac90f2aa7413d9095a592090648e557Ben Murdochbase::Version ChromeConfigurator::GetBrowserVersion() const {
232116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  return base::Version(chrome::VersionInfo().Version());
233116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch}
234116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
235116680a4aac90f2aa7413d9095a592090648e557Ben Murdochstd::string ChromeConfigurator::GetChannel() const {
236116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  return ChromeOmahaQueryParamsDelegate::GetChannelString();
237116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch}
238116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
239116680a4aac90f2aa7413d9095a592090648e557Ben Murdochstd::string ChromeConfigurator::GetLang() const {
240116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  return ChromeOmahaQueryParamsDelegate::GetLang();
241116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch}
242116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
243116680a4aac90f2aa7413d9095a592090648e557Ben Murdochstd::string ChromeConfigurator::GetOSLongName() const {
244116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  return chrome::VersionInfo().OSType();
245116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch}
246116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
247116680a4aac90f2aa7413d9095a592090648e557Ben Murdochstd::string ChromeConfigurator::ExtraRequestParams() const {
2485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return extra_info_;
2495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
251116680a4aac90f2aa7413d9095a592090648e557Ben Murdochsize_t ChromeConfigurator::UrlSizeLimit() const {
2525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return 1024ul;
2535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
255116680a4aac90f2aa7413d9095a592090648e557Ben Murdochnet::URLRequestContextGetter* ChromeConfigurator::RequestContext() const {
2565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return url_request_getter_;
2575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2595f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)scoped_refptr<OutOfProcessPatcher>
2605f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)ChromeConfigurator::CreateOutOfProcessPatcher() const {
2615f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  return make_scoped_refptr(new ChromeOutOfProcessPatcher);
2625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
264eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochbool ChromeConfigurator::DeltasEnabled() const {
265eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  return deltas_enabled_;
266eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch}
267eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
268a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)bool ChromeConfigurator::UseBackgroundDownloader() const {
269a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  return background_downloads_enabled_;
270a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)}
271a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
2725f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)scoped_refptr<base::SequencedTaskRunner>
2735f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)ChromeConfigurator::GetSequencedTaskRunner() const {
2745f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  return content::BrowserThread::GetBlockingPool()
2755f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)      ->GetSequencedTaskRunnerWithShutdownBehavior(
2765f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)          content::BrowserThread::GetBlockingPool()->GetSequenceToken(),
2775f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)          base::SequencedWorkerPool::SKIP_ON_SHUTDOWN);
2785f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)}
2795f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
2805f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)scoped_refptr<base::SingleThreadTaskRunner>
2815f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)ChromeConfigurator::GetSingleThreadTaskRunner() const {
2825f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  return content::BrowserThread::GetMessageLoopProxyForThread(
2835f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)      content::BrowserThread::FILE);
2845f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)}
2855f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
28603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)}  // namespace
28703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
288116680a4aac90f2aa7413d9095a592090648e557Ben MurdochConfigurator* MakeChromeComponentUpdaterConfigurator(
289116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    const base::CommandLine* cmdline,
290010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    net::URLRequestContextGetter* context_getter) {
2915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return new ChromeConfigurator(cmdline, context_getter);
2925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
2945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}  // namespace component_updater
295