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