Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(97)

Side by Side Diff: chrome/browser/component_updater/component_updater_configurator.cc

Issue 18516010: Implemented completion pings for component updates. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/component_updater/component_updater_ping_manager.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
14 #include "base/strings/string_util.h" 13 #include "base/strings/string_util.h"
15 #include "base/win/windows_version.h" 14 #include "base/win/windows_version.h"
16 #include "build/build_config.h" 15 #include "build/build_config.h"
17 #include "chrome/browser/component_updater/component_patcher.h" 16 #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) 21 #if defined(OS_WIN)
23 #include "chrome/browser/component_updater/component_patcher_win.h" 22 #include "chrome/browser/component_updater/component_patcher_win.h"
24 #endif 23 #endif
25 24
26 namespace { 25 namespace {
27 26
28 // Default time constants. 27 // Default time constants.
29 const int kDelayOneMinute = 60; 28 const int kDelayOneMinute = 60;
30 const int kDelayOneHour = kDelayOneMinute * 60; 29 const int kDelayOneHour = kDelayOneMinute * 60;
31 30
32 // Debug values you can pass to --component-updater=value1,value2. 31 // Debug values you can pass to --component-updater=value1,value2.
33 // Speed up component checking. 32 // Speed up component checking.
34 const char kSwitchFastUpdate[] = "fast-update"; 33 const char kSwitchFastUpdate[] = "fast-update";
35 // Force out-of-process-xml parsing. 34 // Force out-of-process-xml parsing.
36 const char kSwitchOutOfProcess[] = "out-of-process"; 35 const char kSwitchOutOfProcess[] = "out-of-process";
37 // Add "testrequest=1" parameter to the update check query. 36 // Add "testrequest=1" parameter to the update check query.
38 const char kSwitchRequestParam[] = "test-request"; 37 const char kSwitchRequestParam[] = "test-request";
39 // Disables differential updates. 38 // Disables differential updates.
40 const char kSwitchDisableDeltaUpdates[] = "disable-delta-updates"; 39 const char kSwitchDisableDeltaUpdates[] = "disable-delta-updates";
40 // Disables pings. Pings are the requests sent to the update server that report
41 // the success or the failure of component install or update attempts.
42 extern const char kSwitchDisablePings[] = "disable-pings";
43
41 // Sets the URL for updates. 44 // Sets the URL for updates.
42 const char kSwitchUrlSource[] = "url-source"; 45 const char kSwitchUrlSource[] = "url-source";
43 46
44 // The default url from which an update manifest can be fetched. Can be 47 // The default url from which an update manifest can be fetched. Can be
45 // overridden with --component-updater=url-source=someurl. 48 // overridden with --component-updater=url-source=someurl.
46 const char kDefaultUrlSource[] = 49 const char kDefaultUrlSource[] =
47 "http://clients2.google.com/service/update2/crx"; 50 "http://clients2.google.com/service/update2/crx";
48 51
52 // The url to send the pings to.
53 const char kPingUrl[] = "http://tools.google.com/service/update2";
54
49 // Returns true if and only if |test| is contained in |vec|. 55 // Returns true if and only if |test| is contained in |vec|.
50 bool HasSwitchValue(const std::vector<std::string>& vec, const char* test) { 56 bool HasSwitchValue(const std::vector<std::string>& vec, const char* test) {
51 if (vec.empty()) 57 if (vec.empty())
52 return 0; 58 return 0;
53 return (std::find(vec.begin(), vec.end(), test) != vec.end()); 59 return (std::find(vec.begin(), vec.end(), test) != vec.end());
54 } 60 }
55 61
56 // If there is an element of |vec| of the form |test|=.*, returns the right- 62 // If there is an element of |vec| of the form |test|=.*, returns the right-
57 // hand side of that assignment. Otherwise, returns an empty string. 63 // hand side of that assignment. Otherwise, returns an empty string.
58 // The right-hand side may contain additional '=' characters, allowing for 64 // The right-hand side may contain additional '=' characters, allowing for
(...skipping 23 matching lines...) Expand all
82 net::URLRequestContextGetter* url_request_getter); 88 net::URLRequestContextGetter* url_request_getter);
83 89
84 virtual ~ChromeConfigurator() {} 90 virtual ~ChromeConfigurator() {}
85 91
86 virtual int InitialDelay() OVERRIDE; 92 virtual int InitialDelay() OVERRIDE;
87 virtual int NextCheckDelay() OVERRIDE; 93 virtual int NextCheckDelay() OVERRIDE;
88 virtual int StepDelay() OVERRIDE; 94 virtual int StepDelay() OVERRIDE;
89 virtual int MinimumReCheckWait() OVERRIDE; 95 virtual int MinimumReCheckWait() OVERRIDE;
90 virtual int OnDemandDelay() OVERRIDE; 96 virtual int OnDemandDelay() OVERRIDE;
91 virtual GURL UpdateUrl() OVERRIDE; 97 virtual GURL UpdateUrl() OVERRIDE;
98 virtual GURL PingUrl() OVERRIDE;
92 virtual const char* ExtraRequestParams() OVERRIDE; 99 virtual const char* ExtraRequestParams() OVERRIDE;
93 virtual size_t UrlSizeLimit() OVERRIDE; 100 virtual size_t UrlSizeLimit() OVERRIDE;
94 virtual net::URLRequestContextGetter* RequestContext() OVERRIDE; 101 virtual net::URLRequestContextGetter* RequestContext() OVERRIDE;
95 virtual bool InProcess() OVERRIDE; 102 virtual bool InProcess() OVERRIDE;
96 virtual void OnEvent(Events event, int val) OVERRIDE;
97 virtual ComponentPatcher* CreateComponentPatcher() OVERRIDE; 103 virtual ComponentPatcher* CreateComponentPatcher() OVERRIDE;
98 virtual bool DeltasEnabled() const OVERRIDE; 104 virtual bool DeltasEnabled() const OVERRIDE;
99 105
100 private: 106 private:
101 net::URLRequestContextGetter* url_request_getter_; 107 net::URLRequestContextGetter* url_request_getter_;
102 std::string extra_info_; 108 std::string extra_info_;
103 std::string url_source_; 109 std::string url_source_;
104 bool fast_update_; 110 bool fast_update_;
105 bool out_of_process_; 111 bool out_of_process_;
112 bool pings_enabled_;
106 bool deltas_enabled_; 113 bool deltas_enabled_;
107 }; 114 };
108 115
109 ChromeConfigurator::ChromeConfigurator(const CommandLine* cmdline, 116 ChromeConfigurator::ChromeConfigurator(const CommandLine* cmdline,
110 net::URLRequestContextGetter* url_request_getter) 117 net::URLRequestContextGetter* url_request_getter)
111 : url_request_getter_(url_request_getter), 118 : url_request_getter_(url_request_getter),
112 extra_info_(chrome::OmahaQueryParams::Get( 119 extra_info_(chrome::OmahaQueryParams::Get(
113 chrome::OmahaQueryParams::CHROME)), 120 chrome::OmahaQueryParams::CHROME)),
114 fast_update_(false), 121 fast_update_(false),
115 out_of_process_(false), 122 out_of_process_(false),
123 pings_enabled_(false),
116 deltas_enabled_(false) { 124 deltas_enabled_(false) {
117 // Parse comma-delimited debug flags. 125 // Parse comma-delimited debug flags.
118 std::vector<std::string> switch_values; 126 std::vector<std::string> switch_values;
119 Tokenize(cmdline->GetSwitchValueASCII(switches::kComponentUpdater), 127 Tokenize(cmdline->GetSwitchValueASCII(switches::kComponentUpdater),
120 ",", &switch_values); 128 ",", &switch_values);
121 fast_update_ = HasSwitchValue(switch_values, kSwitchFastUpdate); 129 fast_update_ = HasSwitchValue(switch_values, kSwitchFastUpdate);
122 out_of_process_ = HasSwitchValue(switch_values, kSwitchOutOfProcess); 130 out_of_process_ = HasSwitchValue(switch_values, kSwitchOutOfProcess);
131 pings_enabled_ = !HasSwitchValue(switch_values, kSwitchDisablePings);
123 #if defined(OS_WIN) 132 #if defined(OS_WIN)
124 deltas_enabled_ = !HasSwitchValue(switch_values, kSwitchDisableDeltaUpdates); 133 deltas_enabled_ = !HasSwitchValue(switch_values, kSwitchDisableDeltaUpdates);
125 #else 134 #else
126 deltas_enabled_ = false; 135 deltas_enabled_ = false;
127 #endif 136 #endif
128 137
129 url_source_ = GetSwitchArgument(switch_values, kSwitchUrlSource); 138 url_source_ = GetSwitchArgument(switch_values, kSwitchUrlSource);
130 if (url_source_.empty()) { 139 if (url_source_.empty()) {
131 url_source_ = kDefaultUrlSource; 140 url_source_ = kDefaultUrlSource;
132 } 141 }
(...skipping 26 matching lines...) Expand all
159 } 168 }
160 169
161 int ChromeConfigurator::OnDemandDelay() { 170 int ChromeConfigurator::OnDemandDelay() {
162 return fast_update_ ? 2 : (30 * kDelayOneMinute); 171 return fast_update_ ? 2 : (30 * kDelayOneMinute);
163 } 172 }
164 173
165 GURL ChromeConfigurator::UpdateUrl() { 174 GURL ChromeConfigurator::UpdateUrl() {
166 return GURL(url_source_); 175 return GURL(url_source_);
167 } 176 }
168 177
178 GURL ChromeConfigurator::PingUrl() {
179 return pings_enabled_ ? GURL(kPingUrl) : GURL();
180 }
181
169 const char* ChromeConfigurator::ExtraRequestParams() { 182 const char* ChromeConfigurator::ExtraRequestParams() {
170 return extra_info_.c_str(); 183 return extra_info_.c_str();
171 } 184 }
172 185
173 size_t ChromeConfigurator::UrlSizeLimit() { 186 size_t ChromeConfigurator::UrlSizeLimit() {
174 return 1024ul; 187 return 1024ul;
175 } 188 }
176 189
177 net::URLRequestContextGetter* ChromeConfigurator::RequestContext() { 190 net::URLRequestContextGetter* ChromeConfigurator::RequestContext() {
178 return url_request_getter_; 191 return url_request_getter_;
179 } 192 }
180 193
181 bool ChromeConfigurator::InProcess() { 194 bool ChromeConfigurator::InProcess() {
182 return !out_of_process_; 195 return !out_of_process_;
183 } 196 }
184 197
185 void ChromeConfigurator::OnEvent(Events event, int val) {
186 switch (event) {
187 case kManifestCheck:
188 UMA_HISTOGRAM_ENUMERATION("ComponentUpdater.ManifestCheck", val, 100);
189 break;
190 case kComponentUpdated:
191 UMA_HISTOGRAM_ENUMERATION("ComponentUpdater.ComponentUpdated", val, 100);
192 break;
193 case kManifestError:
194 UMA_HISTOGRAM_COUNTS_100("ComponentUpdater.ManifestError", val);
195 break;
196 case kNetworkError:
197 UMA_HISTOGRAM_ENUMERATION("ComponentUpdater.NetworkError", val, 100);
198 break;
199 case kUnpackError:
200 UMA_HISTOGRAM_ENUMERATION("ComponentUpdater.UnpackError", val, 100);
201 break;
202 case kInstallerError:
203 UMA_HISTOGRAM_ENUMERATION("ComponentUpdater.InstallError", val, 100);
204 break;
205 default:
206 NOTREACHED();
207 break;
208 }
209 }
210
211 ComponentPatcher* ChromeConfigurator::CreateComponentPatcher() { 198 ComponentPatcher* ChromeConfigurator::CreateComponentPatcher() {
212 #if defined(OS_WIN) 199 #if defined(OS_WIN)
213 return new ComponentPatcherWin(); 200 return new ComponentPatcherWin();
214 #else 201 #else
215 return new ComponentPatcherCrossPlatform(); 202 return new ComponentPatcherCrossPlatform();
216 #endif 203 #endif
217 } 204 }
218 205
219 bool ChromeConfigurator::DeltasEnabled() const { 206 bool ChromeConfigurator::DeltasEnabled() const {
220 return deltas_enabled_; 207 return deltas_enabled_;
221 } 208 }
222 209
223 ComponentUpdateService::Configurator* MakeChromeComponentUpdaterConfigurator( 210 ComponentUpdateService::Configurator* MakeChromeComponentUpdaterConfigurator(
224 const CommandLine* cmdline, net::URLRequestContextGetter* context_getter) { 211 const CommandLine* cmdline, net::URLRequestContextGetter* context_getter) {
225 return new ChromeConfigurator(cmdline, context_getter); 212 return new ChromeConfigurator(cmdline, context_getter);
226 } 213 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/component_updater/component_updater_ping_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698