| 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 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 560 work_items_.push_back(uit); | 564 work_items_.push_back(uit); |
| 561 // If this is the first component registered we call Start to | 565 // If this is the first component registered we call Start to |
| 562 // schedule the first timer. | 566 // schedule the first timer. |
| 563 if (running_ && (work_items_.size() == 1)) | 567 if (running_ && (work_items_.size() == 1)) |
| 564 Start(); | 568 Start(); |
| 565 | 569 |
| 566 return kOk; | 570 return kOk; |
| 567 } | 571 } |
| 568 | 572 |
| 569 // Sets a component to be checked for updates. | 573 // Sets a component to be checked for updates. |
| 570 // The component to add is |crxit| and the |query| string is modified with the | 574 // The component to add is |item| and the |query| string is modified with the |
| 571 // required omaha compatible query. Returns false when the query strings | 575 // required omaha compatible query. Returns false when the query string is |
| 572 // is longer than specified by UrlSizeLimit(). | 576 // longer than specified by UrlSizeLimit(). |
| 577 // If the item is currently on the requested_work_items_ list, the update check |
| 578 // is considered to be "on-demand": the server may honor on-demand checks by |
| 579 // serving updates at 100% rather than a gated fraction. |
| 573 bool CrxUpdateService::AddItemToUpdateCheck(CrxUpdateItem* item, | 580 bool CrxUpdateService::AddItemToUpdateCheck(CrxUpdateItem* item, |
| 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 requested_work_items_.count(item) > 0, // is_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; |
| (...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 995 ScheduleNextRun(false); | 1004 ScheduleNextRun(false); |
| 996 } | 1005 } |
| 997 | 1006 |
| 998 // The component update factory. Using the component updater as a singleton | 1007 // The component update factory. Using the component updater as a singleton |
| 999 // is the job of the browser process. | 1008 // is the job of the browser process. |
| 1000 ComponentUpdateService* ComponentUpdateServiceFactory( | 1009 ComponentUpdateService* ComponentUpdateServiceFactory( |
| 1001 ComponentUpdateService::Configurator* config) { | 1010 ComponentUpdateService::Configurator* config) { |
| 1002 DCHECK(config); | 1011 DCHECK(config); |
| 1003 return new CrxUpdateService(config); | 1012 return new CrxUpdateService(config); |
| 1004 } | 1013 } |
| OLD | NEW |