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

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

Issue 11859044: Add a way to specify different source urls for the component updater (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 11 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 <vector> 8 #include <vector>
9 9
10 #include "base/at_exit.h" 10 #include "base/at_exit.h"
(...skipping 27 matching lines...) Expand all
38 38
39 using content::BrowserThread; 39 using content::BrowserThread;
40 using content::UtilityProcessHost; 40 using content::UtilityProcessHost;
41 using content::UtilityProcessHostClient; 41 using content::UtilityProcessHostClient;
42 using extensions::Extension; 42 using extensions::Extension;
43 43
44 // The component updater is designed to live until process shutdown, so 44 // The component updater is designed to live until process shutdown, so
45 // base::Bind() calls are not refcounted. 45 // base::Bind() calls are not refcounted.
46 46
47 namespace { 47 namespace {
48 // Manifest sources, from most important to least important.
49 const CrxComponent::UrlSource kManifestSources[] = {
50 CrxComponent::BANDAID,
51 CrxComponent::CWS_PUBLIC,
52 CrxComponent::CWS_SANDBOX
53 };
54
48 // Extends an omaha compatible update check url |query| string. Does 55 // Extends an omaha compatible update check url |query| string. Does
49 // not mutate the string if it would be longer than |limit| chars. 56 // not mutate the string if it would be longer than |limit| chars.
50 bool AddQueryString(const std::string& id, 57 bool AddQueryString(const std::string& id,
51 const std::string& version, 58 const std::string& version,
52 size_t limit, 59 size_t limit,
53 std::string* query) { 60 std::string* query) {
54 std::string additional = 61 std::string additional =
55 base::StringPrintf("id=%s&v=%s&uc", id.c_str(), version.c_str()); 62 base::StringPrintf("id=%s&v=%s&uc", id.c_str(), version.c_str());
56 additional = "x=" + net::EscapeQueryParamValue(additional, true); 63 additional = "x=" + net::EscapeQueryParamValue(additional, true);
57 if ((additional.size() + query->size() + 1) > limit) 64 if ((additional.size() + query->size() + 1) > limit)
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 } 215 }
209 private: 216 private:
210 const std::string& id_; 217 const std::string& id_;
211 }; 218 };
212 }; 219 };
213 220
214 } // namespace. 221 } // namespace.
215 222
216 typedef ComponentUpdateService::Configurator Config; 223 typedef ComponentUpdateService::Configurator Config;
217 224
218 CrxComponent::CrxComponent() : installer(NULL) {} 225 CrxComponent::CrxComponent()
219 CrxComponent::~CrxComponent() {} 226 : installer(NULL),
227 source(BANDAID) {
cpu_(ooo_6.6-7.5) 2013/01/21 02:47:19 the default source is the current one so I don't h
228 }
229
230 CrxComponent::~CrxComponent() {
231 }
220 232
221 ////////////////////////////////////////////////////////////////////////////// 233 //////////////////////////////////////////////////////////////////////////////
222 // The one and only implementation of the ComponentUpdateService interface. In 234 // The one and only implementation of the ComponentUpdateService interface. In
223 // charge of running the show. The main method is ProcessPendingItems() which 235 // charge of running the show. The main method is ProcessPendingItems() which
224 // is called periodically to do the upgrades/installs or the update checks. 236 // is called periodically to do the upgrades/installs or the update checks.
225 // An important consideration here is to be as "low impact" as we can to the 237 // An important consideration here is to be as "low impact" as we can to the
226 // rest of the browser, so even if we have many components registered and 238 // rest of the browser, so even if we have many components registered and
227 // eligible for update, we only do one thing at a time with pauses in between 239 // eligible for update, we only do one thing at a time with pauses in between
228 // the tasks. Also when we do network requests there is only one |url_fetcher_| 240 // the tasks. Also when we do network requests there is only one |url_fetcher_|
229 // in flight at at a time. 241 // in flight at at a time.
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 CRXContext* context = new CRXContext; 519 CRXContext* context = new CRXContext;
508 context->pk_hash = item->component.pk_hash; 520 context->pk_hash = item->component.pk_hash;
509 context->id = item->id; 521 context->id = item->id;
510 context->installer = item->component.installer; 522 context->installer = item->component.installer;
511 url_fetcher_.reset(net::URLFetcher::Create( 523 url_fetcher_.reset(net::URLFetcher::Create(
512 0, item->crx_url, net::URLFetcher::GET, 524 0, item->crx_url, net::URLFetcher::GET,
513 MakeContextDelegate(this, context))); 525 MakeContextDelegate(this, context)));
514 StartFetch(url_fetcher_.get(), config_->RequestContext(), true); 526 StartFetch(url_fetcher_.get(), config_->RequestContext(), true);
515 return; 527 return;
516 } 528 }
517 529
cpu_(ooo_6.6-7.5) 2013/01/21 02:47:19 this new for loop is the meat of the change. Basic
518 std::string query; 530 for (size_t ix = 0; ix != arraysize(kManifestSources); ++ix) {
519 // If no pending upgrades, we check the if there are new 531 const CrxComponent::UrlSource manifest_source = kManifestSources[ix];
520 // components we have not checked against the server. We 532
521 // can batch a bunch in a single url request. 533 std::string query;
522 for (UpdateItems::const_iterator it = work_items_.begin(); 534 // If no pending upgrades, we check the if there are new
asargent_no_longer_on_chrome 2013/01/23 17:58:32 typo: "we check the if there"
cpu_(ooo_6.6-7.5) 2013/01/23 18:56:06 Done.
523 it != work_items_.end(); ++it) { 535 // components we have not checked against the server. We
524 CrxUpdateItem* item = *it; 536 // can batch a bunch in a single url request.
525 if (item->status != CrxUpdateItem::kNew) 537 for (UpdateItems::const_iterator it = work_items_.begin();
538 it != work_items_.end(); ++it) {
539 CrxUpdateItem* item = *it;
540 if (item->status != CrxUpdateItem::kNew)
541 continue;
542 if (item->component.source != manifest_source)
543 continue;
544 if (!AddItemToUpdateCheck(item, &query))
545 break;
546 }
547
548 // Next we can go back to components we already checked, here
549 // we can also batch them in a single url request, as long as
550 // we have not checked them recently.
551 const base::TimeDelta min_delta_time =
552 base::TimeDelta::FromSeconds(config_->MinimumReCheckWait());
553
554 for (UpdateItems::const_iterator it = work_items_.begin();
555 it != work_items_.end(); ++it) {
556 CrxUpdateItem* item = *it;
557 if ((item->status != CrxUpdateItem::kNoUpdate) &&
558 (item->status != CrxUpdateItem::kUpToDate))
559 continue;
560 if (item->component.source != manifest_source)
561 continue;
562 base::TimeDelta delta = base::Time::Now() - item->last_check;
563 if (delta < min_delta_time)
564 continue;
565 if (!AddItemToUpdateCheck(item, &query))
566 break;
567 }
568
569 // Finally, we check components that we already updated as long
570 // we have not checked them recently.
asargent_no_longer_on_chrome 2013/01/23 17:58:32 typo: comment should say "..updated as long as we
cpu_(ooo_6.6-7.5) 2013/01/23 18:56:06 Done.
571 for (UpdateItems::const_iterator it = work_items_.begin();
572 it != work_items_.end(); ++it) {
573 CrxUpdateItem* item = *it;
574 if (item->status != CrxUpdateItem::kUpdated)
575 continue;
576 if (item->component.source != manifest_source)
577 continue;
578 base::TimeDelta delta = base::Time::Now() - item->last_check;
579 if (delta < min_delta_time)
580 continue;
581 if (!AddItemToUpdateCheck(item, &query))
582 break;
583 }
asargent_no_longer_on_chrome 2013/01/23 17:58:32 I assume that work_items_ will always be very shor
cpu_(ooo_6.6-7.5) 2013/01/23 18:56:06 Yep, currently at 4 items. On 2013/01/23 17:58:32
584
585 // If no components to update we move down to the next source.
586 if (query.empty())
526 continue; 587 continue;
527 if (!AddItemToUpdateCheck(item, &query))
528 break;
529 }
530 588
531 // Next we can go back to components we already checked, here 589 // We got components to check. Start the url request and exit.
532 // we can also batch them in a single url request, as long as 590 const std::string full_query =
533 // we have not checked them recently. 591 MakeFinalQuery(config_->UpdateUrl(manifest_source).spec(),
534 const base::TimeDelta min_delta_time = 592 query,
535 base::TimeDelta::FromSeconds(config_->MinimumReCheckWait()); 593 config_->ExtraRequestParams());
536 594
537 for (UpdateItems::const_iterator it = work_items_.begin(); 595 url_fetcher_.reset(net::URLFetcher::Create(
538 it != work_items_.end(); ++it) { 596 0, GURL(full_query), net::URLFetcher::GET,
539 CrxUpdateItem* item = *it; 597 MakeContextDelegate(this, new UpdateContext())));
540 if ((item->status != CrxUpdateItem::kNoUpdate) && 598 StartFetch(url_fetcher_.get(), config_->RequestContext(), false);
541 (item->status != CrxUpdateItem::kUpToDate))
542 continue;
543 base::TimeDelta delta = base::Time::Now() - item->last_check;
544 if (delta < min_delta_time)
545 continue;
546 if (!AddItemToUpdateCheck(item, &query))
547 break;
548 }
549 // Finally, we check components that we already updated.
550 for (UpdateItems::const_iterator it = work_items_.begin();
551 it != work_items_.end(); ++it) {
552 CrxUpdateItem* item = *it;
553 if (item->status != CrxUpdateItem::kUpdated)
554 continue;
555 base::TimeDelta delta = base::Time::Now() - item->last_check;
556 if (delta < min_delta_time)
557 continue;
558 if (!AddItemToUpdateCheck(item, &query))
559 break;
560 }
561
562 if (query.empty()) {
563 // Next check after the long sleep.
564 ScheduleNextRun(false);
565 return; 599 return;
566 } 600 }
567 601
568 // We got components to check. Start the url request. 602 // No components to update. Next check after the long sleep.
569 const std::string full_query = MakeFinalQuery(config_->UpdateUrl().spec(), 603 ScheduleNextRun(false);
570 query,
571 config_->ExtraRequestParams());
572 url_fetcher_.reset(net::URLFetcher::Create(
573 0, GURL(full_query), net::URLFetcher::GET,
574 MakeContextDelegate(this, new UpdateContext())));
575 StartFetch(url_fetcher_.get(), config_->RequestContext(), false);
576 } 604 }
577 605
578 // Caled when we got a response from the update server. It consists of an xml 606 // Caled when we got a response from the update server. It consists of an xml
579 // document following the omaha update scheme. 607 // document following the omaha update scheme.
580 void CrxUpdateService::OnURLFetchComplete(const net::URLFetcher* source, 608 void CrxUpdateService::OnURLFetchComplete(const net::URLFetcher* source,
581 UpdateContext* context) { 609 UpdateContext* context) {
582 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 610 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
583 if (FetchSuccess(*source)) { 611 if (FetchSuccess(*source)) {
584 std::string xml; 612 std::string xml;
585 source->GetResponseAsString(&xml); 613 source->GetResponseAsString(&xml);
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
772 ScheduleNextRun(false); 800 ScheduleNextRun(false);
773 } 801 }
774 802
775 // The component update factory. Using the component updater as a singleton 803 // The component update factory. Using the component updater as a singleton
776 // is the job of the browser process. 804 // is the job of the browser process.
777 ComponentUpdateService* ComponentUpdateServiceFactory( 805 ComponentUpdateService* ComponentUpdateServiceFactory(
778 ComponentUpdateService::Configurator* config) { 806 ComponentUpdateService::Configurator* config) {
779 DCHECK(config); 807 DCHECK(config);
780 return new CrxUpdateService(config); 808 return new CrxUpdateService(config);
781 } 809 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698