| 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 <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/at_exit.h" | 10 #include "base/at_exit.h" |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 Del* delegate_; | 129 Del* delegate_; |
| 130 Ctx* context_; | 130 Ctx* context_; |
| 131 }; | 131 }; |
| 132 // This function creates the right DelegateWithContext using template inference. | 132 // This function creates the right DelegateWithContext using template inference. |
| 133 template <typename Del, typename Ctx> | 133 template <typename Del, typename Ctx> |
| 134 net::URLFetcherDelegate* MakeContextDelegate(Del* delegate, Ctx* context) { | 134 net::URLFetcherDelegate* MakeContextDelegate(Del* delegate, Ctx* context) { |
| 135 return new DelegateWithContext<Del, Ctx>(delegate, context); | 135 return new DelegateWithContext<Del, Ctx>(delegate, context); |
| 136 } | 136 } |
| 137 | 137 |
| 138 // Helper to start a url request using |fetcher| with the common flags. | 138 // Helper to start a url request using |fetcher| with the common flags. |
| 139 void StartFetch(content::URLFetcher* fetcher, | 139 void StartFetch(net::URLFetcher* fetcher, |
| 140 net::URLRequestContextGetter* context_getter, | 140 net::URLRequestContextGetter* context_getter, |
| 141 bool save_to_file) { | 141 bool save_to_file) { |
| 142 fetcher->SetRequestContext(context_getter); | 142 fetcher->SetRequestContext(context_getter); |
| 143 fetcher->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | | 143 fetcher->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | |
| 144 net::LOAD_DO_NOT_SAVE_COOKIES | | 144 net::LOAD_DO_NOT_SAVE_COOKIES | |
| 145 net::LOAD_DISABLE_CACHE); | 145 net::LOAD_DISABLE_CACHE); |
| 146 // TODO(cpu): Define our retry and backoff policy. | 146 // TODO(cpu): Define our retry and backoff policy. |
| 147 fetcher->SetAutomaticallyRetryOn5xx(false); | 147 fetcher->SetAutomaticallyRetryOn5xx(false); |
| 148 if (save_to_file) { | 148 if (save_to_file) { |
| 149 fetcher->SaveResponseToTemporaryFile( | 149 fetcher->SaveResponseToTemporaryFile( |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 void DoneInstalling(const std::string& component_id, | 318 void DoneInstalling(const std::string& component_id, |
| 319 ComponentUnpacker::Error error); | 319 ComponentUnpacker::Error error); |
| 320 | 320 |
| 321 size_t ChangeItemStatus(CrxUpdateItem::Status from, | 321 size_t ChangeItemStatus(CrxUpdateItem::Status from, |
| 322 CrxUpdateItem::Status to); | 322 CrxUpdateItem::Status to); |
| 323 | 323 |
| 324 CrxUpdateItem* FindUpdateItemById(const std::string& id); | 324 CrxUpdateItem* FindUpdateItemById(const std::string& id); |
| 325 | 325 |
| 326 scoped_ptr<Config> config_; | 326 scoped_ptr<Config> config_; |
| 327 | 327 |
| 328 scoped_ptr<content::URLFetcher> url_fetcher_; | 328 scoped_ptr<net::URLFetcher> url_fetcher_; |
| 329 | 329 |
| 330 typedef std::vector<CrxUpdateItem*> UpdateItems; | 330 typedef std::vector<CrxUpdateItem*> UpdateItems; |
| 331 UpdateItems work_items_; | 331 UpdateItems work_items_; |
| 332 | 332 |
| 333 base::OneShotTimer<CrxUpdateService> timer_; | 333 base::OneShotTimer<CrxUpdateService> timer_; |
| 334 | 334 |
| 335 Version chrome_version_; | 335 Version chrome_version_; |
| 336 | 336 |
| 337 bool running_; | 337 bool running_; |
| 338 | 338 |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 500 CrxUpdateItem* item = *it; | 500 CrxUpdateItem* item = *it; |
| 501 if (item->status != CrxUpdateItem::kCanUpdate) | 501 if (item->status != CrxUpdateItem::kCanUpdate) |
| 502 continue; | 502 continue; |
| 503 // Found component to update, start the process. | 503 // Found component to update, start the process. |
| 504 item->status = CrxUpdateItem::kDownloading; | 504 item->status = CrxUpdateItem::kDownloading; |
| 505 CRXContext* context = new CRXContext; | 505 CRXContext* context = new CRXContext; |
| 506 context->pk_hash = item->component.pk_hash; | 506 context->pk_hash = item->component.pk_hash; |
| 507 context->id = item->id; | 507 context->id = item->id; |
| 508 context->installer = item->component.installer; | 508 context->installer = item->component.installer; |
| 509 url_fetcher_.reset(content::URLFetcher::Create( | 509 url_fetcher_.reset(content::URLFetcher::Create( |
| 510 0, item->crx_url, content::URLFetcher::GET, | 510 0, item->crx_url, net::URLFetcher::GET, |
| 511 MakeContextDelegate(this, context))); | 511 MakeContextDelegate(this, context))); |
| 512 StartFetch(url_fetcher_.get(), config_->RequestContext(), true); | 512 StartFetch(url_fetcher_.get(), config_->RequestContext(), true); |
| 513 return; | 513 return; |
| 514 } | 514 } |
| 515 | 515 |
| 516 std::string query; | 516 std::string query; |
| 517 // If no pending upgrades, we check the if there are new | 517 // If no pending upgrades, we check the if there are new |
| 518 // components we have not checked against the server. We | 518 // components we have not checked against the server. We |
| 519 // can batch a bunch in a single url request. | 519 // can batch a bunch in a single url request. |
| 520 for (UpdateItems::const_iterator it = work_items_.begin(); | 520 for (UpdateItems::const_iterator it = work_items_.begin(); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 561 // Next check after the long sleep. | 561 // Next check after the long sleep. |
| 562 ScheduleNextRun(false); | 562 ScheduleNextRun(false); |
| 563 return; | 563 return; |
| 564 } | 564 } |
| 565 | 565 |
| 566 // We got components to check. Start the url request. | 566 // We got components to check. Start the url request. |
| 567 const std::string full_query = MakeFinalQuery(config_->UpdateUrl().spec(), | 567 const std::string full_query = MakeFinalQuery(config_->UpdateUrl().spec(), |
| 568 query, | 568 query, |
| 569 config_->ExtraRequestParams()); | 569 config_->ExtraRequestParams()); |
| 570 url_fetcher_.reset(content::URLFetcher::Create( | 570 url_fetcher_.reset(content::URLFetcher::Create( |
| 571 0, GURL(full_query), content::URLFetcher::GET, | 571 0, GURL(full_query), net::URLFetcher::GET, |
| 572 MakeContextDelegate(this, new UpdateContext()))); | 572 MakeContextDelegate(this, new UpdateContext()))); |
| 573 StartFetch(url_fetcher_.get(), config_->RequestContext(), false); | 573 StartFetch(url_fetcher_.get(), config_->RequestContext(), false); |
| 574 } | 574 } |
| 575 | 575 |
| 576 // Caled when we got a response from the update server. It consists of an xml | 576 // Caled when we got a response from the update server. It consists of an xml |
| 577 // document following the omaha update scheme. | 577 // document following the omaha update scheme. |
| 578 void CrxUpdateService::OnURLFetchComplete(const net::URLFetcher* source, | 578 void CrxUpdateService::OnURLFetchComplete(const net::URLFetcher* source, |
| 579 UpdateContext* context) { | 579 UpdateContext* context) { |
| 580 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 580 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 581 if (FetchSuccess(*source)) { | 581 if (FetchSuccess(*source)) { |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 769 ScheduleNextRun(false); | 769 ScheduleNextRun(false); |
| 770 } | 770 } |
| 771 | 771 |
| 772 // The component update factory. Using the component updater as a singleton | 772 // The component update factory. Using the component updater as a singleton |
| 773 // is the job of the browser process. | 773 // is the job of the browser process. |
| 774 ComponentUpdateService* ComponentUpdateServiceFactory( | 774 ComponentUpdateService* ComponentUpdateServiceFactory( |
| 775 ComponentUpdateService::Configurator* config) { | 775 ComponentUpdateService::Configurator* config) { |
| 776 DCHECK(config); | 776 DCHECK(config); |
| 777 return new CrxUpdateService(config); | 777 return new CrxUpdateService(config); |
| 778 } | 778 } |
| OLD | NEW |