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

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

Issue 15908002: Differential updates for components. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: really removing the lzma files this time. Created 7 years, 6 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_service.h" 5 #include "chrome/browser/component_updater/component_updater_service.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/at_exit.h" 11 #include "base/at_exit.h"
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/compiler_specific.h"
13 #include "base/file_util.h" 14 #include "base/file_util.h"
14 #include "base/files/file_path.h" 15 #include "base/files/file_path.h"
16 #include "base/guid.h"
15 #include "base/logging.h" 17 #include "base/logging.h"
16 #include "base/memory/scoped_ptr.h" 18 #include "base/memory/scoped_ptr.h"
17 #include "base/stl_util.h" 19 #include "base/stl_util.h"
18 #include "base/strings/string_number_conversions.h" 20 #include "base/strings/string_number_conversions.h"
19 #include "base/strings/string_piece.h" 21 #include "base/strings/string_piece.h"
20 #include "base/strings/string_util.h" 22 #include "base/strings/string_util.h"
21 #include "base/strings/stringprintf.h" 23 #include "base/strings/stringprintf.h"
24 #include "base/sys_info.h"
22 #include "base/timer.h" 25 #include "base/timer.h"
23 #include "chrome/browser/browser_process.h" 26 #include "chrome/browser/browser_process.h"
27 #include "chrome/browser/component_updater/component_patcher.h"
24 #include "chrome/browser/component_updater/component_unpacker.h" 28 #include "chrome/browser/component_updater/component_unpacker.h"
25 #include "chrome/common/chrome_notification_types.h" 29 #include "chrome/common/chrome_notification_types.h"
26 #include "chrome/common/chrome_utility_messages.h" 30 #include "chrome/common/chrome_utility_messages.h"
27 #include "chrome/common/chrome_version_info.h" 31 #include "chrome/common/chrome_version_info.h"
28 #include "chrome/common/extensions/extension.h" 32 #include "chrome/common/extensions/extension.h"
33 #include "chrome/common/omaha_query_params/omaha_query_params.h"
29 #include "content/public/browser/browser_thread.h" 34 #include "content/public/browser/browser_thread.h"
30 #include "content/public/browser/notification_service.h" 35 #include "content/public/browser/notification_service.h"
31 #include "content/public/browser/utility_process_host.h" 36 #include "content/public/browser/utility_process_host.h"
32 #include "content/public/browser/utility_process_host_client.h" 37 #include "content/public/browser/utility_process_host_client.h"
33 #include "googleurl/src/gurl.h" 38 #include "googleurl/src/gurl.h"
34 #include "net/base/escape.h" 39 #include "net/base/escape.h"
35 #include "net/base/load_flags.h" 40 #include "net/base/load_flags.h"
36 #include "net/base/net_errors.h" 41 #include "net/base/net_errors.h"
37 #include "net/url_request/url_fetcher.h" 42 #include "net/url_request/url_fetcher.h"
38 #include "net/url_request/url_fetcher_delegate.h" 43 #include "net/url_request/url_fetcher_delegate.h"
39 #include "net/url_request/url_request_status.h" 44 #include "net/url_request/url_request_status.h"
40 45
41 using content::BrowserThread; 46 using content::BrowserThread;
42 using content::UtilityProcessHost; 47 using content::UtilityProcessHost;
43 using content::UtilityProcessHostClient; 48 using content::UtilityProcessHostClient;
44 using extensions::Extension; 49 using extensions::Extension;
45 50
46 // The component updater is designed to live until process shutdown, so 51 // The component updater is designed to live until process shutdown, so
47 // base::Bind() calls are not refcounted. 52 // base::Bind() calls are not refcounted.
48 53
49 namespace { 54 namespace {
55
56 typedef ComponentUpdateService::Configurator Config;
57
50 // Manifest sources, from most important to least important. 58 // Manifest sources, from most important to least important.
51 const CrxComponent::UrlSource kManifestSources[] = { 59 const CrxComponent::UrlSource kManifestSources[] = {
52 CrxComponent::BANDAID, 60 CrxComponent::BANDAID,
53 CrxComponent::CWS_PUBLIC, 61 CrxComponent::CWS_PUBLIC,
54 CrxComponent::CWS_SANDBOX 62 CrxComponent::CWS_SANDBOX,
55 }; 63 };
56 64
57 // Extends an omaha compatible update check url |query| string. Does 65 // Extends an omaha compatible update check url |query| string. Does
58 // not mutate the string if it would be longer than |limit| chars. 66 // not mutate the string if it would be longer than |limit| chars.
59 bool AddQueryString(const std::string& id, 67 bool AddQueryString(const std::string& id,
60 const std::string& version, 68 const std::string& version,
69 const std::string& fingerprint,
61 size_t limit, 70 size_t limit,
62 std::string* query) { 71 std::string* query) {
63 std::string additional = 72 std::string additional =
64 base::StringPrintf("id=%s&v=%s&uc", id.c_str(), version.c_str()); 73 base::StringPrintf("id=%s&v=%s&fp=%s&uc",
74 id.c_str(), version.c_str(), fingerprint.c_str());
65 additional = "x=" + net::EscapeQueryParamValue(additional, true); 75 additional = "x=" + net::EscapeQueryParamValue(additional, true);
66 if ((additional.size() + query->size() + 1) > limit) 76 if ((additional.size() + query->size() + 1) > limit)
67 return false; 77 return false;
68 if (!query->empty()) 78 if (!query->empty())
69 query->append(1, '&'); 79 query->append(1, '&');
70 query->append(additional); 80 query->append(additional);
71 return true; 81 return true;
72 } 82 }
73 83
74 // Create the final omaha compatible query. The |extra| is optional and can 84 // Create the final omaha compatible query. The |extra| is optional and can
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 net::LOAD_DISABLE_CACHE); 166 net::LOAD_DISABLE_CACHE);
157 // TODO(cpu): Define our retry and backoff policy. 167 // TODO(cpu): Define our retry and backoff policy.
158 fetcher->SetAutomaticallyRetryOn5xx(false); 168 fetcher->SetAutomaticallyRetryOn5xx(false);
159 if (save_to_file) { 169 if (save_to_file) {
160 fetcher->SaveResponseToTemporaryFile( 170 fetcher->SaveResponseToTemporaryFile(
161 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)); 171 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE));
162 } 172 }
163 fetcher->Start(); 173 fetcher->Start();
164 } 174 }
165 175
166 // Returs true if the url request of |fetcher| was succesful. 176 // Returns true if the url request of |fetcher| was succesful.
167 bool FetchSuccess(const net::URLFetcher& fetcher) { 177 bool FetchSuccess(const net::URLFetcher& fetcher) {
168 return (fetcher.GetStatus().status() == net::URLRequestStatus::SUCCESS) && 178 return (fetcher.GetStatus().status() == net::URLRequestStatus::SUCCESS) &&
169 (fetcher.GetResponseCode() == 200); 179 (fetcher.GetResponseCode() == 200);
170 } 180 }
171 181
182 // Returns the error code which occured during the fetch. This function
183 // is intended to be called for logging purposes only, since it folds different
184 // types of errors to fit them in the returned type. The function returns 0 if
185 // the fetch was successful. If errors happen, the function could return a
186 // network error, an http response code, or the status of the fetch, if the
187 // fetch is pending or canceled.
188 int GetFetchError(const net::URLFetcher& fetcher) {
189 if (FetchSuccess(fetcher))
190 return 0;
191
192 const net::URLRequestStatus::Status status(fetcher.GetStatus().status());
193 if (status == net::URLRequestStatus::FAILED)
194 return fetcher.GetStatus().error();
195
196 if (status == net::URLRequestStatus::IO_PENDING ||
197 status == net::URLRequestStatus::CANCELED)
198 return status;
199
200 const int response_code(fetcher.GetResponseCode());
201 if (status == net::URLRequestStatus::SUCCESS && response_code != 200)
202 return response_code;
203
204 return -1;
205 }
206
207
172 // This is the one and only per-item state structure. Designed to be hosted 208 // This is the one and only per-item state structure. Designed to be hosted
173 // in a std::vector or a std::list. The two main members are |component| 209 // in a std::vector or a std::list. The two main members are |component|
174 // which is supplied by the the component updater client and |status| which 210 // which is supplied by the the component updater client and |status| which
175 // is modified as the item is processed by the update pipeline. The expected 211 // is modified as the item is processed by the update pipeline. The expected
176 // transition graph is: 212 // transition graph is:
177 // error error error 213 //
178 // +--kNoUpdate<------<-------+------<------+------<------+ 214 // kNew
179 // | | | | 215 // |
180 // V yes | | | 216 // V
181 // kNew --->kChecking-->[update?]----->kCanUpdate-->kDownloading-->kUpdating 217 // +----------------------> kChecking -<---------+-----<-------+
182 // ^ | | 218 // | | | |
183 // | |no | 219 // | V no | |
184 // |--kUpToDate<---+ | 220 // kNoUpdate [update?] ->---- kUpToDate kUpdated
185 // | success | 221 // ^ | ^
186 // +--kUpdated<-------------------------------------------+ 222 // | yes | |
223 // | diff=false V |
224 // | +-----------> kCanUpdate |
225 // | | | |
226 // | | V no |
227 // | | [differential update?]->----+ |
228 // | | | | |
229 // | | yes | | |
230 // | | error V | |
231 // | +---------<- kDownloadingDiff | |
232 // | | | | |
233 // | | | | |
234 // | | error V | |
235 // | +---------<- kUpdatingDiff ->--------|-----------+ success
236 // | | |
237 // | error V |
238 // +----------------------------------------- kDownloading |
239 // | | |
240 // | error V |
241 // +------------------------------------------ kUpdating ->----+ success
187 // 242 //
188 struct CrxUpdateItem { 243 struct CrxUpdateItem {
189 enum Status { 244 enum Status {
190 kNew, 245 kNew,
191 kChecking, 246 kChecking,
192 kCanUpdate, 247 kCanUpdate,
248 kDownloadingDiff,
193 kDownloading, 249 kDownloading,
250 kUpdatingDiff,
194 kUpdating, 251 kUpdating,
195 kUpdated, 252 kUpdated,
196 kUpToDate, 253 kUpToDate,
197 kNoUpdate, 254 kNoUpdate,
198 kLastStatus 255 kLastStatus
199 }; 256 };
200 257
201 Status status; 258 Status status;
259 std::string id;
260 CrxComponent component;
261
262 base::Time last_check;
263
264 // True if the update response includes an update for this component.
265 bool is_update_available;
266
267 // True is a completion ping has been queued for this component. If an update
268 // is available for this component, one completion ping must be sent
269 // after the component has reached either the kNoUpdate or kUpdated states.
270 bool ping_queued;
271
272 // These members are initialized with their corresponding values from the
273 // update server response.
202 GURL crx_url; 274 GURL crx_url;
203 std::string id; 275 GURL diff_crx_url;
204 base::Time last_check; 276 std::string package_hash;
205 CrxComponent component; 277 std::string diff_package_hash;
278 int size;
279 int diff_size;
280
281 // The from/to version and fingerprint values.
282 Version previous_version;
206 Version next_version; 283 Version next_version;
284 std::string previous_fp;
285 std::string next_fp;
207 286
208 CrxUpdateItem() : status(kNew) {} 287 // True if the differential update failed for any reason.
288 bool diff_update_failed;
289
290 // The error information for full and differential updates.
291 int error_code;
292 int extra_code1;
293 int diff_error_code;
294 int diff_extra_code1;
295
296 CrxUpdateItem()
297 : status(kNew),
298 is_update_available(false),
299 ping_queued(false),
300 size(0),
301 diff_size(0),
302 diff_update_failed(false),
303 error_code(0),
304 extra_code1(0),
305 diff_error_code(0),
306 diff_extra_code1(0) {
307 }
209 308
210 // Function object used to find a specific component. 309 // Function object used to find a specific component.
211 class FindById { 310 class FindById {
212 public: 311 public:
213 explicit FindById(const std::string& id) : id_(id) {} 312 explicit FindById(const std::string& id) : id_(id) {}
214 313
215 bool operator() (CrxUpdateItem* item) const { 314 bool operator() (CrxUpdateItem* item) const {
216 return (item->id == id_); 315 return (item->id == id_);
217 } 316 }
218 private: 317 private:
219 const std::string& id_; 318 const std::string& id_;
220 }; 319 };
221 }; 320 };
222 321
322 // Returns true if a differential update is available for the update item.
323 bool IsDiffUpdateAvailable(const CrxUpdateItem* update_item) {
324 return update_item->diff_crx_url.is_valid();
325 }
326
327 // Returns true if a differential update is available, it has not failed yet,
328 // and the configuration allows it.
329 bool CanTryDiffUpdate(const CrxUpdateItem* update_item, const Config& config) {
330 return IsDiffUpdateAvailable(update_item) &&
331 !update_item->diff_update_failed &&
332 config.DeltasEnabled();
333 }
334
223 } // namespace. 335 } // namespace.
224 336
225 typedef ComponentUpdateService::Configurator Config;
226
227 CrxComponent::CrxComponent() 337 CrxComponent::CrxComponent()
228 : installer(NULL), 338 : installer(NULL),
229 source(BANDAID) { 339 source(BANDAID) {
230 } 340 }
231 341
232 CrxComponent::~CrxComponent() { 342 CrxComponent::~CrxComponent() {
233 } 343 }
234 344
235 ////////////////////////////////////////////////////////////////////////////// 345 //////////////////////////////////////////////////////////////////////////////
236 // The one and only implementation of the ComponentUpdateService interface. In 346 // The one and only implementation of the ComponentUpdateService interface. In
237 // charge of running the show. The main method is ProcessPendingItems() which 347 // charge of running the show. The main method is ProcessPendingItems() which
238 // is called periodically to do the upgrades/installs or the update checks. 348 // is called periodically to do the upgrades/installs or the update checks.
239 // An important consideration here is to be as "low impact" as we can to the 349 // An important consideration here is to be as "low impact" as we can to the
240 // rest of the browser, so even if we have many components registered and 350 // rest of the browser, so even if we have many components registered and
241 // eligible for update, we only do one thing at a time with pauses in between 351 // eligible for update, we only do one thing at a time with pauses in between
242 // the tasks. Also when we do network requests there is only one |url_fetcher_| 352 // the tasks. Also when we do network requests there is only one |url_fetcher_|
243 // in flight at at a time. 353 // in flight at a time.
244 // There are no locks in this code, the main structure |work_items_| is mutated 354 // There are no locks in this code, the main structure |work_items_| is mutated
245 // only from the UI thread. The unpack and installation is done in the file 355 // only from the UI thread. The unpack and installation is done in the file
246 // thread and the network requests are done in the IO thread and in the file 356 // thread and the network requests are done in the IO thread and in the file
247 // thread. 357 // thread.
248 class CrxUpdateService : public ComponentUpdateService { 358 class CrxUpdateService : public ComponentUpdateService {
249 public: 359 public:
250 explicit CrxUpdateService(ComponentUpdateService::Configurator* config); 360 explicit CrxUpdateService(ComponentUpdateService::Configurator* config);
251 361
252 virtual ~CrxUpdateService(); 362 virtual ~CrxUpdateService();
253 363
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 CrxUpdateService* service_; 402 CrxUpdateService* service_;
293 DISALLOW_COPY_AND_ASSIGN(ManifestParserBridge); 403 DISALLOW_COPY_AND_ASSIGN(ManifestParserBridge);
294 }; 404 };
295 405
296 // Context for a update check url request. See DelegateWithContext above. 406 // Context for a update check url request. See DelegateWithContext above.
297 struct UpdateContext { 407 struct UpdateContext {
298 base::Time start; 408 base::Time start;
299 UpdateContext() : start(base::Time::Now()) {} 409 UpdateContext() : start(base::Time::Now()) {}
300 }; 410 };
301 411
412 // Context for a completion ping.
413 struct PingContext {
robertshield 2013/06/17 17:47:00 This struct appears rather empty. If it's here as
Sorin Jianu 2013/06/17 22:21:09 Done.
414 };
415
302 // Context for a crx download url request. See DelegateWithContext above. 416 // Context for a crx download url request. See DelegateWithContext above.
303 struct CRXContext { 417 struct CRXContext {
304 ComponentInstaller* installer; 418 ComponentInstaller* installer;
305 std::vector<uint8> pk_hash; 419 std::vector<uint8> pk_hash;
306 std::string id; 420 std::string id;
421 std::string fingerprint;
307 CRXContext() : installer(NULL) {} 422 CRXContext() : installer(NULL) {}
308 }; 423 };
309 424
310 void OnURLFetchComplete(const net::URLFetcher* source, 425 void OnURLFetchComplete(const net::URLFetcher* source,
311 UpdateContext* context); 426 UpdateContext* context);
312 427
313 void OnURLFetchComplete(const net::URLFetcher* source, 428 void OnURLFetchComplete(const net::URLFetcher* source,
314 CRXContext* context); 429 CRXContext* context);
315 430
431 void OnURLFetchComplete(const net::URLFetcher* source,
432 PingContext* context);
433
316 private: 434 private:
317 // See ManifestParserBridge. 435 // See ManifestParserBridge.
318 void OnParseUpdateManifestSucceeded( 436 void OnParseUpdateManifestSucceeded(
319 const UpdateManifest::Results& results); 437 const UpdateManifest::Results& results);
320 438
321 // See ManifestParserBridge. 439 // See ManifestParserBridge.
322 void OnParseUpdateManifestFailed( 440 void OnParseUpdateManifestFailed(const std::string& error_message);
323 const std::string& error_message);
324 441
325 bool AddItemToUpdateCheck(CrxUpdateItem* item, std::string* query); 442 bool AddItemToUpdateCheck(CrxUpdateItem* item, std::string* query);
326 443
327 void ProcessPendingItems(); 444 void ProcessPendingItems();
328 445
329 void ScheduleNextRun(bool step_delay); 446 void ScheduleNextRun(bool step_delay);
330 447
331 void ParseManifest(const std::string& xml); 448 void ParseManifest(const std::string& xml);
332 449
333 void Install(const CRXContext* context, const base::FilePath& crx_path); 450 void Install(const CRXContext* context, const base::FilePath& crx_path);
334 451
335 void DoneInstalling(const std::string& component_id, 452 void DoneInstalling(const std::string& component_id,
336 ComponentUnpacker::Error error); 453 ComponentUnpacker::Error error,
454 int extended_error);
337 455
338 size_t ChangeItemStatus(CrxUpdateItem::Status from, 456 size_t ChangeItemStatus(CrxUpdateItem::Status from,
339 CrxUpdateItem::Status to); 457 CrxUpdateItem::Status to);
340 458
341 CrxUpdateItem* FindUpdateItemById(const std::string& id); 459 CrxUpdateItem* FindUpdateItemById(const std::string& id);
342 460
461 void SendPing(const std::string& ping);
462
463 // These functions build a ping request. Building the ping changes the state
464 // of the update item to indicate that a completion ping has been collected
465 // and queued for this item.
466 std::string BuildPing() const;
467 std::string BuildPingApps() const;
468 static std::string BuildPingEvent(CrxUpdateItem* item);
469
343 scoped_ptr<Config> config_; 470 scoped_ptr<Config> config_;
344 471
472 scoped_ptr<ComponentPatcher> component_patcher_;
473
345 scoped_ptr<net::URLFetcher> url_fetcher_; 474 scoped_ptr<net::URLFetcher> url_fetcher_;
346 475
476 scoped_ptr<net::URLFetcher> ping_sender_;
477
478 // A collection of every work item.
347 typedef std::vector<CrxUpdateItem*> UpdateItems; 479 typedef std::vector<CrxUpdateItem*> UpdateItems;
348 // A collection of every work item.
349 UpdateItems work_items_; 480 UpdateItems work_items_;
350 481
351 // A particular set of items from work_items_, which should be checked ASAP. 482 // A particular set of items from work_items_, which should be checked ASAP.
352 std::set<CrxUpdateItem*> requested_work_items_; 483 std::set<CrxUpdateItem*> requested_work_items_;
353 484
354 base::OneShotTimer<CrxUpdateService> timer_; 485 base::OneShotTimer<CrxUpdateService> timer_;
355 486
356 Version chrome_version_; 487 const Version chrome_version_;
488 const std::string prod_id_;
489 const std::string os_type_;
490 const std::string os_version_;
357 491
358 bool running_; 492 bool running_;
359 493
360 DISALLOW_COPY_AND_ASSIGN(CrxUpdateService); 494 DISALLOW_COPY_AND_ASSIGN(CrxUpdateService);
361 }; 495 };
362 496
363 ////////////////////////////////////////////////////////////////////////////// 497 //////////////////////////////////////////////////////////////////////////////
364 498
365 CrxUpdateService::CrxUpdateService( 499 CrxUpdateService::CrxUpdateService(ComponentUpdateService::Configurator* config)
366 ComponentUpdateService::Configurator* config)
367 : config_(config), 500 : config_(config),
501 component_patcher_(config->CreateComponentPatcher()),
368 chrome_version_(chrome::VersionInfo().Version()), 502 chrome_version_(chrome::VersionInfo().Version()),
503 prod_id_(chrome::OmahaQueryParams::GetProdIdString(
504 chrome::OmahaQueryParams::CHROME)),
505 os_type_(chrome::VersionInfo().OSType()),
506 os_version_(base::SysInfo().OperatingSystemVersion()),
369 running_(false) { 507 running_(false) {
370 } 508 }
371 509
372 CrxUpdateService::~CrxUpdateService() { 510 CrxUpdateService::~CrxUpdateService() {
373 // Because we are a singleton, at this point only the UI thread should be 511 // Because we are a singleton, at this point only the UI thread should be
374 // alive, this simplifies the management of the work that could be in 512 // alive, this simplifies the management of the work that could be in
375 // flight in other threads. 513 // flight in other threads.
376 Stop(); 514 Stop();
377 STLDeleteElements(&work_items_); 515 STLDeleteElements(&work_items_);
378 } 516 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 void CrxUpdateService::ScheduleNextRun(bool step_delay) { 549 void CrxUpdateService::ScheduleNextRun(bool step_delay) {
412 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 550 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
413 DCHECK(url_fetcher_.get() == NULL); 551 DCHECK(url_fetcher_.get() == NULL);
414 CHECK(!timer_.IsRunning()); 552 CHECK(!timer_.IsRunning());
415 // It could be the case that Stop() had been called while a url request 553 // It could be the case that Stop() had been called while a url request
416 // or unpacking was in flight, if so we arrive here but |running_| is 554 // or unpacking was in flight, if so we arrive here but |running_| is
417 // false. In that case do not loop again. 555 // false. In that case do not loop again.
418 if (!running_) 556 if (!running_)
419 return; 557 return;
420 558
559 if (!step_delay && config_->PingsEnabled()) {
560 const std::string ping(BuildPing());
561 if (!ping.empty())
562 SendPing(ping);
563 }
564
421 // Keep the delay short if in the middle of an update (step_delay), 565 // Keep the delay short if in the middle of an update (step_delay),
422 // or there are new requested_work_items_ that have not been processed yet. 566 // or there are new requested_work_items_ that have not been processed yet.
423 int64 delay = (step_delay || requested_work_items_.size() > 0) 567 int64 delay = (step_delay || requested_work_items_.size() > 0)
424 ? config_->StepDelay() : config_->NextCheckDelay(); 568 ? config_->StepDelay() : config_->NextCheckDelay();
425 569
426 if (!step_delay) { 570 if (!step_delay) {
427 content::NotificationService::current()->Notify( 571 content::NotificationService::current()->Notify(
428 chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, 572 chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING,
429 content::Source<ComponentUpdateService>(this), 573 content::Source<ComponentUpdateService>(this),
430 content::NotificationService::NoDetails()); 574 content::NotificationService::NoDetails());
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 CrxUpdateItem* uit; 628 CrxUpdateItem* uit;
485 uit = FindUpdateItemById(id); 629 uit = FindUpdateItemById(id);
486 if (uit) { 630 if (uit) {
487 uit->component = component; 631 uit->component = component;
488 return kReplaced; 632 return kReplaced;
489 } 633 }
490 634
491 uit = new CrxUpdateItem; 635 uit = new CrxUpdateItem;
492 uit->id.swap(id); 636 uit->id.swap(id);
493 uit->component = component; 637 uit->component = component;
638
494 work_items_.push_back(uit); 639 work_items_.push_back(uit);
495 // If this is the first component registered we call Start to 640 // If this is the first component registered we call Start to
496 // schedule the first timer. 641 // schedule the first timer.
497 if (running_ && (work_items_.size() == 1)) 642 if (running_ && (work_items_.size() == 1))
498 Start(); 643 Start();
499 644
500 return kOk; 645 return kOk;
501 } 646 }
502 647
503 // Sets a component to be checked for updates. 648 // Sets a component to be checked for updates.
504 // The componet to add is |crxit| and the |query| string is modified with the 649 // The componet to add is |crxit| and the |query| string is modified with the
robertshield 2013/06/17 17:47:00 component
Sorin Jianu 2013/06/17 22:21:09 Done.
505 // required omaha compatible query. Returns false when the query strings 650 // required omaha compatible query. Returns false when the query strings
506 // is longer than specified by UrlSizeLimit(). 651 // is longer than specified by UrlSizeLimit().
507 bool CrxUpdateService::AddItemToUpdateCheck(CrxUpdateItem* item, 652 bool CrxUpdateService::AddItemToUpdateCheck(CrxUpdateItem* item,
508 std::string* query) { 653 std::string* query) {
509 if (!AddQueryString(item->id, 654 if (!AddQueryString(item->id,
510 item->component.version.GetString(), 655 item->component.version.GetString(),
656 item->component.fingerprint,
511 config_->UrlSizeLimit(), query)) 657 config_->UrlSizeLimit(), query))
512 return false; 658 return false;
659
513 item->status = CrxUpdateItem::kChecking; 660 item->status = CrxUpdateItem::kChecking;
514 item->last_check = base::Time::Now(); 661 item->last_check = base::Time::Now();
662 item->is_update_available = false;
663 item->ping_queued = false;
664 item->previous_version = item->component.version;
665 item->next_version = Version();
666 item->previous_fp = item->component.fingerprint;
667 item->next_fp = "";
668 item->diff_update_failed = false;
669 item->error_code = 0;
670 item->extra_code1 = 0;
671 item->diff_error_code = 0;
672 item->diff_extra_code1 = 0;
515 return true; 673 return true;
516 } 674 }
517 675
518 // Start the process of checking for an update, for a particular component 676 // Start the process of checking for an update, for a particular component
519 // that was previously registered. 677 // that was previously registered.
520 ComponentUpdateService::Status CrxUpdateService::CheckForUpdateSoon( 678 ComponentUpdateService::Status CrxUpdateService::CheckForUpdateSoon(
521 const CrxComponent& component) { 679 const CrxComponent& component) {
522 if (component.pk_hash.empty() || 680 if (component.pk_hash.empty() ||
523 !component.version.IsValid() || 681 !component.version.IsValid() ||
524 !component.installer) 682 !component.installer)
525 return kError; 683 return kError;
526 684
527 std::string id = 685 std::string id =
528 HexStringToID(StringToLowerASCII(base::HexEncode(&component.pk_hash[0], 686 HexStringToID(StringToLowerASCII(base::HexEncode(&component.pk_hash[0],
529 component.pk_hash.size()/2))); 687 component.pk_hash.size()/2)));
530 688
531 CrxUpdateItem* uit; 689 CrxUpdateItem* uit;
532 uit = FindUpdateItemById(id); 690 uit = FindUpdateItemById(id);
533 if (!uit) 691 if (!uit)
534 return kError; 692 return kError;
535 693
536 // Check if the request is too soon. 694 // Check if the request is too soon.
537 base::TimeDelta delta = base::Time::Now() - uit->last_check; 695 base::TimeDelta delta = base::Time::Now() - uit->last_check;
538 if (delta < base::TimeDelta::FromSeconds(config_->OnDemandDelay())) { 696 if (delta < base::TimeDelta::FromSeconds(config_->OnDemandDelay()))
539 return kError; 697 return kError;
540 }
541 698
542 switch (uit->status) { 699 switch (uit->status) {
543 // If the item is already in the process of being updated, there is 700 // If the item is already in the process of being updated, there is
544 // no point in this call, so return kInProgress. 701 // no point in this call, so return kInProgress.
545 case CrxUpdateItem::kChecking: 702 case CrxUpdateItem::kChecking:
546 case CrxUpdateItem::kCanUpdate: 703 case CrxUpdateItem::kCanUpdate:
704 case CrxUpdateItem::kDownloadingDiff:
547 case CrxUpdateItem::kDownloading: 705 case CrxUpdateItem::kDownloading:
706 case CrxUpdateItem::kUpdatingDiff:
548 case CrxUpdateItem::kUpdating: 707 case CrxUpdateItem::kUpdating:
549 return kInProgress; 708 return kInProgress;
550 // Otherwise the item was already checked a while back (or it is new), 709 // Otherwise the item was already checked a while back (or it is new),
551 // set its status to kNew to give it a slightly higher priority. 710 // set its status to kNew to give it a slightly higher priority.
552 case CrxUpdateItem::kNew: 711 case CrxUpdateItem::kNew:
553 case CrxUpdateItem::kUpdated: 712 case CrxUpdateItem::kUpdated:
554 case CrxUpdateItem::kUpToDate: 713 case CrxUpdateItem::kUpToDate:
555 case CrxUpdateItem::kNoUpdate: 714 case CrxUpdateItem::kNoUpdate:
556 uit->status = CrxUpdateItem::kNew; 715 uit->status = CrxUpdateItem::kNew;
557 requested_work_items_.insert(uit); 716 requested_work_items_.insert(uit);
(...skipping 18 matching lines...) Expand all
576 void CrxUpdateService::ProcessPendingItems() { 735 void CrxUpdateService::ProcessPendingItems() {
577 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 736 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
578 // First check for ready upgrades and do one. The first 737 // First check for ready upgrades and do one. The first
579 // step is to fetch the crx package. 738 // step is to fetch the crx package.
580 for (UpdateItems::const_iterator it = work_items_.begin(); 739 for (UpdateItems::const_iterator it = work_items_.begin();
581 it != work_items_.end(); ++it) { 740 it != work_items_.end(); ++it) {
582 CrxUpdateItem* item = *it; 741 CrxUpdateItem* item = *it;
583 if (item->status != CrxUpdateItem::kCanUpdate) 742 if (item->status != CrxUpdateItem::kCanUpdate)
584 continue; 743 continue;
585 // Found component to update, start the process. 744 // Found component to update, start the process.
586 item->status = CrxUpdateItem::kDownloading;
587 CRXContext* context = new CRXContext; 745 CRXContext* context = new CRXContext;
588 context->pk_hash = item->component.pk_hash; 746 context->pk_hash = item->component.pk_hash;
589 context->id = item->id; 747 context->id = item->id;
590 context->installer = item->component.installer; 748 context->installer = item->component.installer;
749 context->fingerprint = item->next_fp;
750 GURL package_url;
751 if (CanTryDiffUpdate(item, *config_)) {
752 package_url = item->diff_crx_url;
753 item->status = CrxUpdateItem::kDownloadingDiff;
754 } else {
755 package_url = item->crx_url;
756 item->status = CrxUpdateItem::kDownloading;
757 }
591 url_fetcher_.reset(net::URLFetcher::Create( 758 url_fetcher_.reset(net::URLFetcher::Create(
592 0, item->crx_url, net::URLFetcher::GET, 759 0, package_url, net::URLFetcher::GET,
593 MakeContextDelegate(this, context))); 760 MakeContextDelegate(this, context)));
594 StartFetch(url_fetcher_.get(), config_->RequestContext(), true); 761 StartFetch(url_fetcher_.get(), config_->RequestContext(), true);
595 return; 762 return;
596 } 763 }
597 764
598 for (size_t ix = 0; ix != arraysize(kManifestSources); ++ix) { 765 for (size_t ix = 0; ix != arraysize(kManifestSources); ++ix) {
599 const CrxComponent::UrlSource manifest_source = kManifestSources[ix]; 766 const CrxComponent::UrlSource manifest_source = kManifestSources[ix];
600 767
601 std::string query; 768 std::string query;
602 // If no pending upgrades, we check if there are new components we have not 769 // If no pending upgrades, we check if there are new components we have not
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
693 delete context; 860 delete context;
694 } 861 }
695 862
696 // Parsing the manifest is either done right now for tests or in a sandboxed 863 // Parsing the manifest is either done right now for tests or in a sandboxed
697 // process for the production environment. This mitigates the case where an 864 // process for the production environment. This mitigates the case where an
698 // attacker was able to feed us a malicious xml string. 865 // attacker was able to feed us a malicious xml string.
699 void CrxUpdateService::ParseManifest(const std::string& xml) { 866 void CrxUpdateService::ParseManifest(const std::string& xml) {
700 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 867 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
701 if (config_->InProcess()) { 868 if (config_->InProcess()) {
702 UpdateManifest manifest; 869 UpdateManifest manifest;
703 if (!manifest.Parse(xml)) { 870 if (!manifest.Parse(xml))
704 CrxUpdateService::OnParseUpdateManifestFailed(manifest.errors()); 871 CrxUpdateService::OnParseUpdateManifestFailed(manifest.errors());
705 } else { 872 else
706 CrxUpdateService::OnParseUpdateManifestSucceeded(manifest.results()); 873 CrxUpdateService::OnParseUpdateManifestSucceeded(manifest.results());
707 }
708 } else { 874 } else {
709 UtilityProcessHost* host = 875 UtilityProcessHost* host =
710 UtilityProcessHost::Create(new ManifestParserBridge(this), 876 UtilityProcessHost::Create(new ManifestParserBridge(this),
711 base::MessageLoopProxy::current().get()); 877 base::MessageLoopProxy::current().get());
712 host->EnableZygote(); 878 host->EnableZygote();
713 host->Send(new ChromeUtilityMsg_ParseUpdateManifest(xml)); 879 host->Send(new ChromeUtilityMsg_ParseUpdateManifest(xml));
714 } 880 }
715 } 881 }
716 882
717 // A valid Omaha update check has arrived, from only the list of components that 883 // A valid Omaha update check has arrived, from only the list of components that
(...skipping 27 matching lines...) Expand all
745 } 911 }
746 if (!it->browser_min_version.empty()) { 912 if (!it->browser_min_version.empty()) {
747 if (IsVersionNewer(chrome_version_, it->browser_min_version)) { 913 if (IsVersionNewer(chrome_version_, it->browser_min_version)) {
748 // Does not apply for this chrome version. 914 // Does not apply for this chrome version.
749 crx->status = CrxUpdateItem::kNoUpdate; 915 crx->status = CrxUpdateItem::kNoUpdate;
750 continue; 916 continue;
751 } 917 }
752 } 918 }
753 // All test passed. Queue an upgrade for this component and fire the 919 // All test passed. Queue an upgrade for this component and fire the
754 // notifications. 920 // notifications.
921 crx->is_update_available = true;
755 crx->crx_url = it->crx_url; 922 crx->crx_url = it->crx_url;
923 crx->package_hash = it->package_hash;
924 crx->size = it->size;
925 crx->diff_crx_url = it->diff_crx_url;
926 crx->diff_package_hash = it->diff_package_hash;
927 crx->diff_size = it->diff_size;
756 crx->status = CrxUpdateItem::kCanUpdate; 928 crx->status = CrxUpdateItem::kCanUpdate;
757 crx->next_version = Version(it->version); 929 crx->next_version = Version(it->version);
930 crx->next_fp = it->package_fingerprint;
758 ++update_pending; 931 ++update_pending;
759 932
760 content::NotificationService::current()->Notify( 933 content::NotificationService::current()->Notify(
761 chrome::NOTIFICATION_COMPONENT_UPDATE_FOUND, 934 chrome::NOTIFICATION_COMPONENT_UPDATE_FOUND,
762 content::Source<std::string>(&crx->id), 935 content::Source<std::string>(&crx->id),
763 content::NotificationService::NoDetails()); 936 content::NotificationService::NoDetails());
764 } 937 }
765 938
766 // All the components that are not mentioned in the manifest we 939 // All the components that are not mentioned in the manifest we
767 // consider them up to date. 940 // consider them up to date.
(...skipping 14 matching lines...) Expand all
782 } 955 }
783 956
784 // Called when the CRX package has been downloaded to a temporary location. 957 // Called when the CRX package has been downloaded to a temporary location.
785 // Here we fire the notifications and schedule the component-specific installer 958 // Here we fire the notifications and schedule the component-specific installer
786 // to be called in the file thread. 959 // to be called in the file thread.
787 void CrxUpdateService::OnURLFetchComplete(const net::URLFetcher* source, 960 void CrxUpdateService::OnURLFetchComplete(const net::URLFetcher* source,
788 CRXContext* context) { 961 CRXContext* context) {
789 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 962 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
790 int error_code = net::OK; 963 int error_code = net::OK;
791 964
965 CrxUpdateItem* crx = FindUpdateItemById(context->id);
966
792 if (source->FileErrorOccurred(&error_code) || !FetchSuccess(*source)) { 967 if (source->FileErrorOccurred(&error_code) || !FetchSuccess(*source)) {
793 size_t count = ChangeItemStatus(CrxUpdateItem::kDownloading, 968 if (crx->status == CrxUpdateItem::kDownloadingDiff) {
794 CrxUpdateItem::kNoUpdate); 969 crx->diff_error_code = GetFetchError(*source);
795 DCHECK_EQ(count, 1ul); 970 crx->diff_update_failed = true;
971 crx->status = CrxUpdateItem::kCanUpdate;
972 BrowserThread::PostTask(
973 BrowserThread::UI,
974 FROM_HERE,
975 base::Bind(&CrxUpdateService::ProcessPendingItems,
976 base::Unretained(this)));
977 return;
978 }
979 crx->error_code = GetFetchError(*source);
980 crx->status = CrxUpdateItem::kNoUpdate;
796 config_->OnEvent(Configurator::kNetworkError, CrxIdtoUMAId(context->id)); 981 config_->OnEvent(Configurator::kNetworkError, CrxIdtoUMAId(context->id));
797 url_fetcher_.reset(); 982 url_fetcher_.reset();
798 ScheduleNextRun(false); 983 ScheduleNextRun(false);
799 } else { 984 } else {
800 base::FilePath temp_crx_path; 985 base::FilePath temp_crx_path;
801 CHECK(source->GetResponseAsFilePath(true, &temp_crx_path)); 986 CHECK(source->GetResponseAsFilePath(true, &temp_crx_path));
802 size_t count = ChangeItemStatus(CrxUpdateItem::kDownloading, 987 crx->status = (crx->status == CrxUpdateItem::kDownloadingDiff) ?
803 CrxUpdateItem::kUpdating); 988 CrxUpdateItem::kUpdatingDiff : CrxUpdateItem::kUpdating;
804 DCHECK_EQ(count, 1ul); 989
805 url_fetcher_.reset(); 990 url_fetcher_.reset();
806 991
807 content::NotificationService::current()->Notify( 992 content::NotificationService::current()->Notify(
808 chrome::NOTIFICATION_COMPONENT_UPDATE_READY, 993 chrome::NOTIFICATION_COMPONENT_UPDATE_READY,
809 content::Source<std::string>(&context->id), 994 content::Source<std::string>(&context->id),
810 content::NotificationService::NoDetails()); 995 content::NotificationService::NoDetails());
811 996
812 // Why unretained? See comment at top of file. 997 // Why unretained? See comment at top of file.
813 BrowserThread::PostDelayedTask( 998 BrowserThread::PostDelayedTask(
814 BrowserThread::FILE, 999 BrowserThread::FILE,
815 FROM_HERE, 1000 FROM_HERE,
816 base::Bind(&CrxUpdateService::Install, 1001 base::Bind(&CrxUpdateService::Install,
817 base::Unretained(this), 1002 base::Unretained(this),
818 context, 1003 context,
819 temp_crx_path), 1004 temp_crx_path),
820 base::TimeDelta::FromMilliseconds(config_->StepDelay())); 1005 base::TimeDelta::FromMilliseconds(config_->StepDelay()));
821 } 1006 }
822 } 1007 }
823 1008
824 // Install consists of digital signature verification, unpacking and then 1009 // Install consists of digital signature verification, unpacking and then
825 // calling the component specific installer. All that is handled by the 1010 // calling the component specific installer. All that is handled by the
826 // |unpacker|. If there is an error this function is in charge of deleting 1011 // |unpacker|. If there is an error this function is in charge of deleting
827 // the files created. 1012 // the files created.
828 void CrxUpdateService::Install(const CRXContext* context, 1013 void CrxUpdateService::Install(const CRXContext* context,
829 const base::FilePath& crx_path) { 1014 const base::FilePath& crx_path) {
830 // This function owns the |crx_path| and the |context| object. 1015 // This function owns the |crx_path| and the |context| object.
831 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 1016 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
832 ComponentUnpacker 1017 ComponentUnpacker unpacker(context->pk_hash,
833 unpacker(context->pk_hash, crx_path, context->installer); 1018 crx_path,
834 if (!file_util::Delete(crx_path, false)) { 1019 context->fingerprint,
1020 component_patcher_.get(),
1021 context->installer);
1022 if (!file_util::Delete(crx_path, false))
835 NOTREACHED() << crx_path.value(); 1023 NOTREACHED() << crx_path.value();
836 }
837 // Why unretained? See comment at top of file. 1024 // Why unretained? See comment at top of file.
838 BrowserThread::PostDelayedTask( 1025 BrowserThread::PostDelayedTask(
839 BrowserThread::UI, 1026 BrowserThread::UI,
840 FROM_HERE, 1027 FROM_HERE,
841 base::Bind(&CrxUpdateService::DoneInstalling, base::Unretained(this), 1028 base::Bind(&CrxUpdateService::DoneInstalling, base::Unretained(this),
842 context->id, unpacker.error()), 1029 context->id, unpacker.error(), unpacker.extended_error()),
843 base::TimeDelta::FromMilliseconds(config_->StepDelay())); 1030 base::TimeDelta::FromMilliseconds(config_->StepDelay()));
844 delete context; 1031 delete context;
845 } 1032 }
846 1033
847 // Installation has been completed. Adjust the component status and 1034 // Installation has been completed. Adjust the component status and
848 // schedule the next check. 1035 // schedule the next check.
849 void CrxUpdateService::DoneInstalling(const std::string& component_id, 1036 void CrxUpdateService::DoneInstalling(const std::string& component_id,
850 ComponentUnpacker::Error error) { 1037 ComponentUnpacker::Error error,
1038 int extra_code) {
851 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1039 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
852 1040
853 CrxUpdateItem* item = FindUpdateItemById(component_id); 1041 CrxUpdateItem* item = FindUpdateItemById(component_id);
1042 if (item->status == CrxUpdateItem::kUpdatingDiff) {
1043 if (error != ComponentUnpacker::kNone) {
1044 item->diff_error_code = error;
1045 item->diff_extra_code1 = extra_code;
1046 item->diff_update_failed = true;
1047 item->status = CrxUpdateItem::kCanUpdate;
1048 BrowserThread::PostTask(
1049 BrowserThread::UI,
1050 FROM_HERE,
1051 base::Bind(&CrxUpdateService::ProcessPendingItems,
1052 base::Unretained(this)));
1053 return;
1054 }
1055 }
1056
1057 if (error != ComponentUnpacker::kNone) {
1058 item->error_code = error;
1059 item->extra_code1 = extra_code;
1060 }
1061
854 item->status = (error == ComponentUnpacker::kNone) ? CrxUpdateItem::kUpdated : 1062 item->status = (error == ComponentUnpacker::kNone) ? CrxUpdateItem::kUpdated :
855 CrxUpdateItem::kNoUpdate; 1063 CrxUpdateItem::kNoUpdate;
856 if (item->status == CrxUpdateItem::kUpdated) 1064 if (item->status == CrxUpdateItem::kUpdated) {
857 item->component.version = item->next_version; 1065 item->component.version = item->next_version;
1066 item->component.fingerprint = item->next_fp;
1067 }
858 1068
859 Configurator::Events event; 1069 Configurator::Events event;
860 switch (error) { 1070 switch (error) {
861 case ComponentUnpacker::kNone: 1071 case ComponentUnpacker::kNone:
862 event = Configurator::kComponentUpdated; 1072 event = Configurator::kComponentUpdated;
863 break; 1073 break;
864 case ComponentUnpacker::kInstallerError: 1074 case ComponentUnpacker::kInstallerError:
865 event = Configurator::kInstallerError; 1075 event = Configurator::kInstallerError;
866 break; 1076 break;
867 default: 1077 default:
868 event = Configurator::kUnpackError; 1078 event = Configurator::kUnpackError;
869 break; 1079 break;
870 } 1080 }
871 1081
872 config_->OnEvent(event, CrxIdtoUMAId(component_id)); 1082 config_->OnEvent(event, CrxIdtoUMAId(component_id));
873 ScheduleNextRun(false); 1083 ScheduleNextRun(false);
874 } 1084 }
875 1085
1086 void CrxUpdateService::SendPing(const std::string& ping) {
1087 VLOG(3) << "Sending ping. " << ping;
1088 const std::string ping_url(config_->PingUrl().spec());
1089 ping_sender_.reset(net::URLFetcher::Create(
1090 0, GURL(ping_url), net::URLFetcher::POST,
1091 MakeContextDelegate(this, new PingContext())));
1092 ping_sender_->SetUploadData(std::string("application/xml"), ping);
1093 StartFetch(ping_sender_.get(), config_->RequestContext(), false);
1094 }
1095
1096 void CrxUpdateService::OnURLFetchComplete(const net::URLFetcher* source,
1097 PingContext* context) {
1098 VLOG(3) << "Sending component update ping returned "
1099 << FetchSuccess(*source);
1100 ping_sender_.reset();
1101 }
1102
1103 // Builds a ping message for the update items that have completed. Returns
1104 // an empty string if there are no completed items.
1105 std::string CrxUpdateService::BuildPing() const {
1106 const std::string apps(BuildPingApps());
1107 if (apps.empty())
1108 return std::string();
1109
1110 const char response_format[] =
1111 "<o:gupdate xmlns:o=\"http://www.google.com/update2/request\" "
1112 "protocol=\"2.0\" version=\"%s-%s\" requestid=\"{%s}\"> "
1113 "<o:os platform=\"%s\" version=\"%s\"/> "
1114 "%s"
1115 "</o:gupdate>";
1116 const std::string response_envelope(
1117 base::StringPrintf(response_format,
1118 prod_id_.c_str(),
1119 chrome_version_.GetString().c_str(),
1120 base::GenerateGUID().c_str(),
1121 os_type_.c_str(),
1122 os_version_.c_str(),
1123 apps.c_str()));
1124 return response_envelope;
1125 }
1126
1127 // Returns a string containing the sequence of app elements inside the
1128 // ping message.
1129 std::string CrxUpdateService::BuildPingApps() const {
1130 const char app_format[] = "<o:app appid=\"%s\" version=\"%s\">%s</o:app>";
1131
1132 std::string ping_apps;
1133 for (UpdateItems::const_iterator it = work_items_.begin();
1134 it != work_items_.end(); ++it) {
1135 CrxUpdateItem* item = *it;
1136 // Only ping once if an update was available and the item is completed.
1137 if (item->is_update_available && !item->ping_queued &&
1138 (item->status == CrxUpdateItem::kNoUpdate ||
1139 item->status == CrxUpdateItem::kUpdated)) {
1140 const std::string version = item->component.version.GetString().c_str();
1141 ping_apps += base::StringPrintf(app_format,
1142 item->id.c_str(),
1143 version.c_str(),
1144 BuildPingEvent(item).c_str());
1145 }
1146 }
1147 return ping_apps;
1148 }
1149
1150 // Returns a string representing one ping event for an update item.
1151 std::string CrxUpdateService::BuildPingEvent(CrxUpdateItem* item) {
1152 DCHECK(item->status == CrxUpdateItem::kNoUpdate ||
1153 item->status == CrxUpdateItem::kUpdated);
1154 DCHECK(item->is_update_available);
1155
1156 using base::StringAppendF;
1157
1158 std::string ping_event("<o:event eventtype=\"3\"");
1159 const int event_result = item->status == CrxUpdateItem::kUpdated;
1160 StringAppendF(&ping_event, " eventresult=\"%d\"", event_result);
1161 StringAppendF(&ping_event, " previousversion=\"%s\"",
1162 item->previous_version.GetString().c_str());
1163 StringAppendF(&ping_event, " nextversion=\"%s\"",
1164 item->next_version.GetString().c_str());
1165 if (item->error_code)
1166 StringAppendF(&ping_event, " errorcode=\"%d\"", item->error_code);
1167 if (item->extra_code1)
1168 StringAppendF(&ping_event, " extracode1=\"%d\"", item->extra_code1);
1169 if (IsDiffUpdateAvailable(item))
1170 StringAppendF(&ping_event, " diffresult=\"%d\"", !item->diff_update_failed);
1171 if (item->diff_error_code)
1172 StringAppendF(&ping_event, " differrorcode=\"%d\"", item->diff_error_code);
1173 if (item->diff_extra_code1) {
1174 StringAppendF(&ping_event,
1175 " diffextracode1=\"%d\"",
1176 item->diff_extra_code1);
1177 }
1178 if (!item->previous_fp.empty())
1179 StringAppendF(&ping_event, " previousfp=\"%s\"", item->previous_fp.c_str());
1180 if (!item->next_fp.empty())
1181 StringAppendF(&ping_event, " nextfp=\"%s\"", item->next_fp.c_str());
1182 StringAppendF(&ping_event, "/>");
1183 item->ping_queued = true;
1184 return ping_event;
1185 }
1186
1187
876 // The component update factory. Using the component updater as a singleton 1188 // The component update factory. Using the component updater as a singleton
877 // is the job of the browser process. 1189 // is the job of the browser process.
878 ComponentUpdateService* ComponentUpdateServiceFactory( 1190 ComponentUpdateService* ComponentUpdateServiceFactory(
879 ComponentUpdateService::Configurator* config) { 1191 ComponentUpdateService::Configurator* config) {
880 DCHECK(config); 1192 DCHECK(config);
881 return new CrxUpdateService(config); 1193 return new CrxUpdateService(config);
882 } 1194 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698