| 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 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 const int kDelayOneMinute = 60; | 22 const int kDelayOneMinute = 60; |
| 23 const int kDelayOneHour = kDelayOneMinute * 60; | 23 const int kDelayOneHour = kDelayOneMinute * 60; |
| 24 | 24 |
| 25 // Debug values you can pass to --component-updater-debug=value1,value2. | 25 // Debug values you can pass to --component-updater-debug=value1,value2. |
| 26 // Speed up component checking. | 26 // Speed up component checking. |
| 27 const char kDebugFastUpdate[] = "fast-update"; | 27 const char kDebugFastUpdate[] = "fast-update"; |
| 28 // Force out-of-process-xml parsing. | 28 // Force out-of-process-xml parsing. |
| 29 const char kDebugOutOfProcess[] = "out-of-process"; | 29 const char kDebugOutOfProcess[] = "out-of-process"; |
| 30 // Add "testrequest=1" parameter to the update check query. | 30 // Add "testrequest=1" parameter to the update check query. |
| 31 const char kDebugRequestParam[] = "test-request"; | 31 const char kDebugRequestParam[] = "test-request"; |
| 32 // Use the sandbox/staging Omaha for debugging instead of Omaha. |
| 33 const char kDebugUpdateURL[] = "staging-update-url"; |
| 34 |
| 32 | 35 |
| 33 bool HasDebugValue(const std::vector<std::string>& vec, const char* test) { | 36 bool HasDebugValue(const std::vector<std::string>& vec, const char* test) { |
| 34 if (vec.empty()) | 37 if (vec.empty()) |
| 35 return 0; | 38 return 0; |
| 36 return (std::find(vec.begin(), vec.end(), test) != vec.end()); | 39 return (std::find(vec.begin(), vec.end(), test) != vec.end()); |
| 37 } | 40 } |
| 38 | 41 |
| 39 // The request extra information is the OS and architecture, this helps | 42 // The request extra information is the OS and architecture, this helps |
| 40 // the server select the right package to be delivered. | 43 // the server select the right package to be delivered. |
| 41 const char kExtraInfo[] = | 44 const char kExtraInfo[] = |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 virtual size_t UrlSizeLimit() OVERRIDE; | 98 virtual size_t UrlSizeLimit() OVERRIDE; |
| 96 virtual net::URLRequestContextGetter* RequestContext() OVERRIDE; | 99 virtual net::URLRequestContextGetter* RequestContext() OVERRIDE; |
| 97 virtual bool InProcess() OVERRIDE; | 100 virtual bool InProcess() OVERRIDE; |
| 98 virtual void OnEvent(Events event, int val) OVERRIDE; | 101 virtual void OnEvent(Events event, int val) OVERRIDE; |
| 99 | 102 |
| 100 private: | 103 private: |
| 101 net::URLRequestContextGetter* url_request_getter_; | 104 net::URLRequestContextGetter* url_request_getter_; |
| 102 std::string extra_info_; | 105 std::string extra_info_; |
| 103 bool fast_update_; | 106 bool fast_update_; |
| 104 bool out_of_process_; | 107 bool out_of_process_; |
| 108 bool use_debug_url_; |
| 105 }; | 109 }; |
| 106 | 110 |
| 107 ChromeConfigurator::ChromeConfigurator(const CommandLine* cmdline, | 111 ChromeConfigurator::ChromeConfigurator(const CommandLine* cmdline, |
| 108 net::URLRequestContextGetter* url_request_getter) | 112 net::URLRequestContextGetter* url_request_getter) |
| 109 : url_request_getter_(url_request_getter), | 113 : url_request_getter_(url_request_getter), |
| 110 extra_info_(kExtraInfo) { | 114 extra_info_(kExtraInfo) { |
| 111 // Parse comma-delimited debug flags. | 115 // Parse comma-delimited debug flags. |
| 112 std::vector<std::string> debug_values; | 116 std::vector<std::string> debug_values; |
| 113 Tokenize(cmdline->GetSwitchValueASCII(switches::kComponentUpdaterDebug), | 117 Tokenize(cmdline->GetSwitchValueASCII(switches::kComponentUpdaterDebug), |
| 114 ",", &debug_values); | 118 ",", &debug_values); |
| 115 fast_update_ = HasDebugValue(debug_values, kDebugFastUpdate); | 119 fast_update_ = HasDebugValue(debug_values, kDebugFastUpdate); |
| 116 out_of_process_ = HasDebugValue(debug_values, kDebugOutOfProcess); | 120 out_of_process_ = HasDebugValue(debug_values, kDebugOutOfProcess); |
| 121 use_debug_url_ = HasDebugValue(debug_values, kDebugUpdateURL); |
| 122 |
| 117 // Make the extra request params, they are necessary so omaha does | 123 // Make the extra request params, they are necessary so omaha does |
| 118 // not deliver components that are going to be rejected at install time. | 124 // not deliver components that are going to be rejected at install time. |
| 119 extra_info_ += chrome::VersionInfo().Version(); | 125 extra_info_ += chrome::VersionInfo().Version(); |
| 120 if (HasDebugValue(debug_values, kDebugRequestParam)) | 126 if (HasDebugValue(debug_values, kDebugRequestParam)) |
| 121 extra_info_ += "&testrequest=1"; | 127 extra_info_ += "&testrequest=1"; |
| 122 } | 128 } |
| 123 | 129 |
| 124 int ChromeConfigurator::InitialDelay() { | 130 int ChromeConfigurator::InitialDelay() { |
| 125 return fast_update_ ? 1 : (6 * kDelayOneMinute); | 131 return fast_update_ ? 1 : (6 * kDelayOneMinute); |
| 126 } | 132 } |
| 127 | 133 |
| 128 int ChromeConfigurator::NextCheckDelay() { | 134 int ChromeConfigurator::NextCheckDelay() { |
| 129 return fast_update_ ? 3 : (4 * kDelayOneHour); | 135 return fast_update_ ? 3 : (4 * kDelayOneHour); |
| 130 } | 136 } |
| 131 | 137 |
| 132 int ChromeConfigurator::StepDelay() { | 138 int ChromeConfigurator::StepDelay() { |
| 133 return fast_update_ ? 1 : 4; | 139 return fast_update_ ? 1 : 4; |
| 134 } | 140 } |
| 135 | 141 |
| 136 int ChromeConfigurator::MinimumReCheckWait() { | 142 int ChromeConfigurator::MinimumReCheckWait() { |
| 137 return fast_update_ ? 30 : (6 * kDelayOneHour); | 143 return fast_update_ ? 30 : (6 * kDelayOneHour); |
| 138 } | 144 } |
| 139 | 145 |
| 140 GURL ChromeConfigurator::UpdateUrl() { | 146 GURL ChromeConfigurator::UpdateUrl() { |
| 141 return GURL("http://clients2.google.com/service/update2/crx"); | 147 if (!use_debug_url_) { |
| 148 return GURL("http://clients2.google.com/service/update2/crx"); |
| 149 } else { |
| 150 return GURL("http://omaha.sandbox.google.com/service/update2/crx"); |
| 151 } |
| 142 } | 152 } |
| 143 | 153 |
| 144 const char* ChromeConfigurator::ExtraRequestParams() { | 154 const char* ChromeConfigurator::ExtraRequestParams() { |
| 145 return extra_info_.c_str(); | 155 return extra_info_.c_str(); |
| 146 } | 156 } |
| 147 | 157 |
| 148 size_t ChromeConfigurator::UrlSizeLimit() { | 158 size_t ChromeConfigurator::UrlSizeLimit() { |
| 149 return 1024ul; | 159 return 1024ul; |
| 150 } | 160 } |
| 151 | 161 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 180 default: | 190 default: |
| 181 NOTREACHED(); | 191 NOTREACHED(); |
| 182 break; | 192 break; |
| 183 } | 193 } |
| 184 } | 194 } |
| 185 | 195 |
| 186 ComponentUpdateService::Configurator* MakeChromeComponentUpdaterConfigurator( | 196 ComponentUpdateService::Configurator* MakeChromeComponentUpdaterConfigurator( |
| 187 const CommandLine* cmdline, net::URLRequestContextGetter* context_getter) { | 197 const CommandLine* cmdline, net::URLRequestContextGetter* context_getter) { |
| 188 return new ChromeConfigurator(cmdline, context_getter); | 198 return new ChromeConfigurator(cmdline, context_getter); |
| 189 } | 199 } |
| OLD | NEW |