| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_configurator.h" | 5 #include "chrome/browser/component_updater/component_updater_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/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
| 14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
| 15 #include "base/win/windows_version.h" | 15 #include "base/win/windows_version.h" |
| 16 #include "build/build_config.h" | 16 #include "build/build_config.h" |
| 17 #include "chrome/browser/component_updater/component_patcher.h" | |
| 18 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
| 19 #include "chrome/common/omaha_query_params/omaha_query_params.h" | 18 #include "chrome/common/omaha_query_params/omaha_query_params.h" |
| 20 #include "net/url_request/url_request_context_getter.h" | 19 #include "net/url_request/url_request_context_getter.h" |
| 21 | 20 |
| 22 #if defined(OS_WIN) | |
| 23 #include "chrome/browser/component_updater/component_patcher_win.h" | |
| 24 #endif | |
| 25 | |
| 26 namespace { | 21 namespace { |
| 27 | |
| 28 // Default time constants. | 22 // Default time constants. |
| 29 const int kDelayOneMinute = 60; | 23 const int kDelayOneMinute = 60; |
| 30 const int kDelayOneHour = kDelayOneMinute * 60; | 24 const int kDelayOneHour = kDelayOneMinute * 60; |
| 31 | 25 |
| 32 // Debug values you can pass to --component-updater-debug=value1,value2. | 26 // Debug values you can pass to --component-updater-debug=value1,value2. |
| 33 // Speed up component checking. | 27 // Speed up component checking. |
| 34 const char kSwitchFastUpdate[] = "fast-update"; | 28 const char kDebugFastUpdate[] = "fast-update"; |
| 35 // Force out-of-process-xml parsing. | 29 // Force out-of-process-xml parsing. |
| 36 const char kSwitchOutOfProcess[] = "out-of-process"; | 30 const char kDebugOutOfProcess[] = "out-of-process"; |
| 37 // Add "testrequest=1" parameter to the update check query. | 31 // Add "testrequest=1" parameter to the update check query. |
| 38 const char kSwitchRequestParam[] = "test-request"; | 32 const char kDebugRequestParam[] = "test-request"; |
| 39 // Disables differential updates. | |
| 40 const char kSwitchDisableDeltaUpdates[] = "disable-delta-updates"; | |
| 41 | 33 |
| 42 // The urls from which an update manifest can be fetched. | 34 // The urls from which an update manifest can be fetched. |
| 43 const char* kUrlSources[] = { | 35 const char* kUrlSources[] = { |
| 44 "http://clients2.google.com/service/update2/crx", // BANDAID | 36 "http://clients2.google.com/service/update2/crx", // BANDAID |
| 45 "http://omaha.google.com/service/update2/crx", // CWS_PUBLIC | 37 "http://omaha.google.com/service/update2/crx", // CWS_PUBLIC |
| 46 "http://omaha.sandbox.google.com/service/update2/crx", // CWS_SANDBOX | 38 "http://omaha.sandbox.google.com/service/update2/crx" // CWS_SANDBOX |
| 47 }; | 39 }; |
| 48 | 40 |
| 49 bool HasSwitchValue(const std::vector<std::string>& vec, const char* test) { | 41 bool HasDebugValue(const std::vector<std::string>& vec, const char* test) { |
| 50 if (vec.empty()) | 42 if (vec.empty()) |
| 51 return 0; | 43 return 0; |
| 52 return (std::find(vec.begin(), vec.end(), test) != vec.end()); | 44 return (std::find(vec.begin(), vec.end(), test) != vec.end()); |
| 53 } | 45 } |
| 54 | 46 |
| 55 } // namespace | 47 } // namespace |
| 56 | 48 |
| 57 class ChromeConfigurator : public ComponentUpdateService::Configurator { | 49 class ChromeConfigurator : public ComponentUpdateService::Configurator { |
| 58 public: | 50 public: |
| 59 ChromeConfigurator(const CommandLine* cmdline, | 51 ChromeConfigurator(const CommandLine* cmdline, |
| 60 net::URLRequestContextGetter* url_request_getter); | 52 net::URLRequestContextGetter* url_request_getter); |
| 61 | 53 |
| 62 virtual ~ChromeConfigurator() {} | 54 virtual ~ChromeConfigurator() {} |
| 63 | 55 |
| 64 virtual int InitialDelay() OVERRIDE; | 56 virtual int InitialDelay() OVERRIDE; |
| 65 virtual int NextCheckDelay() OVERRIDE; | 57 virtual int NextCheckDelay() OVERRIDE; |
| 66 virtual int StepDelay() OVERRIDE; | 58 virtual int StepDelay() OVERRIDE; |
| 67 virtual int MinimumReCheckWait() OVERRIDE; | 59 virtual int MinimumReCheckWait() OVERRIDE; |
| 68 virtual int OnDemandDelay() OVERRIDE; | 60 virtual int OnDemandDelay() OVERRIDE; |
| 69 virtual GURL UpdateUrl(CrxComponent::UrlSource source) OVERRIDE; | 61 virtual GURL UpdateUrl(CrxComponent::UrlSource source) OVERRIDE; |
| 70 virtual const char* ExtraRequestParams() OVERRIDE; | 62 virtual const char* ExtraRequestParams() OVERRIDE; |
| 71 virtual size_t UrlSizeLimit() OVERRIDE; | 63 virtual size_t UrlSizeLimit() OVERRIDE; |
| 72 virtual net::URLRequestContextGetter* RequestContext() OVERRIDE; | 64 virtual net::URLRequestContextGetter* RequestContext() OVERRIDE; |
| 73 virtual bool InProcess() OVERRIDE; | 65 virtual bool InProcess() OVERRIDE; |
| 74 virtual void OnEvent(Events event, int val) OVERRIDE; | 66 virtual void OnEvent(Events event, int val) OVERRIDE; |
| 75 virtual ComponentPatcher* CreateComponentPatcher() OVERRIDE; | |
| 76 virtual bool DeltasEnabled() const OVERRIDE; | |
| 77 | 67 |
| 78 private: | 68 private: |
| 79 net::URLRequestContextGetter* url_request_getter_; | 69 net::URLRequestContextGetter* url_request_getter_; |
| 80 std::string extra_info_; | 70 std::string extra_info_; |
| 81 bool fast_update_; | 71 bool fast_update_; |
| 82 bool out_of_process_; | 72 bool out_of_process_; |
| 83 bool deltas_enabled_; | |
| 84 }; | 73 }; |
| 85 | 74 |
| 86 ChromeConfigurator::ChromeConfigurator(const CommandLine* cmdline, | 75 ChromeConfigurator::ChromeConfigurator(const CommandLine* cmdline, |
| 87 net::URLRequestContextGetter* url_request_getter) | 76 net::URLRequestContextGetter* url_request_getter) |
| 88 : url_request_getter_(url_request_getter), | 77 : url_request_getter_(url_request_getter), |
| 89 extra_info_(chrome::OmahaQueryParams::Get( | 78 extra_info_(chrome::OmahaQueryParams::Get( |
| 90 chrome::OmahaQueryParams::CHROME)), | 79 chrome::OmahaQueryParams::CHROME)) { |
| 91 fast_update_(false), | |
| 92 out_of_process_(false), | |
| 93 deltas_enabled_(false) { | |
| 94 // Parse comma-delimited debug flags. | 80 // Parse comma-delimited debug flags. |
| 95 std::vector<std::string> switch_values; | 81 std::vector<std::string> debug_values; |
| 96 Tokenize(cmdline->GetSwitchValueASCII(switches::kComponentUpdater), | 82 Tokenize(cmdline->GetSwitchValueASCII(switches::kComponentUpdaterDebug), |
| 97 ",", &switch_values); | 83 ",", &debug_values); |
| 98 fast_update_ = HasSwitchValue(switch_values, kSwitchFastUpdate); | 84 fast_update_ = HasDebugValue(debug_values, kDebugFastUpdate); |
| 99 out_of_process_ = HasSwitchValue(switch_values, kSwitchOutOfProcess); | 85 out_of_process_ = HasDebugValue(debug_values, kDebugOutOfProcess); |
| 100 #if defined(OS_WIN) | |
| 101 deltas_enabled_ = !HasSwitchValue(switch_values, kSwitchDisableDeltaUpdates); | |
| 102 #else | |
| 103 deltas_enabled_ = false; | |
| 104 #endif | |
| 105 | 86 |
| 106 // Make the extra request params, they are necessary so omaha does | 87 // Make the extra request params, they are necessary so omaha does |
| 107 // not deliver components that are going to be rejected at install time. | 88 // not deliver components that are going to be rejected at install time. |
| 108 #if defined(OS_WIN) | 89 #if defined(OS_WIN) |
| 109 if (base::win::OSInfo::GetInstance()->wow64_status() == | 90 if (base::win::OSInfo::GetInstance()->wow64_status() == |
| 110 base::win::OSInfo::WOW64_ENABLED) | 91 base::win::OSInfo::WOW64_ENABLED) |
| 111 extra_info_ += "&wow64=1"; | 92 extra_info_ += "&wow64=1"; |
| 112 #endif | 93 #endif |
| 113 if (HasSwitchValue(switch_values, kSwitchRequestParam)) | 94 if (HasDebugValue(debug_values, kDebugRequestParam)) |
| 114 extra_info_ += "&testrequest=1"; | 95 extra_info_ += "&testrequest=1"; |
| 115 } | 96 } |
| 116 | 97 |
| 117 int ChromeConfigurator::InitialDelay() { | 98 int ChromeConfigurator::InitialDelay() { |
| 118 return fast_update_ ? 1 : (6 * kDelayOneMinute); | 99 return fast_update_ ? 1 : (6 * kDelayOneMinute); |
| 119 } | 100 } |
| 120 | 101 |
| 121 int ChromeConfigurator::NextCheckDelay() { | 102 int ChromeConfigurator::NextCheckDelay() { |
| 122 return fast_update_ ? 3 : (2 * kDelayOneHour); | 103 return fast_update_ ? 3 : (2 * kDelayOneHour); |
| 123 } | 104 } |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 break; | 154 break; |
| 174 case kInstallerError: | 155 case kInstallerError: |
| 175 UMA_HISTOGRAM_ENUMERATION("ComponentUpdater.InstallError", val, 100); | 156 UMA_HISTOGRAM_ENUMERATION("ComponentUpdater.InstallError", val, 100); |
| 176 break; | 157 break; |
| 177 default: | 158 default: |
| 178 NOTREACHED(); | 159 NOTREACHED(); |
| 179 break; | 160 break; |
| 180 } | 161 } |
| 181 } | 162 } |
| 182 | 163 |
| 183 ComponentPatcher* ChromeConfigurator::CreateComponentPatcher() { | |
| 184 #if defined(OS_WIN) | |
| 185 return new ComponentPatcherWin(); | |
| 186 #else | |
| 187 return new ComponentPatcherCrossPlatform(); | |
| 188 #endif | |
| 189 } | |
| 190 | |
| 191 bool ChromeConfigurator::DeltasEnabled() const { | |
| 192 return deltas_enabled_; | |
| 193 } | |
| 194 | |
| 195 ComponentUpdateService::Configurator* MakeChromeComponentUpdaterConfigurator( | 164 ComponentUpdateService::Configurator* MakeChromeComponentUpdaterConfigurator( |
| 196 const CommandLine* cmdline, net::URLRequestContextGetter* context_getter) { | 165 const CommandLine* cmdline, net::URLRequestContextGetter* context_getter) { |
| 197 return new ChromeConfigurator(cmdline, context_getter); | 166 return new ChromeConfigurator(cmdline, context_getter); |
| 198 } | 167 } |
| OLD | NEW |