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

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: ChromeConfigurator owns the ping manager. 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
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" 13 #include "base/scoped_ptr.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/browser/component_updater/component_patcher.h"
18 #include "chrome/browser/component_updater/component_updater_ping_manager.h"
19 #include "chrome/browser/component_updater/component_updater_service.h"
18 #include "chrome/common/chrome_switches.h" 20 #include "chrome/common/chrome_switches.h"
19 #include "chrome/common/omaha_query_params/omaha_query_params.h" 21 #include "chrome/common/omaha_query_params/omaha_query_params.h"
20 #include "net/url_request/url_request_context_getter.h" 22 #include "net/url_request/url_request_context_getter.h"
21 23
22 #if defined(OS_WIN) 24 #if defined(OS_WIN)
23 #include "chrome/browser/component_updater/component_patcher_win.h" 25 #include "chrome/browser/component_updater/component_patcher_win.h"
24 #endif 26 #endif
25 27
26 namespace { 28 namespace {
27 29
28 // Default time constants. 30 // Default time constants.
29 const int kDelayOneMinute = 60; 31 const int kDelayOneMinute = 60;
30 const int kDelayOneHour = kDelayOneMinute * 60; 32 const int kDelayOneHour = kDelayOneMinute * 60;
31 33
32 // Debug values you can pass to --component-updater=value1,value2. 34 // Debug values you can pass to --component-updater=value1,value2.
33 // Speed up component checking. 35 // Speed up component checking.
34 const char kSwitchFastUpdate[] = "fast-update"; 36 const char kSwitchFastUpdate[] = "fast-update";
35 // Force out-of-process-xml parsing. 37 // Force out-of-process-xml parsing.
36 const char kSwitchOutOfProcess[] = "out-of-process"; 38 const char kSwitchOutOfProcess[] = "out-of-process";
37 // Add "testrequest=1" parameter to the update check query. 39 // Add "testrequest=1" parameter to the update check query.
38 const char kSwitchRequestParam[] = "test-request"; 40 const char kSwitchRequestParam[] = "test-request";
39 // Disables differential updates. 41 // Disables differential updates.
40 const char kSwitchDisableDeltaUpdates[] = "disable-delta-updates"; 42 const char kSwitchDisableDeltaUpdates[] = "disable-delta-updates";
43 // Disables pings. Pings are the requests sent to the update server that report
44 // the success or the failure of component install or update attempts.
45 extern const char kSwitchDisablePings[] = "disable-pings";
46
41 // Sets the URL for updates. 47 // Sets the URL for updates.
42 const char kSwitchUrlSource[] = "url-source"; 48 const char kSwitchUrlSource[] = "url-source";
43 49
44 // The default url from which an update manifest can be fetched. Can be 50 // The default url from which an update manifest can be fetched. Can be
45 // overridden with --component-updater=url-source=someurl. 51 // overridden with --component-updater=url-source=someurl.
46 const char kDefaultUrlSource[] = 52 const char kDefaultUrlSource[] =
47 "http://clients2.google.com/service/update2/crx"; 53 "http://clients2.google.com/service/update2/crx";
48 54
55 // The url to send the pings to.
56 const char kPingUrl[] = "http://tools.google.com/service/update2";
57
49 // Returns true if and only if |test| is contained in |vec|. 58 // Returns true if and only if |test| is contained in |vec|.
50 bool HasSwitchValue(const std::vector<std::string>& vec, const char* test) { 59 bool HasSwitchValue(const std::vector<std::string>& vec, const char* test) {
51 if (vec.empty()) 60 if (vec.empty())
52 return 0; 61 return 0;
53 return (std::find(vec.begin(), vec.end(), test) != vec.end()); 62 return (std::find(vec.begin(), vec.end(), test) != vec.end());
54 } 63 }
55 64
56 // If there is an element of |vec| of the form |test|=.*, returns the right- 65 // 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. 66 // hand side of that assignment. Otherwise, returns an empty string.
58 // The right-hand side may contain additional '=' characters, allowing for 67 // The right-hand side may contain additional '=' characters, allowing for
(...skipping 15 matching lines...) Expand all
74 return std::string(); 83 return std::string();
75 } 84 }
76 85
77 } // namespace 86 } // namespace
78 87
79 class ChromeConfigurator : public ComponentUpdateService::Configurator { 88 class ChromeConfigurator : public ComponentUpdateService::Configurator {
80 public: 89 public:
81 ChromeConfigurator(const CommandLine* cmdline, 90 ChromeConfigurator(const CommandLine* cmdline,
82 net::URLRequestContextGetter* url_request_getter); 91 net::URLRequestContextGetter* url_request_getter);
83 92
84 virtual ~ChromeConfigurator() {} 93 virtual ~ChromeConfigurator();
85 94
95 virtual void Init(ComponentUpdateService* cus) OVERRIDE;
86 virtual int InitialDelay() OVERRIDE; 96 virtual int InitialDelay() OVERRIDE;
87 virtual int NextCheckDelay() OVERRIDE; 97 virtual int NextCheckDelay() OVERRIDE;
88 virtual int StepDelay() OVERRIDE; 98 virtual int StepDelay() OVERRIDE;
89 virtual int MinimumReCheckWait() OVERRIDE; 99 virtual int MinimumReCheckWait() OVERRIDE;
90 virtual int OnDemandDelay() OVERRIDE; 100 virtual int OnDemandDelay() OVERRIDE;
91 virtual GURL UpdateUrl() OVERRIDE; 101 virtual GURL UpdateUrl() OVERRIDE;
102 virtual GURL PingUrl() OVERRIDE;
92 virtual const char* ExtraRequestParams() OVERRIDE; 103 virtual const char* ExtraRequestParams() OVERRIDE;
93 virtual size_t UrlSizeLimit() OVERRIDE; 104 virtual size_t UrlSizeLimit() OVERRIDE;
94 virtual net::URLRequestContextGetter* RequestContext() OVERRIDE; 105 virtual net::URLRequestContextGetter* RequestContext() OVERRIDE;
95 virtual bool InProcess() OVERRIDE; 106 virtual bool InProcess() OVERRIDE;
96 virtual void OnEvent(Events event, int val) OVERRIDE;
97 virtual ComponentPatcher* CreateComponentPatcher() OVERRIDE; 107 virtual ComponentPatcher* CreateComponentPatcher() OVERRIDE;
98 virtual bool DeltasEnabled() const OVERRIDE; 108 virtual bool DeltasEnabled() const OVERRIDE;
99 109
100 private: 110 private:
101 net::URLRequestContextGetter* url_request_getter_; 111 net::URLRequestContextGetter* url_request_getter_;
102 std::string extra_info_; 112 std::string extra_info_;
103 std::string url_source_; 113 std::string url_source_;
104 bool fast_update_; 114 bool fast_update_;
105 bool out_of_process_; 115 bool out_of_process_;
116 bool pings_enabled_;
106 bool deltas_enabled_; 117 bool deltas_enabled_;
118 scoped_ptr<component_updater::PingManager> ping_manager_;
119 ComponentUpdateService* cus_; // Not owned by this class.
107 }; 120 };
108 121
109 ChromeConfigurator::ChromeConfigurator(const CommandLine* cmdline, 122 ChromeConfigurator::ChromeConfigurator(const CommandLine* cmdline,
110 net::URLRequestContextGetter* url_request_getter) 123 net::URLRequestContextGetter* url_request_getter)
111 : url_request_getter_(url_request_getter), 124 : url_request_getter_(url_request_getter),
112 extra_info_(chrome::OmahaQueryParams::Get( 125 extra_info_(chrome::OmahaQueryParams::Get(
113 chrome::OmahaQueryParams::CHROME)), 126 chrome::OmahaQueryParams::CHROME)),
114 fast_update_(false), 127 fast_update_(false),
115 out_of_process_(false), 128 out_of_process_(false),
129 pings_enabled_(false),
116 deltas_enabled_(false) { 130 deltas_enabled_(false) {
117 // Parse comma-delimited debug flags. 131 // Parse comma-delimited debug flags.
118 std::vector<std::string> switch_values; 132 std::vector<std::string> switch_values;
119 Tokenize(cmdline->GetSwitchValueASCII(switches::kComponentUpdater), 133 Tokenize(cmdline->GetSwitchValueASCII(switches::kComponentUpdater),
120 ",", &switch_values); 134 ",", &switch_values);
121 fast_update_ = HasSwitchValue(switch_values, kSwitchFastUpdate); 135 fast_update_ = HasSwitchValue(switch_values, kSwitchFastUpdate);
122 out_of_process_ = HasSwitchValue(switch_values, kSwitchOutOfProcess); 136 out_of_process_ = HasSwitchValue(switch_values, kSwitchOutOfProcess);
137 pings_enabled_ = !HasSwitchValue(switch_values, kSwitchDisablePings);
123 #if defined(OS_WIN) 138 #if defined(OS_WIN)
124 deltas_enabled_ = !HasSwitchValue(switch_values, kSwitchDisableDeltaUpdates); 139 deltas_enabled_ = !HasSwitchValue(switch_values, kSwitchDisableDeltaUpdates);
125 #else 140 #else
126 deltas_enabled_ = false; 141 deltas_enabled_ = false;
127 #endif 142 #endif
128 143
129 url_source_ = GetSwitchArgument(switch_values, kSwitchUrlSource); 144 url_source_ = GetSwitchArgument(switch_values, kSwitchUrlSource);
130 if (url_source_.empty()) { 145 if (url_source_.empty()) {
131 url_source_ = kDefaultUrlSource; 146 url_source_ = kDefaultUrlSource;
132 } 147 }
133 148
134 // Make the extra request params, they are necessary so omaha does 149 // Make the extra request params, they are necessary so omaha does
135 // not deliver components that are going to be rejected at install time. 150 // not deliver components that are going to be rejected at install time.
136 #if defined(OS_WIN) 151 #if defined(OS_WIN)
137 if (base::win::OSInfo::GetInstance()->wow64_status() == 152 if (base::win::OSInfo::GetInstance()->wow64_status() ==
138 base::win::OSInfo::WOW64_ENABLED) 153 base::win::OSInfo::WOW64_ENABLED)
139 extra_info_ += "&wow64=1"; 154 extra_info_ += "&wow64=1";
140 #endif 155 #endif
141 if (HasSwitchValue(switch_values, kSwitchRequestParam)) 156 if (HasSwitchValue(switch_values, kSwitchRequestParam))
142 extra_info_ += "&testrequest=1"; 157 extra_info_ += "&testrequest=1";
143 } 158 }
144 159
160 ChromeConfigurator::~ChromeConfigurator() {
161 if (cus_)
162 cus_->RemoveObserver(ping_manager_.get());
163 }
164
165 void ChromeConfigurator::Init(ComponentUpdateService* cus) {
166 cus_ = cus;
167 ping_manager_.reset(new component_updater::PingManager(PingUrl(),
168 RequestContext()));
169 cus_->AddObserver(ping_manager_.get());
170 }
171
145 int ChromeConfigurator::InitialDelay() { 172 int ChromeConfigurator::InitialDelay() {
146 return fast_update_ ? 1 : (6 * kDelayOneMinute); 173 return fast_update_ ? 1 : (6 * kDelayOneMinute);
147 } 174 }
148 175
149 int ChromeConfigurator::NextCheckDelay() { 176 int ChromeConfigurator::NextCheckDelay() {
150 return fast_update_ ? 3 : (2 * kDelayOneHour); 177 return fast_update_ ? 3 : (2 * kDelayOneHour);
151 } 178 }
152 179
153 int ChromeConfigurator::StepDelay() { 180 int ChromeConfigurator::StepDelay() {
154 return fast_update_ ? 1 : 4; 181 return fast_update_ ? 1 : 4;
155 } 182 }
156 183
157 int ChromeConfigurator::MinimumReCheckWait() { 184 int ChromeConfigurator::MinimumReCheckWait() {
158 return fast_update_ ? 30 : (6 * kDelayOneHour); 185 return fast_update_ ? 30 : (6 * kDelayOneHour);
159 } 186 }
160 187
161 int ChromeConfigurator::OnDemandDelay() { 188 int ChromeConfigurator::OnDemandDelay() {
162 return fast_update_ ? 2 : (30 * kDelayOneMinute); 189 return fast_update_ ? 2 : (30 * kDelayOneMinute);
163 } 190 }
164 191
165 GURL ChromeConfigurator::UpdateUrl() { 192 GURL ChromeConfigurator::UpdateUrl() {
166 return GURL(url_source_); 193 return GURL(url_source_);
167 } 194 }
168 195
196 GURL ChromeConfigurator::PingUrl() {
197 return pings_enabled_ ? GURL(kPingUrl) : GURL();
198 }
199
169 const char* ChromeConfigurator::ExtraRequestParams() { 200 const char* ChromeConfigurator::ExtraRequestParams() {
170 return extra_info_.c_str(); 201 return extra_info_.c_str();
171 } 202 }
172 203
173 size_t ChromeConfigurator::UrlSizeLimit() { 204 size_t ChromeConfigurator::UrlSizeLimit() {
174 return 1024ul; 205 return 1024ul;
175 } 206 }
176 207
177 net::URLRequestContextGetter* ChromeConfigurator::RequestContext() { 208 net::URLRequestContextGetter* ChromeConfigurator::RequestContext() {
178 return url_request_getter_; 209 return url_request_getter_;
179 } 210 }
180 211
181 bool ChromeConfigurator::InProcess() { 212 bool ChromeConfigurator::InProcess() {
182 return !out_of_process_; 213 return !out_of_process_;
183 } 214 }
184 215
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() { 216 ComponentPatcher* ChromeConfigurator::CreateComponentPatcher() {
212 #if defined(OS_WIN) 217 #if defined(OS_WIN)
213 return new ComponentPatcherWin(); 218 return new ComponentPatcherWin();
214 #else 219 #else
215 return new ComponentPatcherCrossPlatform(); 220 return new ComponentPatcherCrossPlatform();
216 #endif 221 #endif
217 } 222 }
218 223
219 bool ChromeConfigurator::DeltasEnabled() const { 224 bool ChromeConfigurator::DeltasEnabled() const {
220 return deltas_enabled_; 225 return deltas_enabled_;
221 } 226 }
222 227
223 ComponentUpdateService::Configurator* MakeChromeComponentUpdaterConfigurator( 228 ComponentUpdateService::Configurator* MakeChromeComponentUpdaterConfigurator(
224 const CommandLine* cmdline, net::URLRequestContextGetter* context_getter) { 229 const CommandLine* cmdline, net::URLRequestContextGetter* context_getter) {
225 return new ChromeConfigurator(cmdline, context_getter); 230 return new ChromeConfigurator(cmdline, context_getter);
226 } 231 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698