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 { |
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, | 112 virtual bool GetComponentDetails(const std::string& component_id, |
160 CrxUpdateItem* item) const OVERRIDE; | 113 CrxUpdateItem* item) const OVERRIDE; |
161 virtual OnDemandUpdater& GetOnDemandUpdater() OVERRIDE; | |
162 virtual scoped_refptr<base::SequencedTaskRunner> GetSequencedTaskRunner() | 114 virtual scoped_refptr<base::SequencedTaskRunner> GetSequencedTaskRunner() |
163 OVERRIDE; | 115 OVERRIDE; |
164 | 116 |
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. | 117 // Context for a crx download url request. |
172 struct CRXContext { | 118 struct CRXContext { |
173 ComponentInstaller* installer; | 119 ComponentInstaller* installer; |
174 std::vector<uint8> pk_hash; | 120 std::vector<uint8> pk_hash; |
175 std::string id; | 121 std::string id; |
176 std::string fingerprint; | 122 std::string fingerprint; |
177 CRXContext() : installer(NULL) {} | 123 CRXContext() : installer(NULL) {} |
178 }; | 124 }; |
179 | 125 |
180 private: | 126 private: |
181 enum ErrorCategory { | 127 enum ErrorCategory { |
182 kErrorNone = 0, | 128 kErrorNone = 0, |
183 kNetworkError, | 129 kNetworkError, |
184 kUnpackError, | 130 kUnpackError, |
185 kInstallError, | 131 kInstallError, |
186 }; | 132 }; |
187 | 133 |
188 enum StepDelayInterval { | 134 enum StepDelayInterval { |
189 kStepDelayShort = 0, | 135 kStepDelayShort = 0, |
190 kStepDelayMedium, | 136 kStepDelayMedium, |
191 kStepDelayLong, | 137 kStepDelayLong, |
192 }; | 138 }; |
193 | 139 |
| 140 // Overrides for ComponentUpdateService. |
| 141 virtual void MaybeThrottle(const std::string& crx_id, |
| 142 const base::Closure& callback) OVERRIDE; |
| 143 virtual ComponentUpdateService::Status OnDemandUpdate( |
| 144 const std::string& component_id) OVERRIDE; |
| 145 |
194 void UpdateCheckComplete(int error, | 146 void UpdateCheckComplete(int error, |
195 const std::string& error_message, | 147 const std::string& error_message, |
196 const UpdateResponse::Results& results); | 148 const UpdateResponse::Results& results); |
197 void OnUpdateCheckSucceeded(const UpdateResponse::Results& results); | 149 void OnUpdateCheckSucceeded(const UpdateResponse::Results& results); |
198 void OnUpdateCheckFailed(int error, const std::string& error_message); | 150 void OnUpdateCheckFailed(int error, const std::string& error_message); |
199 | 151 |
200 void DownloadProgress(const std::string& component_id, | 152 void DownloadProgress(const std::string& component_id, |
201 const CrxDownloader::Result& download_result); | 153 const CrxDownloader::Result& download_result); |
202 | 154 |
203 void DownloadComplete(scoped_ptr<CRXContext> crx_context, | 155 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); | 188 void ChangeItemState(CrxUpdateItem* item, CrxUpdateItem::Status to); |
237 | 189 |
238 size_t ChangeItemStatus(CrxUpdateItem::Status from, CrxUpdateItem::Status to); | 190 size_t ChangeItemStatus(CrxUpdateItem::Status from, CrxUpdateItem::Status to); |
239 | 191 |
240 CrxUpdateItem* FindUpdateItemById(const std::string& id) const; | 192 CrxUpdateItem* FindUpdateItemById(const std::string& id) const; |
241 | 193 |
242 void NotifyObservers(Observer::Events event, const std::string& id); | 194 void NotifyObservers(Observer::Events event, const std::string& id); |
243 | 195 |
244 bool HasOnDemandItems() const; | 196 bool HasOnDemandItems() const; |
245 | 197 |
246 void OnNewResourceThrottle(base::WeakPtr<CUResourceThrottle> rt, | |
247 const std::string& crx_id); | |
248 | |
249 Status GetServiceStatus(const CrxUpdateItem::Status status); | 198 Status GetServiceStatus(const CrxUpdateItem::Status status); |
250 | 199 |
251 scoped_ptr<Configurator> config_; | 200 scoped_ptr<Configurator> config_; |
252 | 201 |
253 scoped_ptr<UpdateChecker> update_checker_; | 202 scoped_ptr<UpdateChecker> update_checker_; |
254 | 203 |
255 scoped_ptr<PingManager> ping_manager_; | 204 scoped_ptr<PingManager> ping_manager_; |
256 | 205 |
257 scoped_refptr<ComponentUnpacker> unpacker_; | 206 scoped_refptr<ComponentUnpacker> unpacker_; |
258 | 207 |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 case CrxUpdateItem::kDownloading: | 390 case CrxUpdateItem::kDownloading: |
442 case CrxUpdateItem::kDownloadingDiff: | 391 case CrxUpdateItem::kDownloadingDiff: |
443 case CrxUpdateItem::kLastStatus: | 392 case CrxUpdateItem::kLastStatus: |
444 // No notification for these states. | 393 // No notification for these states. |
445 break; | 394 break; |
446 } | 395 } |
447 | 396 |
448 // Free possible pending network requests. | 397 // Free possible pending network requests. |
449 if ((to == CrxUpdateItem::kUpdated) || (to == CrxUpdateItem::kUpToDate) || | 398 if ((to == CrxUpdateItem::kUpdated) || (to == CrxUpdateItem::kUpToDate) || |
450 (to == CrxUpdateItem::kNoUpdate)) { | 399 (to == CrxUpdateItem::kNoUpdate)) { |
451 UnblockandReapAllThrottles(&item->throttles); | 400 for (std::vector<base::Closure>::iterator it = |
| 401 item->ready_callbacks.begin(); |
| 402 it != item->ready_callbacks.end(); |
| 403 ++it) { |
| 404 it->Run(); |
| 405 } |
| 406 item->ready_callbacks.clear(); |
452 } | 407 } |
453 } | 408 } |
454 | 409 |
455 // Changes all the components in |work_items_| that have |from| status to | 410 // Changes all the components in |work_items_| that have |from| status to |
456 // |to| status and returns how many have been changed. | 411 // |to| status and returns how many have been changed. |
457 size_t CrxUpdateService::ChangeItemStatus(CrxUpdateItem::Status from, | 412 size_t CrxUpdateService::ChangeItemStatus(CrxUpdateItem::Status from, |
458 CrxUpdateItem::Status to) { | 413 CrxUpdateItem::Status to) { |
459 DCHECK(thread_checker_.CalledOnValidThread()); | 414 DCHECK(thread_checker_.CalledOnValidThread()); |
460 size_t count = 0; | 415 size_t count = 0; |
461 for (UpdateItems::iterator it = work_items_.begin(); | 416 for (UpdateItems::iterator it = work_items_.begin(); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
526 | 481 |
527 bool CrxUpdateService::GetComponentDetails(const std::string& component_id, | 482 bool CrxUpdateService::GetComponentDetails(const std::string& component_id, |
528 CrxUpdateItem* item) const { | 483 CrxUpdateItem* item) const { |
529 DCHECK(thread_checker_.CalledOnValidThread()); | 484 DCHECK(thread_checker_.CalledOnValidThread()); |
530 const CrxUpdateItem* crx_update_item(FindUpdateItemById(component_id)); | 485 const CrxUpdateItem* crx_update_item(FindUpdateItemById(component_id)); |
531 if (crx_update_item) | 486 if (crx_update_item) |
532 *item = *crx_update_item; | 487 *item = *crx_update_item; |
533 return crx_update_item != NULL; | 488 return crx_update_item != NULL; |
534 } | 489 } |
535 | 490 |
536 OnDemandUpdater& CrxUpdateService::GetOnDemandUpdater() { | |
537 return *this; | |
538 } | |
539 | |
540 scoped_refptr<base::SequencedTaskRunner> | 491 scoped_refptr<base::SequencedTaskRunner> |
541 CrxUpdateService::GetSequencedTaskRunner() { | 492 CrxUpdateService::GetSequencedTaskRunner() { |
542 return config_->GetSequencedTaskRunner(); | 493 return config_->GetSequencedTaskRunner(); |
543 } | 494 } |
544 | 495 |
| 496 void CrxUpdateService::MaybeThrottle(const std::string& crx_id, |
| 497 const base::Closure& callback) { |
| 498 DCHECK(thread_checker_.CalledOnValidThread()); |
| 499 // Check if we can on-demand update, else unblock the request anyway. |
| 500 CrxUpdateItem* item = FindUpdateItemById(crx_id); |
| 501 Status status = OnDemandUpdateWithCooldown(item); |
| 502 if (status == kOk || status == kInProgress) { |
| 503 item->ready_callbacks.push_back(callback); |
| 504 return; |
| 505 } |
| 506 callback.Run(); |
| 507 } |
| 508 |
| 509 // Start the process of checking for an update, for a particular component |
| 510 // that was previously registered. |
| 511 // |component_id| is a value returned from GetCrxComponentID(). |
| 512 ComponentUpdateService::Status CrxUpdateService::OnDemandUpdate( |
| 513 const std::string& component_id) { |
| 514 return OnDemandUpdateInternal(FindUpdateItemById(component_id)); |
| 515 } |
| 516 |
545 // This is the main loop of the component updater. It updates one component | 517 // 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 | 518 // at a time if updates are available. Otherwise, it does an update check or |
547 // takes a long sleep until the loop runs again. | 519 // takes a long sleep until the loop runs again. |
548 void CrxUpdateService::ProcessPendingItems() { | 520 void CrxUpdateService::ProcessPendingItems() { |
549 DCHECK(thread_checker_.CalledOnValidThread()); | 521 DCHECK(thread_checker_.CalledOnValidThread()); |
550 | 522 |
551 CrxUpdateItem* ready_upgrade = FindReadyComponent(); | 523 CrxUpdateItem* ready_upgrade = FindReadyComponent(); |
552 if (ready_upgrade) { | 524 if (ready_upgrade) { |
553 UpdateComponent(ready_upgrade); | 525 UpdateComponent(ready_upgrade); |
554 return; | 526 return; |
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
951 // Move on to the next update, if there is one available. | 923 // Move on to the next update, if there is one available. |
952 ScheduleNextRun(kStepDelayMedium); | 924 ScheduleNextRun(kStepDelayMedium); |
953 } | 925 } |
954 | 926 |
955 void CrxUpdateService::NotifyObservers(Observer::Events event, | 927 void CrxUpdateService::NotifyObservers(Observer::Events event, |
956 const std::string& id) { | 928 const std::string& id) { |
957 DCHECK(thread_checker_.CalledOnValidThread()); | 929 DCHECK(thread_checker_.CalledOnValidThread()); |
958 FOR_EACH_OBSERVER(Observer, observer_list_, OnEvent(event, id)); | 930 FOR_EACH_OBSERVER(Observer, observer_list_, OnEvent(event, id)); |
959 } | 931 } |
960 | 932 |
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( | 933 ComponentUpdateService::Status CrxUpdateService::OnDemandUpdateWithCooldown( |
998 CrxUpdateItem* uit) { | 934 CrxUpdateItem* uit) { |
999 if (!uit) | 935 if (!uit) |
1000 return kError; | 936 return kError; |
1001 | 937 |
1002 // Check if the request is too soon. | 938 // Check if the request is too soon. |
1003 base::TimeDelta delta = base::Time::Now() - uit->last_check; | 939 base::TimeDelta delta = base::Time::Now() - uit->last_check; |
1004 if (delta < base::TimeDelta::FromSeconds(config_->OnDemandDelay())) | 940 if (delta < base::TimeDelta::FromSeconds(config_->OnDemandDelay())) |
1005 return kError; | 941 return kError; |
1006 | 942 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1058 case CrxUpdateItem::kNoUpdate: | 994 case CrxUpdateItem::kNoUpdate: |
1059 return kOk; | 995 return kOk; |
1060 case CrxUpdateItem::kLastStatus: | 996 case CrxUpdateItem::kLastStatus: |
1061 NOTREACHED() << status; | 997 NOTREACHED() << status; |
1062 } | 998 } |
1063 return kError; | 999 return kError; |
1064 } | 1000 } |
1065 | 1001 |
1066 /////////////////////////////////////////////////////////////////////////////// | 1002 /////////////////////////////////////////////////////////////////////////////// |
1067 | 1003 |
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 | 1004 // The component update factory. Using the component updater as a singleton |
1102 // is the job of the browser process. | 1005 // is the job of the browser process. |
1103 ComponentUpdateService* ComponentUpdateServiceFactory(Configurator* config) { | 1006 ComponentUpdateService* ComponentUpdateServiceFactory(Configurator* config) { |
1104 DCHECK(config); | 1007 DCHECK(config); |
1105 return new CrxUpdateService(config); | 1008 return new CrxUpdateService(config); |
1106 } | 1009 } |
1107 | 1010 |
1108 } // namespace component_updater | 1011 } // namespace component_updater |
OLD | NEW |