OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/component_updater/component_updater_service.h" |
| 6 |
| 7 #include <algorithm> |
| 8 #include <string> |
| 9 #include <vector> |
| 10 |
| 11 #include "base/command_line.h" |
| 12 #include "base/compiler_specific.h" |
| 13 #include "base/string_util.h" |
| 14 #include "chrome/common/chrome_switches.h" |
| 15 #include "net/url_request/url_request_context_getter.h" |
| 16 |
| 17 namespace { |
| 18 // Default time constants. |
| 19 const int kDelayOneMinute = 60; |
| 20 const int kDelayOneHour = kDelayOneMinute * 60; |
| 21 |
| 22 // Debug values you can pass to --component-updater-debug=<value>. |
| 23 const char kDebugFastUpdate[] = "fast-update"; |
| 24 const char kDebugOutOfProcess[] = "out-of-process"; |
| 25 |
| 26 bool HasDebugValue(const std::vector<std::string>& vec, const char* test) { |
| 27 if (vec.empty()) |
| 28 return 0; |
| 29 return (std::find(vec.begin(), vec.end(), test) != vec.end()); |
| 30 } |
| 31 |
| 32 } // namespace |
| 33 |
| 34 class ChromeConfigurator : public ComponentUpdateService::Configurator { |
| 35 public: |
| 36 ChromeConfigurator(const CommandLine* cmdline, |
| 37 net::URLRequestContextGetter* url_request_getter); |
| 38 |
| 39 virtual ~ChromeConfigurator() {} |
| 40 |
| 41 virtual int InitialDelay() OVERRIDE; |
| 42 virtual int NextCheckDelay() OVERRIDE; |
| 43 virtual int StepDelay() OVERRIDE; |
| 44 virtual int MinimumReCheckWait() OVERRIDE; |
| 45 virtual GURL UpdateUrl() OVERRIDE; |
| 46 virtual size_t UrlSizeLimit() OVERRIDE; |
| 47 virtual net::URLRequestContextGetter* RequestContext() OVERRIDE; |
| 48 virtual bool InProcess() OVERRIDE; |
| 49 |
| 50 private: |
| 51 net::URLRequestContextGetter* url_request_getter_; |
| 52 bool fast_update_; |
| 53 bool out_of_process_; |
| 54 }; |
| 55 |
| 56 ChromeConfigurator::ChromeConfigurator(const CommandLine* cmdline, |
| 57 net::URLRequestContextGetter* url_request_getter) |
| 58 : url_request_getter_(url_request_getter) { |
| 59 // Parse comma-delimited debug flags. |
| 60 std::vector<std::string> debug_values; |
| 61 Tokenize(cmdline->GetSwitchValueASCII(switches::kComponentUpdaterDebug), |
| 62 ",", &debug_values); |
| 63 fast_update_ = HasDebugValue(debug_values, kDebugFastUpdate); |
| 64 out_of_process_ = HasDebugValue(debug_values, kDebugOutOfProcess); |
| 65 } |
| 66 |
| 67 int ChromeConfigurator::InitialDelay() { |
| 68 return fast_update_ ? 1 : (6 * kDelayOneMinute); |
| 69 } |
| 70 |
| 71 int ChromeConfigurator::NextCheckDelay() { |
| 72 return fast_update_ ? 3 : (4 * kDelayOneHour); |
| 73 } |
| 74 |
| 75 int ChromeConfigurator::StepDelay() { |
| 76 return fast_update_ ? 1 : 4; |
| 77 } |
| 78 |
| 79 int ChromeConfigurator::MinimumReCheckWait() { |
| 80 return fast_update_ ? 30 : (6 * kDelayOneHour); |
| 81 } |
| 82 |
| 83 GURL ChromeConfigurator::UpdateUrl() { |
| 84 return GURL("http://clients2.google.com/service/update2/crx"); |
| 85 } |
| 86 |
| 87 size_t ChromeConfigurator::UrlSizeLimit() { |
| 88 return 1024ul; |
| 89 } |
| 90 |
| 91 net::URLRequestContextGetter* ChromeConfigurator::RequestContext() { |
| 92 return url_request_getter_; |
| 93 } |
| 94 |
| 95 bool ChromeConfigurator::InProcess() { |
| 96 return out_of_process_; |
| 97 } |
| 98 |
| 99 ComponentUpdateService::Configurator* MakeChromeComponentUpdaterConfigurator( |
| 100 const CommandLine* cmdline, net::URLRequestContextGetter* context_getter) { |
| 101 return new ChromeConfigurator(cmdline, context_getter); |
| 102 } |
| 103 |
OLD | NEW |