Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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_service.h" | 5 #include "chrome/browser/component_updater/component_updater_service.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/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
| 14 #include "base/string_util.h" | 14 #include "base/string_util.h" |
| 15 #include "build/build_config.h" | |
| 15 #include "chrome/common/chrome_switches.h" | 16 #include "chrome/common/chrome_switches.h" |
| 16 #include "net/url_request/url_request_context_getter.h" | 17 #include "net/url_request/url_request_context_getter.h" |
| 17 | 18 |
| 18 namespace { | 19 namespace { |
| 19 // Default time constants. | 20 // Default time constants. |
| 20 const int kDelayOneMinute = 60; | 21 const int kDelayOneMinute = 60; |
| 21 const int kDelayOneHour = kDelayOneMinute * 60; | 22 const int kDelayOneHour = kDelayOneMinute * 60; |
| 22 | 23 |
| 23 // Debug values you can pass to --component-updater-debug=<value>. | 24 // Debug values you can pass to --component-updater-debug=<value>. |
| 24 const char kDebugFastUpdate[] = "fast-update"; | 25 const char kDebugFastUpdate[] = "fast-update"; |
| 25 const char kDebugOutOfProcess[] = "out-of-process"; | 26 const char kDebugOutOfProcess[] = "out-of-process"; |
| 26 | 27 |
| 27 bool HasDebugValue(const std::vector<std::string>& vec, const char* test) { | 28 bool HasDebugValue(const std::vector<std::string>& vec, const char* test) { |
| 28 if (vec.empty()) | 29 if (vec.empty()) |
| 29 return 0; | 30 return 0; |
| 30 return (std::find(vec.begin(), vec.end(), test) != vec.end()); | 31 return (std::find(vec.begin(), vec.end(), test) != vec.end()); |
| 31 } | 32 } |
| 32 | 33 |
| 34 // The request extra information is the OS and architecture, this helps | |
| 35 // the server select the right package to be delivered. | |
| 36 const char kExtraInfo[] = | |
| 37 #if defined(OS_MACOSX) | |
| 38 #if defined(__amd64__) | |
| 39 "os=mac&arch=x64"; | |
| 40 #elif defined(__i386__) | |
| 41 "os=mac&arch=x86"; | |
| 42 #else | |
| 43 "os=mac&arch=other"; | |
| 44 #endif | |
| 45 #elif defined(OS_WIN) | |
| 46 #if defined(_WIN64) | |
| 47 "os=win&arch=x64"; | |
| 48 #elif defined(_WIN32) | |
| 49 "os=win&arch=x86"; | |
| 50 #else | |
| 51 "os=win&arch=other"; | |
| 52 #endif | |
| 53 #elif defined(OS_LINUX) | |
| 54 #if defined(__amd64__) | |
| 55 "os=linux&arch=x64"; | |
| 56 #elif defined(__i386__) | |
| 57 "os=linux&arch=x86"; | |
| 58 #else | |
| 59 "os=linux&arch=other"; | |
| 60 #endif | |
| 61 #elif defined(OS_CHROMEOS) | |
| 62 #if defined(__i386__) | |
| 63 "os=cros&arch=x86"; | |
| 64 #else | |
| 65 "os=cros&arch=other"; | |
| 66 #endif | |
| 67 #else | |
| 68 "os=other&arch=other"; | |
|
asargent_no_longer_on_chrome
2011/10/04 23:29:42
Instead of using "other" here in the cases of new
| |
| 69 #endif | |
| 70 | |
| 33 } // namespace | 71 } // namespace |
| 34 | 72 |
| 35 class ChromeConfigurator : public ComponentUpdateService::Configurator { | 73 class ChromeConfigurator : public ComponentUpdateService::Configurator { |
| 36 public: | 74 public: |
| 37 ChromeConfigurator(const CommandLine* cmdline, | 75 ChromeConfigurator(const CommandLine* cmdline, |
| 38 net::URLRequestContextGetter* url_request_getter); | 76 net::URLRequestContextGetter* url_request_getter); |
| 39 | 77 |
| 40 virtual ~ChromeConfigurator() {} | 78 virtual ~ChromeConfigurator() {} |
| 41 | 79 |
| 42 virtual int InitialDelay() OVERRIDE; | 80 virtual int InitialDelay() OVERRIDE; |
| 43 virtual int NextCheckDelay() OVERRIDE; | 81 virtual int NextCheckDelay() OVERRIDE; |
| 44 virtual int StepDelay() OVERRIDE; | 82 virtual int StepDelay() OVERRIDE; |
| 45 virtual int MinimumReCheckWait() OVERRIDE; | 83 virtual int MinimumReCheckWait() OVERRIDE; |
| 46 virtual GURL UpdateUrl() OVERRIDE; | 84 virtual GURL UpdateUrl() OVERRIDE; |
| 85 virtual const char* ExtraRequestParams() OVERRIDE; | |
| 47 virtual size_t UrlSizeLimit() OVERRIDE; | 86 virtual size_t UrlSizeLimit() OVERRIDE; |
| 48 virtual net::URLRequestContextGetter* RequestContext() OVERRIDE; | 87 virtual net::URLRequestContextGetter* RequestContext() OVERRIDE; |
| 49 virtual bool InProcess() OVERRIDE; | 88 virtual bool InProcess() OVERRIDE; |
| 50 virtual void OnEvent(Events event, int val) OVERRIDE; | 89 virtual void OnEvent(Events event, int val) OVERRIDE; |
| 51 | 90 |
| 52 private: | 91 private: |
| 53 net::URLRequestContextGetter* url_request_getter_; | 92 net::URLRequestContextGetter* url_request_getter_; |
| 54 bool fast_update_; | 93 bool fast_update_; |
| 55 bool out_of_process_; | 94 bool out_of_process_; |
| 95 std::string extra_info_; | |
| 56 }; | 96 }; |
| 57 | 97 |
| 58 ChromeConfigurator::ChromeConfigurator(const CommandLine* cmdline, | 98 ChromeConfigurator::ChromeConfigurator(const CommandLine* cmdline, |
| 59 net::URLRequestContextGetter* url_request_getter) | 99 net::URLRequestContextGetter* url_request_getter) |
| 60 : url_request_getter_(url_request_getter) { | 100 : url_request_getter_(url_request_getter) { |
| 61 // Parse comma-delimited debug flags. | 101 // Parse comma-delimited debug flags. |
| 62 std::vector<std::string> debug_values; | 102 std::vector<std::string> debug_values; |
| 63 Tokenize(cmdline->GetSwitchValueASCII(switches::kComponentUpdaterDebug), | 103 Tokenize(cmdline->GetSwitchValueASCII(switches::kComponentUpdaterDebug), |
| 64 ",", &debug_values); | 104 ",", &debug_values); |
| 65 fast_update_ = HasDebugValue(debug_values, kDebugFastUpdate); | 105 fast_update_ = HasDebugValue(debug_values, kDebugFastUpdate); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 79 } | 119 } |
| 80 | 120 |
| 81 int ChromeConfigurator::MinimumReCheckWait() { | 121 int ChromeConfigurator::MinimumReCheckWait() { |
| 82 return fast_update_ ? 30 : (6 * kDelayOneHour); | 122 return fast_update_ ? 30 : (6 * kDelayOneHour); |
| 83 } | 123 } |
| 84 | 124 |
| 85 GURL ChromeConfigurator::UpdateUrl() { | 125 GURL ChromeConfigurator::UpdateUrl() { |
| 86 return GURL("http://clients2.google.com/service/update2/crx"); | 126 return GURL("http://clients2.google.com/service/update2/crx"); |
| 87 } | 127 } |
| 88 | 128 |
| 129 const char* ChromeConfigurator::ExtraRequestParams() { | |
| 130 return kExtraInfo; | |
| 131 } | |
| 132 | |
| 89 size_t ChromeConfigurator::UrlSizeLimit() { | 133 size_t ChromeConfigurator::UrlSizeLimit() { |
| 90 return 1024ul; | 134 return 1024ul; |
| 91 } | 135 } |
| 92 | 136 |
| 93 net::URLRequestContextGetter* ChromeConfigurator::RequestContext() { | 137 net::URLRequestContextGetter* ChromeConfigurator::RequestContext() { |
| 94 return url_request_getter_; | 138 return url_request_getter_; |
| 95 } | 139 } |
| 96 | 140 |
| 97 bool ChromeConfigurator::InProcess() { | 141 bool ChromeConfigurator::InProcess() { |
| 98 return !out_of_process_; | 142 return !out_of_process_; |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 122 NOTREACHED(); | 166 NOTREACHED(); |
| 123 break; | 167 break; |
| 124 } | 168 } |
| 125 } | 169 } |
| 126 | 170 |
| 127 ComponentUpdateService::Configurator* MakeChromeComponentUpdaterConfigurator( | 171 ComponentUpdateService::Configurator* MakeChromeComponentUpdaterConfigurator( |
| 128 const CommandLine* cmdline, net::URLRequestContextGetter* context_getter) { | 172 const CommandLine* cmdline, net::URLRequestContextGetter* context_getter) { |
| 129 return new ChromeConfigurator(cmdline, context_getter); | 173 return new ChromeConfigurator(cmdline, context_getter); |
| 130 } | 174 } |
| 131 | 175 |
| OLD | NEW |