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 <set> | 8 #include <set> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 22 matching lines...) Expand all Loading... | |
33 #include "content/public/browser/utility_process_host.h" | 33 #include "content/public/browser/utility_process_host.h" |
34 #include "content/public/browser/utility_process_host_client.h" | 34 #include "content/public/browser/utility_process_host_client.h" |
35 #include "net/base/escape.h" | 35 #include "net/base/escape.h" |
36 #include "net/base/load_flags.h" | 36 #include "net/base/load_flags.h" |
37 #include "net/base/net_errors.h" | 37 #include "net/base/net_errors.h" |
38 #include "net/url_request/url_fetcher.h" | 38 #include "net/url_request/url_fetcher.h" |
39 #include "net/url_request/url_fetcher_delegate.h" | 39 #include "net/url_request/url_fetcher_delegate.h" |
40 #include "net/url_request/url_request_status.h" | 40 #include "net/url_request/url_request_status.h" |
41 #include "url/gurl.h" | 41 #include "url/gurl.h" |
42 | 42 |
43 #include "content/public/browser/resource_throttle.h" | |
44 #include "content/public/browser/resource_controller.h" | |
45 #include "net/url_request/url_request.h" | |
46 | |
43 using content::BrowserThread; | 47 using content::BrowserThread; |
44 using content::UtilityProcessHost; | 48 using content::UtilityProcessHost; |
45 using content::UtilityProcessHostClient; | 49 using content::UtilityProcessHostClient; |
46 using extensions::Extension; | 50 using extensions::Extension; |
47 | 51 |
48 // The component updater is designed to live until process shutdown, so | 52 // The component updater is designed to live until process shutdown, so |
49 // base::Bind() calls are not refcounted. | 53 // base::Bind() calls are not refcounted. |
50 | 54 |
51 namespace { | 55 namespace { |
52 | 56 |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
228 return HexStringToID(StringToLowerASCII(base::HexEncode(&component.pk_hash[0], | 232 return HexStringToID(StringToLowerASCII(base::HexEncode(&component.pk_hash[0], |
229 component.pk_hash.size()/2))); | 233 component.pk_hash.size()/2))); |
230 } | 234 } |
231 | 235 |
232 CrxComponentInfo::CrxComponentInfo() { | 236 CrxComponentInfo::CrxComponentInfo() { |
233 } | 237 } |
234 | 238 |
235 CrxComponentInfo::~CrxComponentInfo() { | 239 CrxComponentInfo::~CrxComponentInfo() { |
236 } | 240 } |
237 | 241 |
242 //////////////////////////////////////////////////////////////////////////////// | |
243 class CUResourceThrottle | |
244 : public content::ResourceThrottle { | |
245 public: | |
246 explicit CUResourceThrottle(const net::URLRequest* request); | |
247 virtual ~CUResourceThrottle(); | |
248 virtual void WillStartRequest(bool* defer) OVERRIDE; | |
249 virtual void WillRedirectRequest(const GURL& new_url, bool* defer) OVERRIDE; | |
250 void Unblock(); | |
251 }; | |
252 | |
238 ////////////////////////////////////////////////////////////////////////////// | 253 ////////////////////////////////////////////////////////////////////////////// |
239 // The one and only implementation of the ComponentUpdateService interface. In | 254 // The one and only implementation of the ComponentUpdateService interface. In |
240 // charge of running the show. The main method is ProcessPendingItems() which | 255 // charge of running the show. The main method is ProcessPendingItems() which |
241 // is called periodically to do the upgrades/installs or the update checks. | 256 // is called periodically to do the upgrades/installs or the update checks. |
242 // An important consideration here is to be as "low impact" as we can to the | 257 // An important consideration here is to be as "low impact" as we can to the |
243 // rest of the browser, so even if we have many components registered and | 258 // rest of the browser, so even if we have many components registered and |
244 // eligible for update, we only do one thing at a time with pauses in between | 259 // eligible for update, we only do one thing at a time with pauses in between |
245 // the tasks. Also when we do network requests there is only one |url_fetcher_| | 260 // the tasks. Also when we do network requests there is only one |url_fetcher_| |
246 // in flight at a time. | 261 // in flight at a time. |
247 // There are no locks in this code, the main structure |work_items_| is mutated | 262 // There are no locks in this code, the main structure |work_items_| is mutated |
248 // only from the UI thread. The unpack and installation is done in the file | 263 // only from the UI thread. The unpack and installation is done in the file |
249 // thread and the network requests are done in the IO thread and in the file | 264 // thread and the network requests are done in the IO thread and in the file |
250 // thread. | 265 // thread. |
251 class CrxUpdateService : public ComponentUpdateService { | 266 class CrxUpdateService : public ComponentUpdateService { |
252 public: | 267 public: |
253 explicit CrxUpdateService(ComponentUpdateService::Configurator* config); | 268 explicit CrxUpdateService(ComponentUpdateService::Configurator* config); |
254 | 269 |
255 virtual ~CrxUpdateService(); | 270 virtual ~CrxUpdateService(); |
256 | 271 |
257 // Overrides for ComponentUpdateService. | 272 // Overrides for ComponentUpdateService. |
258 virtual Status Start() OVERRIDE; | 273 virtual Status Start() OVERRIDE; |
259 virtual Status Stop() OVERRIDE; | 274 virtual Status Stop() OVERRIDE; |
260 virtual Status RegisterComponent(const CrxComponent& component) OVERRIDE; | 275 virtual Status RegisterComponent(const CrxComponent& component) OVERRIDE; |
261 virtual Status CheckForUpdateSoon(const std::string& component_id) OVERRIDE; | 276 virtual Status CheckForUpdateSoon(const std::string& component_id) OVERRIDE; |
262 virtual void GetComponents( | 277 virtual void GetComponents( |
263 std::vector<CrxComponentInfo>* components) OVERRIDE; | 278 std::vector<CrxComponentInfo>* components) OVERRIDE; |
279 virtual content::ResourceThrottle* GetResourceThrottle( | |
280 net::URLRequest* request, const char* crx_id) OVERRIDE; | |
264 | 281 |
265 // The only purpose of this class is to forward the | 282 // The only purpose of this class is to forward the |
266 // UtilityProcessHostClient callbacks so CrxUpdateService does | 283 // UtilityProcessHostClient callbacks so CrxUpdateService does |
267 // not have to derive from it because that is refcounted. | 284 // not have to derive from it because that is refcounted. |
268 class ManifestParserBridge : public UtilityProcessHostClient { | 285 class ManifestParserBridge : public UtilityProcessHostClient { |
269 public: | 286 public: |
270 explicit ManifestParserBridge(CrxUpdateService* service) | 287 explicit ManifestParserBridge(CrxUpdateService* service) |
271 : service_(service) {} | 288 : service_(service) {} |
272 | 289 |
273 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE { | 290 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE { |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
354 int extended_error); | 371 int extended_error); |
355 | 372 |
356 size_t ChangeItemStatus(CrxUpdateItem::Status from, | 373 size_t ChangeItemStatus(CrxUpdateItem::Status from, |
357 CrxUpdateItem::Status to); | 374 CrxUpdateItem::Status to); |
358 | 375 |
359 CrxUpdateItem* FindUpdateItemById(const std::string& id); | 376 CrxUpdateItem* FindUpdateItemById(const std::string& id); |
360 | 377 |
361 void NotifyComponentObservers(ComponentObserver::Events event, | 378 void NotifyComponentObservers(ComponentObserver::Events event, |
362 int extra) const; | 379 int extra) const; |
363 | 380 |
381 void OnDemandUpdate(CUResourceThrottle* rt, const char* crx_id); | |
382 | |
364 scoped_ptr<ComponentUpdateService::Configurator> config_; | 383 scoped_ptr<ComponentUpdateService::Configurator> config_; |
365 | 384 |
366 scoped_ptr<ComponentPatcher> component_patcher_; | 385 scoped_ptr<ComponentPatcher> component_patcher_; |
367 | 386 |
368 scoped_ptr<net::URLFetcher> url_fetcher_; | 387 scoped_ptr<net::URLFetcher> url_fetcher_; |
369 | 388 |
370 scoped_ptr<component_updater::PingManager> ping_manager_; | 389 scoped_ptr<component_updater::PingManager> ping_manager_; |
371 | 390 |
372 // A collection of every work item. | 391 // A collection of every work item. |
373 typedef std::vector<CrxUpdateItem*> UpdateItems; | 392 typedef std::vector<CrxUpdateItem*> UpdateItems; |
(...skipping 621 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
995 void CrxUpdateService::NotifyComponentObservers( | 1014 void CrxUpdateService::NotifyComponentObservers( |
996 ComponentObserver::Events event, int extra) const { | 1015 ComponentObserver::Events event, int extra) const { |
997 for (UpdateItems::const_iterator it = work_items_.begin(); | 1016 for (UpdateItems::const_iterator it = work_items_.begin(); |
998 it != work_items_.end(); ++it) { | 1017 it != work_items_.end(); ++it) { |
999 ComponentObserver* observer = (*it)->component.observer; | 1018 ComponentObserver* observer = (*it)->component.observer; |
1000 if (observer) | 1019 if (observer) |
1001 observer->OnEvent(event, 0); | 1020 observer->OnEvent(event, 0); |
1002 } | 1021 } |
1003 } | 1022 } |
1004 | 1023 |
1024 content::ResourceThrottle* CrxUpdateService::GetResourceThrottle( | |
1025 net::URLRequest* request, const char* crx_id) { | |
1026 // careful, we might create more than one resource throttle for the same | |
1027 // crx_id, so there needs to be logic that manages that. | |
1028 CUResourceThrottle* rt = new CUResourceThrottle(request); | |
1029 | |
1030 BrowserThread::PostTask( | |
1031 BrowserThread::UI, | |
1032 FROM_HERE, | |
1033 base::Bind(&CrxUpdateService::OnDemandUpdate, base::Unretained(this), | |
1034 rt, crx_id)); | |
1035 | |
1036 return rt; | |
1037 } | |
1038 | |
1039 void CrxUpdateService::OnDemandUpdate( | |
1040 CUResourceThrottle* rt, const char* crx_id) { | |
1041 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
1042 | |
1043 CrxUpdateItem* item = FindUpdateItemById(crx_id); | |
1044 if (!item) { | |
1045 rt->Unblock(); | |
1046 return; | |
1047 } | |
1048 // Then | |
1049 // 1) check that we are not updating this component already. | |
1050 // 2) Call something like | |
1051 // item.component.installer->OnDemandUpdate(..) first? | |
jvoung (off chromium)
2013/10/09 17:05:22
What do you imagine 2) is used for?
We also need
| |
1052 // 3) add it to the 'update_now' list. etc | |
1053 // | |
1054 // If things go sour you can call from the throttle | |
1055 // controller()->Cancel(). | |
1056 } | |
1057 | |
1058 /////////////////////////////////////////////////////////////////////////////// | |
1059 | |
1060 CUResourceThrottle::CUResourceThrottle( | |
1061 const net::URLRequest* request) { | |
1062 // Called from the IO thread. | |
1063 } | |
1064 | |
1065 CUResourceThrottle::~CUResourceThrottle() { | |
1066 // Not sure about the lifetime | |
1067 // delete this; is a possiblity. | |
1068 } | |
1069 | |
1070 void CUResourceThrottle::WillStartRequest(bool* defer) { | |
1071 // By definition we need to block the resource until CUS calls back, typically | |
1072 // expecting UnBlock() once the component is installed. | |
1073 *defer = true; | |
1074 } | |
1075 | |
1076 void CUResourceThrottle::WillRedirectRequest(const GURL& new_url, bool* defer) { | |
1077 *defer = false; | |
darin (slow to review)
2013/10/03 21:31:43
note: you could have a redirect to a media type th
| |
1078 } | |
1079 | |
1080 void CUResourceThrottle::Unblock() { | |
1081 // Can this be called from the UI thread? | |
1082 controller()->Resume(); | |
1083 } | |
1084 | |
1085 //////////////////////////////////////////////////////////////////////////////// | |
1005 // The component update factory. Using the component updater as a singleton | 1086 // The component update factory. Using the component updater as a singleton |
1006 // is the job of the browser process. | 1087 // is the job of the browser process. |
1007 ComponentUpdateService* ComponentUpdateServiceFactory( | 1088 ComponentUpdateService* ComponentUpdateServiceFactory( |
1008 ComponentUpdateService::Configurator* config) { | 1089 ComponentUpdateService::Configurator* config) { |
1009 DCHECK(config); | 1090 DCHECK(config); |
1010 return new CrxUpdateService(config); | 1091 return new CrxUpdateService(config); |
1011 } | 1092 } |
OLD | NEW |