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_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 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
56 CrxComponent::BANDAID, | 56 CrxComponent::BANDAID, |
57 CrxComponent::CWS_PUBLIC, | 57 CrxComponent::CWS_PUBLIC, |
58 CrxComponent::CWS_SANDBOX, | 58 CrxComponent::CWS_SANDBOX, |
59 }; | 59 }; |
60 | 60 |
61 // Extends an omaha compatible update check url |query| string. Does | 61 // Extends an omaha compatible update check url |query| string. Does |
62 // not mutate the string if it would be longer than |limit| chars. | 62 // not mutate the string if it would be longer than |limit| chars. |
63 bool AddQueryString(const std::string& id, | 63 bool AddQueryString(const std::string& id, |
64 const std::string& version, | 64 const std::string& version, |
65 const std::string& fingerprint, | 65 const std::string& fingerprint, |
66 bool ondemand, | |
66 size_t limit, | 67 size_t limit, |
67 std::string* query) { | 68 std::string* query) { |
68 std::string additional = | 69 std::string additional = |
69 base::StringPrintf("id=%s&v=%s&fp=%s&uc", | 70 base::StringPrintf("id=%s&v=%s&fp=%s&uc%s", |
70 id.c_str(), version.c_str(), fingerprint.c_str()); | 71 id.c_str(), |
72 version.c_str(), | |
73 fingerprint.c_str(), | |
74 ondemand ? "&installsource=ondemand" : ""); | |
71 additional = "x=" + net::EscapeQueryParamValue(additional, true); | 75 additional = "x=" + net::EscapeQueryParamValue(additional, true); |
72 if ((additional.size() + query->size() + 1) > limit) | 76 if ((additional.size() + query->size() + 1) > limit) |
73 return false; | 77 return false; |
74 if (!query->empty()) | 78 if (!query->empty()) |
75 query->append(1, '&'); | 79 query->append(1, '&'); |
76 query->append(additional); | 80 query->append(additional); |
77 return true; | 81 return true; |
78 } | 82 } |
79 | 83 |
80 // 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 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
374 CRXContext* context); | 378 CRXContext* context); |
375 | 379 |
376 private: | 380 private: |
377 // See ManifestParserBridge. | 381 // See ManifestParserBridge. |
378 void OnParseUpdateManifestSucceeded( | 382 void OnParseUpdateManifestSucceeded( |
379 const UpdateManifest::Results& results); | 383 const UpdateManifest::Results& results); |
380 | 384 |
381 // See ManifestParserBridge. | 385 // See ManifestParserBridge. |
382 void OnParseUpdateManifestFailed(const std::string& error_message); | 386 void OnParseUpdateManifestFailed(const std::string& error_message); |
383 | 387 |
384 bool AddItemToUpdateCheck(CrxUpdateItem* item, std::string* query); | 388 bool AddItemToUpdateCheck(CrxUpdateItem* item, |
389 bool ondemand, | |
390 std::string* query); | |
385 | 391 |
386 void ProcessPendingItems(); | 392 void ProcessPendingItems(); |
387 | 393 |
388 void ScheduleNextRun(bool step_delay); | 394 void ScheduleNextRun(bool step_delay); |
389 | 395 |
390 void ParseManifest(const std::string& xml); | 396 void ParseManifest(const std::string& xml); |
391 | 397 |
392 void Install(const CRXContext* context, const base::FilePath& crx_path); | 398 void Install(const CRXContext* context, const base::FilePath& crx_path); |
393 | 399 |
394 void DoneInstalling(const std::string& component_id, | 400 void DoneInstalling(const std::string& component_id, |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
564 Start(); | 570 Start(); |
565 | 571 |
566 return kOk; | 572 return kOk; |
567 } | 573 } |
568 | 574 |
569 // Sets a component to be checked for updates. | 575 // Sets a component to be checked for updates. |
570 // The component to add is |crxit| and the |query| string is modified with the | 576 // The component to add is |crxit| and the |query| string is modified with the |
571 // required omaha compatible query. Returns false when the query strings | 577 // required omaha compatible query. Returns false when the query strings |
572 // is longer than specified by UrlSizeLimit(). | 578 // is longer than specified by UrlSizeLimit(). |
573 bool CrxUpdateService::AddItemToUpdateCheck(CrxUpdateItem* item, | 579 bool CrxUpdateService::AddItemToUpdateCheck(CrxUpdateItem* item, |
580 bool ondemand, | |
574 std::string* query) { | 581 std::string* query) { |
575 if (!AddQueryString(item->id, | 582 if (!AddQueryString(item->id, |
576 item->component.version.GetString(), | 583 item->component.version.GetString(), |
577 item->component.fingerprint, | 584 item->component.fingerprint, |
578 config_->UrlSizeLimit(), query)) | 585 ondemand, |
586 config_->UrlSizeLimit(), | |
587 query)) | |
579 return false; | 588 return false; |
580 | 589 |
581 item->status = CrxUpdateItem::kChecking; | 590 item->status = CrxUpdateItem::kChecking; |
582 item->last_check = base::Time::Now(); | 591 item->last_check = base::Time::Now(); |
583 item->previous_version = item->component.version; | 592 item->previous_version = item->component.version; |
584 item->next_version = Version(); | 593 item->next_version = Version(); |
585 item->previous_fp = item->component.fingerprint; | 594 item->previous_fp = item->component.fingerprint; |
586 item->next_fp.clear(); | 595 item->next_fp.clear(); |
587 item->diff_update_failed = false; | 596 item->diff_update_failed = false; |
588 return true; | 597 return true; |
589 } | 598 } |
590 | 599 |
591 // Start the process of checking for an update, for a particular component | 600 // Start the process of checking for an update, for a particular component |
592 // that was previously registered. | 601 // that was previously registered. |
602 // If the component is still at version "0" (representing not-yet-installed), | |
603 // the update check will be an "on-demand" updatecheck, which the server may | |
604 // choose to handle differently. | |
593 ComponentUpdateService::Status CrxUpdateService::CheckForUpdateSoon( | 605 ComponentUpdateService::Status CrxUpdateService::CheckForUpdateSoon( |
594 const CrxComponent& component) { | 606 const CrxComponent& component) { |
595 if (component.pk_hash.empty() || | 607 if (component.pk_hash.empty() || |
596 !component.version.IsValid() || | 608 !component.version.IsValid() || |
597 !component.installer) | 609 !component.installer) |
598 return kError; | 610 return kError; |
599 | 611 |
600 std::string id = | 612 std::string id = |
601 HexStringToID(StringToLowerASCII(base::HexEncode(&component.pk_hash[0], | 613 HexStringToID(StringToLowerASCII(base::HexEncode(&component.pk_hash[0], |
602 component.pk_hash.size()/2))); | 614 component.pk_hash.size()/2))); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
683 std::string query; | 695 std::string query; |
684 // If no pending upgrades, we check if there are new components we have not | 696 // If no pending upgrades, we check if there are new components we have not |
685 // checked against the server. We can batch some in a single url request. | 697 // checked against the server. We can batch some in a single url request. |
686 for (UpdateItems::const_iterator it = work_items_.begin(); | 698 for (UpdateItems::const_iterator it = work_items_.begin(); |
687 it != work_items_.end(); ++it) { | 699 it != work_items_.end(); ++it) { |
688 CrxUpdateItem* item = *it; | 700 CrxUpdateItem* item = *it; |
689 if (item->status != CrxUpdateItem::kNew) | 701 if (item->status != CrxUpdateItem::kNew) |
690 continue; | 702 continue; |
691 if (item->component.source != manifest_source) | 703 if (item->component.source != manifest_source) |
692 continue; | 704 continue; |
693 if (!AddItemToUpdateCheck(item, &query)) | 705 bool ondemand = requested_work_items_.count(item) && |
706 item->component.version.Equals(Version("0")); | |
cpu_(ooo_6.6-7.5)
2013/06/21 00:22:56
I don't think so. This is hacky and the on-demand
waffles
2013/06/21 01:52:08
Done.
I had the Version==0 check in response to m
| |
707 if (!AddItemToUpdateCheck(item, ondemand, &query)) | |
694 break; | 708 break; |
695 // Requested work items may speed up the update cycle up until | 709 // Requested work items may speed up the update cycle up until |
696 // the point that we start an update check. I.e., transition | 710 // the point that we start an update check. I.e., transition |
697 // from kNew -> kChecking. Since the service doesn't guarantee that | 711 // from kNew -> kChecking. Since the service doesn't guarantee that |
698 // the requested items make it any further than kChecking, | 712 // the requested items make it any further than kChecking, |
699 // forget them now. | 713 // forget them now. |
700 requested_work_items_.erase(item); | 714 requested_work_items_.erase(item); |
701 } | 715 } |
702 | 716 |
703 // Next we can go back to components we already checked, here | 717 // Next we can go back to components we already checked, here |
704 // we can also batch them in a single url request, as long as | 718 // we can also batch them in a single url request, as long as |
705 // we have not checked them recently. | 719 // we have not checked them recently. |
706 const base::TimeDelta min_delta_time = | 720 const base::TimeDelta min_delta_time = |
707 base::TimeDelta::FromSeconds(config_->MinimumReCheckWait()); | 721 base::TimeDelta::FromSeconds(config_->MinimumReCheckWait()); |
708 | 722 |
709 for (UpdateItems::const_iterator it = work_items_.begin(); | 723 for (UpdateItems::const_iterator it = work_items_.begin(); |
710 it != work_items_.end(); ++it) { | 724 it != work_items_.end(); ++it) { |
711 CrxUpdateItem* item = *it; | 725 CrxUpdateItem* item = *it; |
712 if ((item->status != CrxUpdateItem::kNoUpdate) && | 726 if ((item->status != CrxUpdateItem::kNoUpdate) && |
713 (item->status != CrxUpdateItem::kUpToDate)) | 727 (item->status != CrxUpdateItem::kUpToDate)) |
714 continue; | 728 continue; |
715 if (item->component.source != manifest_source) | 729 if (item->component.source != manifest_source) |
716 continue; | 730 continue; |
717 base::TimeDelta delta = base::Time::Now() - item->last_check; | 731 base::TimeDelta delta = base::Time::Now() - item->last_check; |
718 if (delta < min_delta_time) | 732 if (delta < min_delta_time) |
719 continue; | 733 continue; |
720 if (!AddItemToUpdateCheck(item, &query)) | 734 if (!AddItemToUpdateCheck(item, false, &query)) |
721 break; | 735 break; |
722 } | 736 } |
723 | 737 |
724 // Finally, we check components that we already updated as long as | 738 // Finally, we check components that we already updated as long as |
725 // we have not checked them recently. | 739 // we have not checked them recently. |
726 for (UpdateItems::const_iterator it = work_items_.begin(); | 740 for (UpdateItems::const_iterator it = work_items_.begin(); |
727 it != work_items_.end(); ++it) { | 741 it != work_items_.end(); ++it) { |
728 CrxUpdateItem* item = *it; | 742 CrxUpdateItem* item = *it; |
729 if (item->status != CrxUpdateItem::kUpdated) | 743 if (item->status != CrxUpdateItem::kUpdated) |
730 continue; | 744 continue; |
731 if (item->component.source != manifest_source) | 745 if (item->component.source != manifest_source) |
732 continue; | 746 continue; |
733 base::TimeDelta delta = base::Time::Now() - item->last_check; | 747 base::TimeDelta delta = base::Time::Now() - item->last_check; |
734 if (delta < min_delta_time) | 748 if (delta < min_delta_time) |
735 continue; | 749 continue; |
736 if (!AddItemToUpdateCheck(item, &query)) | 750 if (!AddItemToUpdateCheck(item, false, &query)) |
737 break; | 751 break; |
738 } | 752 } |
739 | 753 |
740 // If no components to update we move down to the next source. | 754 // If no components to update we move down to the next source. |
741 if (query.empty()) | 755 if (query.empty()) |
742 continue; | 756 continue; |
743 | 757 |
744 // We got components to check. Start the url request and exit. | 758 // We got components to check. Start the url request and exit. |
745 const std::string full_query = | 759 const std::string full_query = |
746 MakeFinalQuery(config_->UpdateUrl(manifest_source).spec(), | 760 MakeFinalQuery(config_->UpdateUrl(manifest_source).spec(), |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
994 ScheduleNextRun(false); | 1008 ScheduleNextRun(false); |
995 } | 1009 } |
996 | 1010 |
997 // The component update factory. Using the component updater as a singleton | 1011 // The component update factory. Using the component updater as a singleton |
998 // is the job of the browser process. | 1012 // is the job of the browser process. |
999 ComponentUpdateService* ComponentUpdateServiceFactory( | 1013 ComponentUpdateService* ComponentUpdateServiceFactory( |
1000 ComponentUpdateService::Configurator* config) { | 1014 ComponentUpdateService::Configurator* config) { |
1001 DCHECK(config); | 1015 DCHECK(config); |
1002 return new CrxUpdateService(config); | 1016 return new CrxUpdateService(config); |
1003 } | 1017 } |
OLD | NEW |