| 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" |
| 17 #include "chrome/common/chrome_switches.h" | 18 #include "chrome/common/chrome_switches.h" |
| 18 #include "chrome/common/omaha_query_params/omaha_query_params.h" | 19 #include "chrome/common/omaha_query_params/omaha_query_params.h" |
| 19 #include "net/url_request/url_request_context_getter.h" | 20 #include "net/url_request/url_request_context_getter.h" |
| 20 | 21 |
| 22 #if defined(OS_WIN) |
| 23 #include "chrome/browser/component_updater/component_patcher_win.h" |
| 24 #endif |
| 25 |
| 21 namespace { | 26 namespace { |
| 27 |
| 22 // Default time constants. | 28 // Default time constants. |
| 23 const int kDelayOneMinute = 60; | 29 const int kDelayOneMinute = 60; |
| 24 const int kDelayOneHour = kDelayOneMinute * 60; | 30 const int kDelayOneHour = kDelayOneMinute * 60; |
| 25 | 31 |
| 26 // Debug values you can pass to --component-updater-debug=value1,value2. | 32 // Debug values you can pass to --component-updater-debug=value1,value2. |
| 27 // Speed up component checking. | 33 // Speed up component checking. |
| 28 const char kDebugFastUpdate[] = "fast-update"; | 34 const char kDebugFastUpdate[] = "fast-update"; |
| 29 // Force out-of-process-xml parsing. | 35 // Force out-of-process-xml parsing. |
| 30 const char kDebugOutOfProcess[] = "out-of-process"; | 36 const char kDebugOutOfProcess[] = "out-of-process"; |
| 31 // Add "testrequest=1" parameter to the update check query. | 37 // Add "testrequest=1" parameter to the update check query. |
| 32 const char kDebugRequestParam[] = "test-request"; | 38 const char kDebugRequestParam[] = "test-request"; |
| 33 | 39 |
| 34 // The urls from which an update manifest can be fetched. | 40 // The urls from which an update manifest can be fetched. |
| 35 const char* kUrlSources[] = { | 41 const char* kUrlSources[] = { |
| 36 "http://clients2.google.com/service/update2/crx", // BANDAID | 42 "http://clients2.google.com/service/update2/crx", // BANDAID |
| 37 "http://omaha.google.com/service/update2/crx", // CWS_PUBLIC | 43 "http://omaha.google.com/service/update2/crx", // CWS_PUBLIC |
| 38 "http://omaha.sandbox.google.com/service/update2/crx" // CWS_SANDBOX | 44 "http://omaha.sandbox.google.com/service/update2/crx", // CWS_SANDBOX |
| 39 }; | 45 }; |
| 40 | 46 |
| 47 // The url to send the completion pings to. Completion pings are sent when |
| 48 // updates have completed, either successfully or with errors. |
| 49 const char kUrlPing[] = "http://tools.google.com/service/update2"; |
| 50 |
| 41 bool HasDebugValue(const std::vector<std::string>& vec, const char* test) { | 51 bool HasDebugValue(const std::vector<std::string>& vec, const char* test) { |
| 42 if (vec.empty()) | 52 if (vec.empty()) |
| 43 return 0; | 53 return 0; |
| 44 return (std::find(vec.begin(), vec.end(), test) != vec.end()); | 54 return (std::find(vec.begin(), vec.end(), test) != vec.end()); |
| 45 } | 55 } |
| 46 | 56 |
| 47 } // namespace | 57 } // namespace |
| 48 | 58 |
| 49 class ChromeConfigurator : public ComponentUpdateService::Configurator { | 59 class ChromeConfigurator : public ComponentUpdateService::Configurator { |
| 50 public: | 60 public: |
| 51 ChromeConfigurator(const CommandLine* cmdline, | 61 ChromeConfigurator(const CommandLine* cmdline, |
| 52 net::URLRequestContextGetter* url_request_getter); | 62 net::URLRequestContextGetter* url_request_getter); |
| 53 | 63 |
| 54 virtual ~ChromeConfigurator() {} | 64 virtual ~ChromeConfigurator() {} |
| 55 | 65 |
| 56 virtual int InitialDelay() OVERRIDE; | 66 virtual int InitialDelay() OVERRIDE; |
| 57 virtual int NextCheckDelay() OVERRIDE; | 67 virtual int NextCheckDelay() OVERRIDE; |
| 58 virtual int StepDelay() OVERRIDE; | 68 virtual int StepDelay() OVERRIDE; |
| 59 virtual int MinimumReCheckWait() OVERRIDE; | 69 virtual int MinimumReCheckWait() OVERRIDE; |
| 60 virtual int OnDemandDelay() OVERRIDE; | 70 virtual int OnDemandDelay() OVERRIDE; |
| 61 virtual GURL UpdateUrl(CrxComponent::UrlSource source) OVERRIDE; | 71 virtual GURL UpdateUrl(CrxComponent::UrlSource source) OVERRIDE; |
| 72 virtual GURL PingUrl() OVERRIDE; |
| 62 virtual const char* ExtraRequestParams() OVERRIDE; | 73 virtual const char* ExtraRequestParams() OVERRIDE; |
| 63 virtual size_t UrlSizeLimit() OVERRIDE; | 74 virtual size_t UrlSizeLimit() OVERRIDE; |
| 64 virtual net::URLRequestContextGetter* RequestContext() OVERRIDE; | 75 virtual net::URLRequestContextGetter* RequestContext() OVERRIDE; |
| 65 virtual bool InProcess() OVERRIDE; | 76 virtual bool InProcess() OVERRIDE; |
| 66 virtual void OnEvent(Events event, int val) OVERRIDE; | 77 virtual void OnEvent(Events event, int val) OVERRIDE; |
| 78 virtual ComponentPatcher* CreateComponentPatcher() OVERRIDE; |
| 79 virtual bool DeltasEnabled() const OVERRIDE; |
| 67 | 80 |
| 68 private: | 81 private: |
| 69 net::URLRequestContextGetter* url_request_getter_; | 82 net::URLRequestContextGetter* url_request_getter_; |
| 70 std::string extra_info_; | 83 std::string extra_info_; |
| 71 bool fast_update_; | 84 bool fast_update_; |
| 72 bool out_of_process_; | 85 bool out_of_process_; |
| 86 bool pings_enabled_; |
| 87 bool deltas_enabled_; |
| 73 }; | 88 }; |
| 74 | 89 |
| 75 ChromeConfigurator::ChromeConfigurator(const CommandLine* cmdline, | 90 ChromeConfigurator::ChromeConfigurator(const CommandLine* cmdline, |
| 76 net::URLRequestContextGetter* url_request_getter) | 91 net::URLRequestContextGetter* url_request_getter) |
| 77 : url_request_getter_(url_request_getter), | 92 : url_request_getter_(url_request_getter), |
| 78 extra_info_(chrome::OmahaQueryParams::Get( | 93 extra_info_(chrome::OmahaQueryParams::Get( |
| 79 chrome::OmahaQueryParams::CHROME)) { | 94 chrome::OmahaQueryParams::CHROME)), |
| 95 fast_update_(false), |
| 96 out_of_process_(false), |
| 97 pings_enabled_(false), |
| 98 deltas_enabled_(false) { |
| 80 // Parse comma-delimited debug flags. | 99 // Parse comma-delimited debug flags. |
| 81 std::vector<std::string> debug_values; | 100 std::vector<std::string> debug_values; |
| 82 Tokenize(cmdline->GetSwitchValueASCII(switches::kComponentUpdaterDebug), | 101 Tokenize(cmdline->GetSwitchValueASCII(switches::kComponentUpdaterDebug), |
| 83 ",", &debug_values); | 102 ",", &debug_values); |
| 84 fast_update_ = HasDebugValue(debug_values, kDebugFastUpdate); | 103 fast_update_ = HasDebugValue(debug_values, kDebugFastUpdate); |
| 85 out_of_process_ = HasDebugValue(debug_values, kDebugOutOfProcess); | 104 out_of_process_ = HasDebugValue(debug_values, kDebugOutOfProcess); |
| 86 | 105 |
| 106 // Parse other command-ling flags. |
| 107 pings_enabled_ = cmdline->HasSwitch(switches::kEnableComponentUpdatePings); |
| 108 #if defined(OS_WIN) |
| 109 deltas_enabled_ = cmdline->HasSwitch(switches::kEnableComponentUpdateDeltas); |
| 110 #else |
| 111 deltas_enabled_ = false; |
| 112 #endif |
| 113 |
| 87 // Make the extra request params, they are necessary so omaha does | 114 // Make the extra request params, they are necessary so omaha does |
| 88 // not deliver components that are going to be rejected at install time. | 115 // not deliver components that are going to be rejected at install time. |
| 89 #if defined(OS_WIN) | 116 #if defined(OS_WIN) |
| 90 if (base::win::OSInfo::GetInstance()->wow64_status() == | 117 if (base::win::OSInfo::GetInstance()->wow64_status() == |
| 91 base::win::OSInfo::WOW64_ENABLED) | 118 base::win::OSInfo::WOW64_ENABLED) |
| 92 extra_info_ += "&wow64=1"; | 119 extra_info_ += "&wow64=1"; |
| 93 #endif | 120 #endif |
| 94 if (HasDebugValue(debug_values, kDebugRequestParam)) | 121 if (HasDebugValue(debug_values, kDebugRequestParam)) |
| 95 extra_info_ += "&testrequest=1"; | 122 extra_info_ += "&testrequest=1"; |
| 96 } | 123 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 112 } | 139 } |
| 113 | 140 |
| 114 int ChromeConfigurator::OnDemandDelay() { | 141 int ChromeConfigurator::OnDemandDelay() { |
| 115 return fast_update_ ? 2 : (30 * kDelayOneMinute); | 142 return fast_update_ ? 2 : (30 * kDelayOneMinute); |
| 116 } | 143 } |
| 117 | 144 |
| 118 GURL ChromeConfigurator::UpdateUrl(CrxComponent::UrlSource source) { | 145 GURL ChromeConfigurator::UpdateUrl(CrxComponent::UrlSource source) { |
| 119 return GURL(kUrlSources[source]); | 146 return GURL(kUrlSources[source]); |
| 120 } | 147 } |
| 121 | 148 |
| 149 GURL ChromeConfigurator::PingUrl() { |
| 150 return pings_enabled_ ? GURL(kUrlPing) : GURL(); |
| 151 } |
| 152 |
| 122 const char* ChromeConfigurator::ExtraRequestParams() { | 153 const char* ChromeConfigurator::ExtraRequestParams() { |
| 123 return extra_info_.c_str(); | 154 return extra_info_.c_str(); |
| 124 } | 155 } |
| 125 | 156 |
| 126 size_t ChromeConfigurator::UrlSizeLimit() { | 157 size_t ChromeConfigurator::UrlSizeLimit() { |
| 127 return 1024ul; | 158 return 1024ul; |
| 128 } | 159 } |
| 129 | 160 |
| 130 net::URLRequestContextGetter* ChromeConfigurator::RequestContext() { | 161 net::URLRequestContextGetter* ChromeConfigurator::RequestContext() { |
| 131 return url_request_getter_; | 162 return url_request_getter_; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 154 break; | 185 break; |
| 155 case kInstallerError: | 186 case kInstallerError: |
| 156 UMA_HISTOGRAM_ENUMERATION("ComponentUpdater.InstallError", val, 100); | 187 UMA_HISTOGRAM_ENUMERATION("ComponentUpdater.InstallError", val, 100); |
| 157 break; | 188 break; |
| 158 default: | 189 default: |
| 159 NOTREACHED(); | 190 NOTREACHED(); |
| 160 break; | 191 break; |
| 161 } | 192 } |
| 162 } | 193 } |
| 163 | 194 |
| 195 ComponentPatcher* ChromeConfigurator::CreateComponentPatcher() { |
| 196 #if defined(OS_WIN) |
| 197 return new ComponentPatcherWin(); |
| 198 #else |
| 199 return new ComponentPatcherCrossPlatform(); |
| 200 #endif |
| 201 } |
| 202 |
| 203 bool ChromeConfigurator::DeltasEnabled() const { |
| 204 return deltas_enabled_; |
| 205 } |
| 206 |
| 164 ComponentUpdateService::Configurator* MakeChromeComponentUpdaterConfigurator( | 207 ComponentUpdateService::Configurator* MakeChromeComponentUpdaterConfigurator( |
| 165 const CommandLine* cmdline, net::URLRequestContextGetter* context_getter) { | 208 const CommandLine* cmdline, net::URLRequestContextGetter* context_getter) { |
| 166 return new ChromeConfigurator(cmdline, context_getter); | 209 return new ChromeConfigurator(cmdline, context_getter); |
| 167 } | 210 } |
| OLD | NEW |