| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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/callback.h" |
| 13 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
| 14 #include "base/file_util.h" | 15 #include "base/file_util.h" |
| 15 #include "base/files/file_path.h" | 16 #include "base/files/file_path.h" |
| 16 #include "base/logging.h" | 17 #include "base/logging.h" |
| 17 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
| 18 #include "base/message_loop/message_loop_proxy.h" | 19 #include "base/message_loop/message_loop_proxy.h" |
| 19 #include "base/observer_list.h" | 20 #include "base/observer_list.h" |
| 20 #include "base/sequenced_task_runner.h" | 21 #include "base/sequenced_task_runner.h" |
| 21 #include "base/stl_util.h" | 22 #include "base/stl_util.h" |
| 22 #include "base/threading/sequenced_worker_pool.h" | 23 #include "base/threading/sequenced_worker_pool.h" |
| 23 #include "base/threading/thread_checker.h" | 24 #include "base/threading/thread_checker.h" |
| 24 #include "base/timer/timer.h" | 25 #include "base/timer/timer.h" |
| 25 #include "chrome/browser/browser_process.h" | |
| 26 #include "chrome/browser/component_updater/component_unpacker.h" | 26 #include "chrome/browser/component_updater/component_unpacker.h" |
| 27 #include "chrome/browser/component_updater/component_updater_configurator.h" | 27 #include "chrome/browser/component_updater/component_updater_configurator.h" |
| 28 #include "chrome/browser/component_updater/component_updater_ping_manager.h" | 28 #include "chrome/browser/component_updater/component_updater_ping_manager.h" |
| 29 #include "chrome/browser/component_updater/component_updater_utils.h" | 29 #include "chrome/browser/component_updater/component_updater_utils.h" |
| 30 #include "chrome/browser/component_updater/crx_downloader.h" | 30 #include "chrome/browser/component_updater/crx_downloader.h" |
| 31 #include "chrome/browser/component_updater/crx_update_item.h" | 31 #include "chrome/browser/component_updater/crx_update_item.h" |
| 32 #include "chrome/browser/component_updater/update_checker.h" | 32 #include "chrome/browser/component_updater/update_checker.h" |
| 33 #include "chrome/browser/component_updater/update_response.h" | 33 #include "chrome/browser/component_updater/update_response.h" |
| 34 #include "content/public/browser/browser_thread.h" | |
| 35 #include "content/public/browser/resource_controller.h" | |
| 36 #include "content/public/browser/resource_throttle.h" | |
| 37 #include "url/gurl.h" | 34 #include "url/gurl.h" |
| 38 | 35 |
| 39 using content::BrowserThread; | |
| 40 | |
| 41 namespace component_updater { | 36 namespace component_updater { |
| 42 | 37 |
| 43 // The component updater is designed to live until process shutdown, so | 38 // The component updater is designed to live until process shutdown, so |
| 44 // base::Bind() calls are not refcounted. | 39 // base::Bind() calls are not refcounted. |
| 45 | 40 |
| 46 namespace { | 41 namespace { |
| 47 | 42 |
| 48 // Returns true if the |proposed| version is newer than |current| version. | 43 // Returns true if the |proposed| version is newer than |current| version. |
| 49 bool IsVersionNewer(const Version& current, const std::string& proposed) { | 44 bool IsVersionNewer(const Version& current, const std::string& proposed) { |
| 50 Version proposed_ver(proposed); | 45 Version proposed_ver(proposed); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 CrxUpdateItem::~CrxUpdateItem() { | 77 CrxUpdateItem::~CrxUpdateItem() { |
| 83 } | 78 } |
| 84 | 79 |
| 85 CrxComponent::CrxComponent() | 80 CrxComponent::CrxComponent() |
| 86 : installer(NULL), allow_background_download(true) { | 81 : installer(NULL), allow_background_download(true) { |
| 87 } | 82 } |
| 88 | 83 |
| 89 CrxComponent::~CrxComponent() { | 84 CrxComponent::~CrxComponent() { |
| 90 } | 85 } |
| 91 | 86 |
| 92 /////////////////////////////////////////////////////////////////////////////// | |
| 93 // In charge of blocking url requests until the |crx_id| component has been | |
| 94 // updated. This class is touched solely from the IO thread. The UI thread | |
| 95 // can post tasks to it via weak pointers. By default the request is blocked | |
| 96 // unless the CrxUpdateService calls Unblock(). | |
| 97 // The lifetime is controlled by Chrome's resource loader so the component | |
| 98 // updater cannot touch objects from this class except via weak pointers. | |
| 99 class CUResourceThrottle : public content::ResourceThrottle, | |
| 100 public base::SupportsWeakPtr<CUResourceThrottle> { | |
| 101 public: | |
| 102 explicit CUResourceThrottle(const net::URLRequest* request); | |
| 103 virtual ~CUResourceThrottle(); | |
| 104 | |
| 105 // Overriden from ResourceThrottle. | |
| 106 virtual void WillStartRequest(bool* defer) OVERRIDE; | |
| 107 virtual void WillRedirectRequest(const GURL& new_url, bool* defer) OVERRIDE; | |
| 108 virtual const char* GetNameForLogging() const OVERRIDE; | |
| 109 | |
| 110 // Component updater calls this function via PostTask to unblock the request. | |
| 111 void Unblock(); | |
| 112 | |
| 113 typedef std::vector<base::WeakPtr<CUResourceThrottle> > WeakPtrVector; | |
| 114 | |
| 115 private: | |
| 116 enum State { NEW, BLOCKED, UNBLOCKED }; | |
| 117 | |
| 118 State state_; | |
| 119 }; | |
| 120 | |
| 121 void UnblockResourceThrottle(base::WeakPtr<CUResourceThrottle> rt) { | |
| 122 BrowserThread::PostTask(BrowserThread::IO, | |
| 123 FROM_HERE, | |
| 124 base::Bind(&CUResourceThrottle::Unblock, rt)); | |
| 125 } | |
| 126 | |
| 127 void UnblockandReapAllThrottles(CUResourceThrottle::WeakPtrVector* throttles) { | |
| 128 CUResourceThrottle::WeakPtrVector::iterator it; | |
| 129 for (it = throttles->begin(); it != throttles->end(); ++it) | |
| 130 UnblockResourceThrottle(*it); | |
| 131 throttles->clear(); | |
| 132 } | |
| 133 | |
| 134 ////////////////////////////////////////////////////////////////////////////// | 87 ////////////////////////////////////////////////////////////////////////////// |
| 135 // The one and only implementation of the ComponentUpdateService interface. In | 88 // The one and only implementation of the ComponentUpdateService interface. In |
| 136 // charge of running the show. The main method is ProcessPendingItems() which | 89 // charge of running the show. The main method is ProcessPendingItems() which |
| 137 // is called periodically to do the upgrades/installs or the update checks. | 90 // is called periodically to do the upgrades/installs or the update checks. |
| 138 // An important consideration here is to be as "low impact" as we can to the | 91 // An important consideration here is to be as "low impact" as we can to the |
| 139 // rest of the browser, so even if we have many components registered and | 92 // rest of the browser, so even if we have many components registered and |
| 140 // eligible for update, we only do one thing at a time with pauses in between | 93 // eligible for update, we only do one thing at a time with pauses in between |
| 141 // the tasks. Also when we do network requests there is only one |url_fetcher_| | 94 // the tasks. Also when we do network requests there is only one |url_fetcher_| |
| 142 // in flight at a time. | 95 // in flight at a time. |
| 143 // There are no locks in this code, the main structure |work_items_| is mutated | 96 // There are no locks in this code, the main structure |work_items_| is mutated |
| 144 // only from the main thread. The unpack and installation is done in a blocking | 97 // only from the main thread. The unpack and installation is done in a blocking |
| 145 // pool thread. The network requests are done in the IO thread or in the file | 98 // pool thread. The network requests are done in the IO thread or in the file |
| 146 // thread. | 99 // thread. |
| 147 class CrxUpdateService : public ComponentUpdateService, public OnDemandUpdater { | 100 class CrxUpdateService : public ComponentUpdateService, public OnDemandUpdater { |
| 148 public: | 101 public: |
| 149 explicit CrxUpdateService(Configurator* config); | 102 explicit CrxUpdateService(Configurator* config); |
| 150 virtual ~CrxUpdateService(); | 103 virtual ~CrxUpdateService(); |
| 151 | 104 |
| 152 // Overrides for ComponentUpdateService. | 105 // Overrides for ComponentUpdateService. |
| 153 virtual void AddObserver(Observer* observer) OVERRIDE; | 106 virtual void AddObserver(Observer* observer) OVERRIDE; |
| 154 virtual void RemoveObserver(Observer* observer) OVERRIDE; | 107 virtual void RemoveObserver(Observer* observer) OVERRIDE; |
| 155 virtual Status Start() OVERRIDE; | 108 virtual Status Start() OVERRIDE; |
| 156 virtual Status Stop() OVERRIDE; | 109 virtual Status Stop() OVERRIDE; |
| 157 virtual Status RegisterComponent(const CrxComponent& component) OVERRIDE; | 110 virtual Status RegisterComponent(const CrxComponent& component) OVERRIDE; |
| 158 virtual std::vector<std::string> GetComponentIDs() const OVERRIDE; | 111 virtual std::vector<std::string> GetComponentIDs() const OVERRIDE; |
| 159 virtual bool GetComponentDetails(const std::string& component_id, | |
| 160 CrxUpdateItem* item) const OVERRIDE; | |
| 161 virtual OnDemandUpdater& GetOnDemandUpdater() OVERRIDE; | 112 virtual OnDemandUpdater& GetOnDemandUpdater() OVERRIDE; |
| 113 virtual void MaybeThrottle(const std::string& crx_id, |
| 114 const base::Closure& callback) OVERRIDE; |
| 162 virtual scoped_refptr<base::SequencedTaskRunner> GetSequencedTaskRunner() | 115 virtual scoped_refptr<base::SequencedTaskRunner> GetSequencedTaskRunner() |
| 163 OVERRIDE; | 116 OVERRIDE; |
| 164 | 117 |
| 165 // Overrides for OnDemandUpdater. | |
| 166 virtual content::ResourceThrottle* GetOnDemandResourceThrottle( | |
| 167 net::URLRequest* request, | |
| 168 const std::string& crx_id) OVERRIDE; | |
| 169 virtual Status OnDemandUpdate(const std::string& component_id) OVERRIDE; | |
| 170 | |
| 171 // Context for a crx download url request. | 118 // Context for a crx download url request. |
| 172 struct CRXContext { | 119 struct CRXContext { |
| 173 ComponentInstaller* installer; | 120 ComponentInstaller* installer; |
| 174 std::vector<uint8> pk_hash; | 121 std::vector<uint8> pk_hash; |
| 175 std::string id; | 122 std::string id; |
| 176 std::string fingerprint; | 123 std::string fingerprint; |
| 177 CRXContext() : installer(NULL) {} | 124 CRXContext() : installer(NULL) {} |
| 178 }; | 125 }; |
| 179 | 126 |
| 180 private: | 127 private: |
| 181 enum ErrorCategory { | 128 enum ErrorCategory { |
| 182 kErrorNone = 0, | 129 kErrorNone = 0, |
| 183 kNetworkError, | 130 kNetworkError, |
| 184 kUnpackError, | 131 kUnpackError, |
| 185 kInstallError, | 132 kInstallError, |
| 186 }; | 133 }; |
| 187 | 134 |
| 188 enum StepDelayInterval { | 135 enum StepDelayInterval { |
| 189 kStepDelayShort = 0, | 136 kStepDelayShort = 0, |
| 190 kStepDelayMedium, | 137 kStepDelayMedium, |
| 191 kStepDelayLong, | 138 kStepDelayLong, |
| 192 }; | 139 }; |
| 193 | 140 |
| 141 // Overrides for ComponentUpdateService. |
| 142 virtual bool GetComponentDetails(const std::string& component_id, |
| 143 CrxUpdateItem* item) const OVERRIDE; |
| 144 |
| 145 // Overrides for OnDemandUpdater. |
| 146 virtual Status OnDemandUpdate(const std::string& component_id) OVERRIDE; |
| 147 |
| 194 void UpdateCheckComplete(int error, | 148 void UpdateCheckComplete(int error, |
| 195 const std::string& error_message, | 149 const std::string& error_message, |
| 196 const UpdateResponse::Results& results); | 150 const UpdateResponse::Results& results); |
| 197 void OnUpdateCheckSucceeded(const UpdateResponse::Results& results); | 151 void OnUpdateCheckSucceeded(const UpdateResponse::Results& results); |
| 198 void OnUpdateCheckFailed(int error, const std::string& error_message); | 152 void OnUpdateCheckFailed(int error, const std::string& error_message); |
| 199 | 153 |
| 200 void DownloadProgress(const std::string& component_id, | 154 void DownloadProgress(const std::string& component_id, |
| 201 const CrxDownloader::Result& download_result); | 155 const CrxDownloader::Result& download_result); |
| 202 | 156 |
| 203 void DownloadComplete(scoped_ptr<CRXContext> crx_context, | 157 void DownloadComplete(scoped_ptr<CRXContext> crx_context, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 void ChangeItemState(CrxUpdateItem* item, CrxUpdateItem::Status to); | 190 void ChangeItemState(CrxUpdateItem* item, CrxUpdateItem::Status to); |
| 237 | 191 |
| 238 size_t ChangeItemStatus(CrxUpdateItem::Status from, CrxUpdateItem::Status to); | 192 size_t ChangeItemStatus(CrxUpdateItem::Status from, CrxUpdateItem::Status to); |
| 239 | 193 |
| 240 CrxUpdateItem* FindUpdateItemById(const std::string& id) const; | 194 CrxUpdateItem* FindUpdateItemById(const std::string& id) const; |
| 241 | 195 |
| 242 void NotifyObservers(Observer::Events event, const std::string& id); | 196 void NotifyObservers(Observer::Events event, const std::string& id); |
| 243 | 197 |
| 244 bool HasOnDemandItems() const; | 198 bool HasOnDemandItems() const; |
| 245 | 199 |
| 246 void OnNewResourceThrottle(base::WeakPtr<CUResourceThrottle> rt, | |
| 247 const std::string& crx_id); | |
| 248 | |
| 249 Status GetServiceStatus(const CrxUpdateItem::Status status); | 200 Status GetServiceStatus(const CrxUpdateItem::Status status); |
| 250 | 201 |
| 251 scoped_ptr<Configurator> config_; | 202 scoped_ptr<Configurator> config_; |
| 252 | 203 |
| 253 scoped_ptr<UpdateChecker> update_checker_; | 204 scoped_ptr<UpdateChecker> update_checker_; |
| 254 | 205 |
| 255 scoped_ptr<PingManager> ping_manager_; | 206 scoped_ptr<PingManager> ping_manager_; |
| 256 | 207 |
| 257 scoped_refptr<ComponentUnpacker> unpacker_; | 208 scoped_refptr<ComponentUnpacker> unpacker_; |
| 258 | 209 |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 441 case CrxUpdateItem::kDownloading: | 392 case CrxUpdateItem::kDownloading: |
| 442 case CrxUpdateItem::kDownloadingDiff: | 393 case CrxUpdateItem::kDownloadingDiff: |
| 443 case CrxUpdateItem::kLastStatus: | 394 case CrxUpdateItem::kLastStatus: |
| 444 // No notification for these states. | 395 // No notification for these states. |
| 445 break; | 396 break; |
| 446 } | 397 } |
| 447 | 398 |
| 448 // Free possible pending network requests. | 399 // Free possible pending network requests. |
| 449 if ((to == CrxUpdateItem::kUpdated) || (to == CrxUpdateItem::kUpToDate) || | 400 if ((to == CrxUpdateItem::kUpdated) || (to == CrxUpdateItem::kUpToDate) || |
| 450 (to == CrxUpdateItem::kNoUpdate)) { | 401 (to == CrxUpdateItem::kNoUpdate)) { |
| 451 UnblockandReapAllThrottles(&item->throttles); | 402 for (std::vector<base::Closure>::iterator it = |
| 403 item->ready_callbacks.begin(); |
| 404 it != item->ready_callbacks.end(); |
| 405 ++it) { |
| 406 it->Run(); |
| 407 } |
| 408 item->ready_callbacks.clear(); |
| 452 } | 409 } |
| 453 } | 410 } |
| 454 | 411 |
| 455 // Changes all the components in |work_items_| that have |from| status to | 412 // Changes all the components in |work_items_| that have |from| status to |
| 456 // |to| status and returns how many have been changed. | 413 // |to| status and returns how many have been changed. |
| 457 size_t CrxUpdateService::ChangeItemStatus(CrxUpdateItem::Status from, | 414 size_t CrxUpdateService::ChangeItemStatus(CrxUpdateItem::Status from, |
| 458 CrxUpdateItem::Status to) { | 415 CrxUpdateItem::Status to) { |
| 459 DCHECK(thread_checker_.CalledOnValidThread()); | 416 DCHECK(thread_checker_.CalledOnValidThread()); |
| 460 size_t count = 0; | 417 size_t count = 0; |
| 461 for (UpdateItems::iterator it = work_items_.begin(); | 418 for (UpdateItems::iterator it = work_items_.begin(); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 517 std::vector<std::string> component_ids; | 474 std::vector<std::string> component_ids; |
| 518 for (UpdateItems::const_iterator it = work_items_.begin(); | 475 for (UpdateItems::const_iterator it = work_items_.begin(); |
| 519 it != work_items_.end(); | 476 it != work_items_.end(); |
| 520 ++it) { | 477 ++it) { |
| 521 const CrxUpdateItem* item = *it; | 478 const CrxUpdateItem* item = *it; |
| 522 component_ids.push_back(item->id); | 479 component_ids.push_back(item->id); |
| 523 } | 480 } |
| 524 return component_ids; | 481 return component_ids; |
| 525 } | 482 } |
| 526 | 483 |
| 484 OnDemandUpdater& CrxUpdateService::GetOnDemandUpdater() { |
| 485 return *this; |
| 486 } |
| 487 |
| 488 void CrxUpdateService::MaybeThrottle(const std::string& crx_id, |
| 489 const base::Closure& callback) { |
| 490 DCHECK(thread_checker_.CalledOnValidThread()); |
| 491 // Check if we can on-demand update, else unblock the request anyway. |
| 492 CrxUpdateItem* item = FindUpdateItemById(crx_id); |
| 493 Status status = OnDemandUpdateWithCooldown(item); |
| 494 if (status == kOk || status == kInProgress) { |
| 495 item->ready_callbacks.push_back(callback); |
| 496 return; |
| 497 } |
| 498 callback.Run(); |
| 499 } |
| 500 |
| 501 scoped_refptr<base::SequencedTaskRunner> |
| 502 CrxUpdateService::GetSequencedTaskRunner() { |
| 503 return config_->GetSequencedTaskRunner(); |
| 504 } |
| 505 |
| 527 bool CrxUpdateService::GetComponentDetails(const std::string& component_id, | 506 bool CrxUpdateService::GetComponentDetails(const std::string& component_id, |
| 528 CrxUpdateItem* item) const { | 507 CrxUpdateItem* item) const { |
| 529 DCHECK(thread_checker_.CalledOnValidThread()); | 508 DCHECK(thread_checker_.CalledOnValidThread()); |
| 530 const CrxUpdateItem* crx_update_item(FindUpdateItemById(component_id)); | 509 const CrxUpdateItem* crx_update_item(FindUpdateItemById(component_id)); |
| 531 if (crx_update_item) | 510 if (crx_update_item) |
| 532 *item = *crx_update_item; | 511 *item = *crx_update_item; |
| 533 return crx_update_item != NULL; | 512 return crx_update_item != NULL; |
| 534 } | 513 } |
| 535 | 514 |
| 536 OnDemandUpdater& CrxUpdateService::GetOnDemandUpdater() { | 515 // Start the process of checking for an update, for a particular component |
| 537 return *this; | 516 // that was previously registered. |
| 538 } | 517 // |component_id| is a value returned from GetCrxComponentID(). |
| 539 | 518 ComponentUpdateService::Status CrxUpdateService::OnDemandUpdate( |
| 540 scoped_refptr<base::SequencedTaskRunner> | 519 const std::string& component_id) { |
| 541 CrxUpdateService::GetSequencedTaskRunner() { | 520 return OnDemandUpdateInternal(FindUpdateItemById(component_id)); |
| 542 return config_->GetSequencedTaskRunner(); | |
| 543 } | 521 } |
| 544 | 522 |
| 545 // This is the main loop of the component updater. It updates one component | 523 // This is the main loop of the component updater. It updates one component |
| 546 // at a time if updates are available. Otherwise, it does an update check or | 524 // at a time if updates are available. Otherwise, it does an update check or |
| 547 // takes a long sleep until the loop runs again. | 525 // takes a long sleep until the loop runs again. |
| 548 void CrxUpdateService::ProcessPendingItems() { | 526 void CrxUpdateService::ProcessPendingItems() { |
| 549 DCHECK(thread_checker_.CalledOnValidThread()); | 527 DCHECK(thread_checker_.CalledOnValidThread()); |
| 550 | 528 |
| 551 CrxUpdateItem* ready_upgrade = FindReadyComponent(); | 529 CrxUpdateItem* ready_upgrade = FindReadyComponent(); |
| 552 if (ready_upgrade) { | 530 if (ready_upgrade) { |
| (...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 951 // Move on to the next update, if there is one available. | 929 // Move on to the next update, if there is one available. |
| 952 ScheduleNextRun(kStepDelayMedium); | 930 ScheduleNextRun(kStepDelayMedium); |
| 953 } | 931 } |
| 954 | 932 |
| 955 void CrxUpdateService::NotifyObservers(Observer::Events event, | 933 void CrxUpdateService::NotifyObservers(Observer::Events event, |
| 956 const std::string& id) { | 934 const std::string& id) { |
| 957 DCHECK(thread_checker_.CalledOnValidThread()); | 935 DCHECK(thread_checker_.CalledOnValidThread()); |
| 958 FOR_EACH_OBSERVER(Observer, observer_list_, OnEvent(event, id)); | 936 FOR_EACH_OBSERVER(Observer, observer_list_, OnEvent(event, id)); |
| 959 } | 937 } |
| 960 | 938 |
| 961 content::ResourceThrottle* CrxUpdateService::GetOnDemandResourceThrottle( | |
| 962 net::URLRequest* request, | |
| 963 const std::string& crx_id) { | |
| 964 // We give the raw pointer to the caller, who will delete it at will | |
| 965 // and we keep for ourselves a weak pointer to it so we can post tasks | |
| 966 // from the UI thread without having to track lifetime directly. | |
| 967 CUResourceThrottle* rt = new CUResourceThrottle(request); | |
| 968 main_task_runner_->PostTask( | |
| 969 FROM_HERE, | |
| 970 base::Bind(&CrxUpdateService::OnNewResourceThrottle, | |
| 971 base::Unretained(this), rt->AsWeakPtr(), crx_id)); | |
| 972 return rt; | |
| 973 } | |
| 974 | |
| 975 void CrxUpdateService::OnNewResourceThrottle( | |
| 976 base::WeakPtr<CUResourceThrottle> rt, | |
| 977 const std::string& crx_id) { | |
| 978 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 979 // Check if we can on-demand update, else unblock the request anyway. | |
| 980 CrxUpdateItem* item = FindUpdateItemById(crx_id); | |
| 981 Status status = OnDemandUpdateWithCooldown(item); | |
| 982 if (status == kOk || status == kInProgress) { | |
| 983 item->throttles.push_back(rt); | |
| 984 return; | |
| 985 } | |
| 986 UnblockResourceThrottle(rt); | |
| 987 } | |
| 988 | |
| 989 // Start the process of checking for an update, for a particular component | |
| 990 // that was previously registered. | |
| 991 // |component_id| is a value returned from GetCrxComponentID(). | |
| 992 ComponentUpdateService::Status CrxUpdateService::OnDemandUpdate( | |
| 993 const std::string& component_id) { | |
| 994 return OnDemandUpdateInternal(FindUpdateItemById(component_id)); | |
| 995 } | |
| 996 | |
| 997 ComponentUpdateService::Status CrxUpdateService::OnDemandUpdateWithCooldown( | 939 ComponentUpdateService::Status CrxUpdateService::OnDemandUpdateWithCooldown( |
| 998 CrxUpdateItem* uit) { | 940 CrxUpdateItem* uit) { |
| 999 if (!uit) | 941 if (!uit) |
| 1000 return kError; | 942 return kError; |
| 1001 | 943 |
| 1002 // Check if the request is too soon. | 944 // Check if the request is too soon. |
| 1003 base::TimeDelta delta = base::Time::Now() - uit->last_check; | 945 base::TimeDelta delta = base::Time::Now() - uit->last_check; |
| 1004 if (delta < base::TimeDelta::FromSeconds(config_->OnDemandDelay())) | 946 if (delta < base::TimeDelta::FromSeconds(config_->OnDemandDelay())) |
| 1005 return kError; | 947 return kError; |
| 1006 | 948 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1058 case CrxUpdateItem::kNoUpdate: | 1000 case CrxUpdateItem::kNoUpdate: |
| 1059 return kOk; | 1001 return kOk; |
| 1060 case CrxUpdateItem::kLastStatus: | 1002 case CrxUpdateItem::kLastStatus: |
| 1061 NOTREACHED() << status; | 1003 NOTREACHED() << status; |
| 1062 } | 1004 } |
| 1063 return kError; | 1005 return kError; |
| 1064 } | 1006 } |
| 1065 | 1007 |
| 1066 /////////////////////////////////////////////////////////////////////////////// | 1008 /////////////////////////////////////////////////////////////////////////////// |
| 1067 | 1009 |
| 1068 CUResourceThrottle::CUResourceThrottle(const net::URLRequest* request) | |
| 1069 : state_(NEW) { | |
| 1070 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
| 1071 } | |
| 1072 | |
| 1073 CUResourceThrottle::~CUResourceThrottle() { | |
| 1074 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
| 1075 } | |
| 1076 | |
| 1077 void CUResourceThrottle::WillStartRequest(bool* defer) { | |
| 1078 if (state_ != UNBLOCKED) { | |
| 1079 state_ = BLOCKED; | |
| 1080 *defer = true; | |
| 1081 } else { | |
| 1082 *defer = false; | |
| 1083 } | |
| 1084 } | |
| 1085 | |
| 1086 void CUResourceThrottle::WillRedirectRequest(const GURL& new_url, bool* defer) { | |
| 1087 WillStartRequest(defer); | |
| 1088 } | |
| 1089 | |
| 1090 const char* CUResourceThrottle::GetNameForLogging() const { | |
| 1091 return "ComponentUpdateResourceThrottle"; | |
| 1092 } | |
| 1093 | |
| 1094 void CUResourceThrottle::Unblock() { | |
| 1095 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
| 1096 if (state_ == BLOCKED) | |
| 1097 controller()->Resume(); | |
| 1098 state_ = UNBLOCKED; | |
| 1099 } | |
| 1100 | |
| 1101 // The component update factory. Using the component updater as a singleton | 1010 // The component update factory. Using the component updater as a singleton |
| 1102 // is the job of the browser process. | 1011 // is the job of the browser process. |
| 1103 ComponentUpdateService* ComponentUpdateServiceFactory(Configurator* config) { | 1012 ComponentUpdateService* ComponentUpdateServiceFactory(Configurator* config) { |
| 1104 DCHECK(config); | 1013 DCHECK(config); |
| 1105 return new CrxUpdateService(config); | 1014 return new CrxUpdateService(config); |
| 1106 } | 1015 } |
| 1107 | 1016 |
| 1108 } // namespace component_updater | 1017 } // namespace component_updater |
| OLD | NEW |