// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "chrome/browser/component_updater/component_updater_service.h" #include #include #include #include "base/command_line.h" #include "base/compiler_specific.h" #include "base/string_util.h" #include "chrome/common/chrome_switches.h" #include "net/url_request/url_request_context_getter.h" namespace { // Default time constants. const int kDelayOneMinute = 60; const int kDelayOneHour = kDelayOneMinute * 60; // Debug values you can pass to --component-updater-debug=. const char kDebugFastUpdate[] = "fast-update"; const char kDebugOutOfProcess[] = "out-of-process"; bool HasDebugValue(const std::vector& vec, const char* test) { if (vec.empty()) return 0; return (std::find(vec.begin(), vec.end(), test) != vec.end()); } } // namespace class ChromeConfigurator : public ComponentUpdateService::Configurator { public: ChromeConfigurator(const CommandLine* cmdline, net::URLRequestContextGetter* url_request_getter); virtual ~ChromeConfigurator() {} virtual int InitialDelay() OVERRIDE; virtual int NextCheckDelay() OVERRIDE; virtual int StepDelay() OVERRIDE; virtual int MinimumReCheckWait() OVERRIDE; virtual GURL UpdateUrl() OVERRIDE; virtual size_t UrlSizeLimit() OVERRIDE; virtual net::URLRequestContextGetter* RequestContext() OVERRIDE; virtual bool InProcess() OVERRIDE; private: net::URLRequestContextGetter* url_request_getter_; bool fast_update_; bool out_of_process_; }; ChromeConfigurator::ChromeConfigurator(const CommandLine* cmdline, net::URLRequestContextGetter* url_request_getter) : url_request_getter_(url_request_getter) { // Parse comma-delimited debug flags. std::vector debug_values; Tokenize(cmdline->GetSwitchValueASCII(switches::kComponentUpdaterDebug), ",", &debug_values); fast_update_ = HasDebugValue(debug_values, kDebugFastUpdate); out_of_process_ = HasDebugValue(debug_values, kDebugOutOfProcess); } int ChromeConfigurator::InitialDelay() { return fast_update_ ? 1 : (6 * kDelayOneMinute); } int ChromeConfigurator::NextCheckDelay() { return fast_update_ ? 3 : (4 * kDelayOneHour); } int ChromeConfigurator::StepDelay() { return fast_update_ ? 1 : 4; } int ChromeConfigurator::MinimumReCheckWait() { return fast_update_ ? 30 : (6 * kDelayOneHour); } GURL ChromeConfigurator::UpdateUrl() { return GURL("http://clients2.google.com/service/update2/crx"); } size_t ChromeConfigurator::UrlSizeLimit() { return 1024ul; } net::URLRequestContextGetter* ChromeConfigurator::RequestContext() { return url_request_getter_; } bool ChromeConfigurator::InProcess() { return !out_of_process_; } ComponentUpdateService::Configurator* MakeChromeComponentUpdaterConfigurator( const CommandLine* cmdline, net::URLRequestContextGetter* context_getter) { return new ChromeConfigurator(cmdline, context_getter); }