Chromium Code Reviews| Index: chrome/browser/component_updater/component_updater_service.cc |
| =================================================================== |
| --- chrome/browser/component_updater/component_updater_service.cc (revision 226022) |
| +++ chrome/browser/component_updater/component_updater_service.cc (working copy) |
| @@ -40,6 +40,10 @@ |
| #include "net/url_request/url_request_status.h" |
| #include "url/gurl.h" |
| +#include "content/public/browser/resource_throttle.h" |
| +#include "content/public/browser/resource_controller.h" |
| +#include "net/url_request/url_request.h" |
| + |
| using content::BrowserThread; |
| using content::UtilityProcessHost; |
| using content::UtilityProcessHostClient; |
| @@ -235,6 +239,17 @@ |
| CrxComponentInfo::~CrxComponentInfo() { |
| } |
| +//////////////////////////////////////////////////////////////////////////////// |
| +class CUResourceThrottle |
| + : public content::ResourceThrottle { |
| + public: |
| + explicit CUResourceThrottle(const net::URLRequest* request); |
| + virtual ~CUResourceThrottle(); |
| + virtual void WillStartRequest(bool* defer) OVERRIDE; |
| + virtual void WillRedirectRequest(const GURL& new_url, bool* defer) OVERRIDE; |
| + void Unblock(); |
| +}; |
| + |
| ////////////////////////////////////////////////////////////////////////////// |
| // The one and only implementation of the ComponentUpdateService interface. In |
| // charge of running the show. The main method is ProcessPendingItems() which |
| @@ -261,6 +276,8 @@ |
| virtual Status CheckForUpdateSoon(const std::string& component_id) OVERRIDE; |
| virtual void GetComponents( |
| std::vector<CrxComponentInfo>* components) OVERRIDE; |
| + virtual content::ResourceThrottle* GetResourceThrottle( |
| + net::URLRequest* request, const char* crx_id) OVERRIDE; |
| // The only purpose of this class is to forward the |
| // UtilityProcessHostClient callbacks so CrxUpdateService does |
| @@ -361,6 +378,8 @@ |
| void NotifyComponentObservers(ComponentObserver::Events event, |
| int extra) const; |
| + void OnDemandUpdate(CUResourceThrottle* rt, const char* crx_id); |
| + |
| scoped_ptr<ComponentUpdateService::Configurator> config_; |
| scoped_ptr<ComponentPatcher> component_patcher_; |
| @@ -1002,6 +1021,68 @@ |
| } |
| } |
| +content::ResourceThrottle* CrxUpdateService::GetResourceThrottle( |
| + net::URLRequest* request, const char* crx_id) { |
| + // careful, we might create more than one resource throttle for the same |
| + // crx_id, so there needs to be logic that manages that. |
| + CUResourceThrottle* rt = new CUResourceThrottle(request); |
| + |
| + BrowserThread::PostTask( |
| + BrowserThread::UI, |
| + FROM_HERE, |
| + base::Bind(&CrxUpdateService::OnDemandUpdate, base::Unretained(this), |
| + rt, crx_id)); |
| + |
| + return rt; |
| +} |
| + |
| +void CrxUpdateService::OnDemandUpdate( |
| + CUResourceThrottle* rt, const char* crx_id) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + |
| + CrxUpdateItem* item = FindUpdateItemById(crx_id); |
| + if (!item) { |
| + rt->Unblock(); |
| + return; |
| + } |
| + // Then |
| + // 1) check that we are not updating this component already. |
| + // 2) Call something like |
| + // 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
|
| + // 3) add it to the 'update_now' list. etc |
| + // |
| + // If things go sour you can call from the throttle |
| + // controller()->Cancel(). |
| +} |
| + |
| +/////////////////////////////////////////////////////////////////////////////// |
| + |
| +CUResourceThrottle::CUResourceThrottle( |
| + const net::URLRequest* request) { |
| + // Called from the IO thread. |
| +} |
| + |
| +CUResourceThrottle::~CUResourceThrottle() { |
| + // Not sure about the lifetime |
| + // delete this; is a possiblity. |
| +} |
| + |
| +void CUResourceThrottle::WillStartRequest(bool* defer) { |
| + // By definition we need to block the resource until CUS calls back, typically |
| + // expecting UnBlock() once the component is installed. |
| + *defer = true; |
| +} |
| + |
| +void CUResourceThrottle::WillRedirectRequest(const GURL& new_url, bool* defer) { |
| + *defer = false; |
|
darin (slow to review)
2013/10/03 21:31:43
note: you could have a redirect to a media type th
|
| +} |
| + |
| +void CUResourceThrottle::Unblock() { |
| + // Can this be called from the UI thread? |
| + controller()->Resume(); |
| +} |
| + |
| +//////////////////////////////////////////////////////////////////////////////// |
| // The component update factory. Using the component updater as a singleton |
| // is the job of the browser process. |
| ComponentUpdateService* ComponentUpdateServiceFactory( |