diff options
author | scherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-02 01:08:18 +0000 |
---|---|---|
committer | scherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-02 01:08:18 +0000 |
commit | 5cf07a4dcb899268019c36a2a1dcc8a0a2c0d26d (patch) | |
tree | 96cfa8d1570684ec0b95072dff6c74ae7a94d4c4 | |
parent | 61951483de50fa7d4acfee7236f03c975bb8116d (diff) | |
download | chromium_src-5cf07a4dcb899268019c36a2a1dcc8a0a2c0d26d.zip chromium_src-5cf07a4dcb899268019c36a2a1dcc8a0a2c0d26d.tar.gz chromium_src-5cf07a4dcb899268019c36a2a1dcc8a0a2c0d26d.tar.bz2 |
Revert 232517 "Component updater on-demand logic with Resource T..."
It's causing tests to die with the following:
[4915:73475:1101/175609:1317657134071:FATAL:browser_process_impl.cc(432)] Check failed: CalledOnValidThread().
> Component updater on-demand logic with Resource Throttle
>
> This CL introduces the new way to ask for an on demand install when you have a network request that needs the component to be present:
>
> ComponentUpdaterService::GetOnDemandResourceThrottle()
>
> Returns a resource throttle and initiates a update check + install immediately. The network request associated with the request is unblocked once the component is installed.
>
> The unittests are in progress here
> https://codereview.chromium.org/55303002/
>
> BUG=307193
> TEST=none
> R=darin@chromium.org, sorin@chromium.org, waffles@chromium.org
>
> Review URL: https://codereview.chromium.org/25713007
TBR=cpu@chromium.org
Review URL: https://codereview.chromium.org/47303007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@232537 0039d316-1c4b-4281-b951-d872f2087c98
4 files changed, 3 insertions, 176 deletions
diff --git a/chrome/browser/component_updater/component_updater_service.cc b/chrome/browser/component_updater/component_updater_service.cc index c25ab33..f3982c0 100644 --- a/chrome/browser/component_updater/component_updater_service.cc +++ b/chrome/browser/component_updater/component_updater_service.cc @@ -15,7 +15,6 @@ #include "base/files/file_path.h" #include "base/logging.h" #include "base/memory/scoped_ptr.h" -#include "base/memory/weak_ptr.h" #include "base/stl_util.h" #include "base/strings/string_number_conversions.h" #include "base/strings/string_piece.h" @@ -32,8 +31,6 @@ #include "chrome/common/chrome_version_info.h" #include "chrome/common/extensions/extension.h" #include "content/public/browser/browser_thread.h" -#include "content/public/browser/resource_controller.h" -#include "content/public/browser/resource_throttle.h" #include "content/public/browser/utility_process_host.h" #include "content/public/browser/utility_process_host_client.h" #include "net/base/escape.h" @@ -41,7 +38,6 @@ #include "net/base/net_errors.h" #include "net/url_request/url_fetcher.h" #include "net/url_request/url_fetcher_delegate.h" -#include "net/url_request/url_request.h" #include "net/url_request/url_request_status.h" #include "url/gurl.h" @@ -241,52 +237,6 @@ CrxComponentInfo::CrxComponentInfo() { CrxComponentInfo::~CrxComponentInfo() { } -/////////////////////////////////////////////////////////////////////////////// -// In charge of blocking url requests until the |crx_id| component has been -// updated. This class is touched solely from the IO thread. The UI thread -// can post tasks to it via weak pointers. By default the request is blocked -// unless the CrxUpdateService calls Unblock(). -// The lifetime is controlled by Chrome's resource loader so the component -// updater cannot touch objects from this class except via weak pointers. -class CUResourceThrottle - : public content::ResourceThrottle, - public base::SupportsWeakPtr<CUResourceThrottle> { - public: - explicit CUResourceThrottle(const net::URLRequest* request); - virtual ~CUResourceThrottle(); - // Overriden from ResourceThrottle. - virtual void WillStartRequest(bool* defer) OVERRIDE; - virtual void WillRedirectRequest(const GURL& new_url, bool* defer) OVERRIDE; - - // Component updater calls this function via PostTask to unblock the request. - void Unblock(); - - typedef std::vector<base::WeakPtr<CUResourceThrottle> > WeakPtrVector; - - private: - enum State { - NEW, - BLOCKED, - UNBLOCKED - }; - - State state_; -}; - -void UnblockResourceThrottle(base::WeakPtr<CUResourceThrottle> rt) { - BrowserThread::PostTask( - BrowserThread::IO, - FROM_HERE, - base::Bind(&CUResourceThrottle::Unblock, rt)); -} - -void UnblockandReapAllThrottles(CUResourceThrottle::WeakPtrVector* throttles) { - CUResourceThrottle::WeakPtrVector::iterator it; - for (it = throttles->begin(); it != throttles->end(); ++it) - UnblockResourceThrottle(*it); - throttles->clear(); -} - ////////////////////////////////////////////////////////////////////////////// // The one and only implementation of the ComponentUpdateService interface. In // charge of running the show. The main method is ProcessPendingItems() which @@ -313,8 +263,6 @@ class CrxUpdateService : public ComponentUpdateService { virtual Status OnDemandUpdate(const std::string& component_id) OVERRIDE; virtual void GetComponents( std::vector<CrxComponentInfo>* components) OVERRIDE; - virtual content::ResourceThrottle* GetOnDemandResourceThrottle( - net::URLRequest* request, const std::string& crx_id) OVERRIDE; // The only purpose of this class is to forward the // UtilityProcessHostClient callbacks so CrxUpdateService does @@ -395,8 +343,6 @@ class CrxUpdateService : public ComponentUpdateService { bool AddItemToUpdateCheck(CrxUpdateItem* item, std::string* query); - Status OnDemandUpdateInternal(CrxUpdateItem* item); - void ProcessPendingItems(); CrxUpdateItem* FindReadyComponent(); @@ -429,9 +375,6 @@ class CrxUpdateService : public ComponentUpdateService { bool HasOnDemandItems() const; - void OnNewResourceThrottle(base::WeakPtr<CUResourceThrottle> rt, - const std::string& crx_id); - scoped_ptr<ComponentUpdateService::Configurator> config_; scoped_ptr<ComponentPatcher> component_patcher_; @@ -616,13 +559,6 @@ void CrxUpdateService::ChangeItemState(CrxUpdateItem* item, break; } } - - // Free possible pending network requests. - if ((to == CrxUpdateItem::kUpdated) || - (to == CrxUpdateItem::kUpToDate) || - (to == CrxUpdateItem::kNoUpdate)) { - UnblockandReapAllThrottles(&item->throttles); - } } // Changes all the components in |work_items_| that have |from| status to @@ -712,13 +648,11 @@ bool CrxUpdateService::AddItemToUpdateCheck(CrxUpdateItem* item, // |component_id| is a value returned from GetCrxComponentID(). ComponentUpdateService::Status CrxUpdateService::OnDemandUpdate( const std::string& component_id) { - return OnDemandUpdateInternal(FindUpdateItemById(component_id)); -} - -ComponentUpdateService::Status CrxUpdateService::OnDemandUpdateInternal( - CrxUpdateItem* uit) { + CrxUpdateItem* uit; + uit = FindUpdateItemById(component_id); if (!uit) return kError; + // Check if the request is too soon. base::TimeDelta delta = base::Time::Now() - uit->last_check; if (delta < base::TimeDelta::FromSeconds(config_->OnDemandDelay())) @@ -1146,66 +1080,6 @@ void CrxUpdateService::NotifyComponentObservers( } } -content::ResourceThrottle* CrxUpdateService::GetOnDemandResourceThrottle( - net::URLRequest* request, const std::string& crx_id) { - // We give the raw pointer to the caller, who will delete it at will - // and we keep for ourselves a weak pointer to it so we can post tasks - // from the UI thread without having to track lifetime directly. - CUResourceThrottle* rt = new CUResourceThrottle(request); - BrowserThread::PostTask( - BrowserThread::UI, - FROM_HERE, - base::Bind(&CrxUpdateService::OnNewResourceThrottle, - base::Unretained(this), - rt->AsWeakPtr(), - crx_id)); - return rt; -} - -void CrxUpdateService::OnNewResourceThrottle( - base::WeakPtr<CUResourceThrottle> rt, const std::string& crx_id) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - // Check if we can on-demand update, else unblock the request anyway. - CrxUpdateItem* item = FindUpdateItemById(crx_id); - Status status = OnDemandUpdateInternal(item); - if (status == kOk || status == kInProgress) { - item->throttles.push_back(rt); - return; - } - UnblockResourceThrottle(rt); -} - -/////////////////////////////////////////////////////////////////////////////// - -CUResourceThrottle::CUResourceThrottle(const net::URLRequest* request) - : state_(NEW) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); -} - -CUResourceThrottle::~CUResourceThrottle() { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); -} - -void CUResourceThrottle::WillStartRequest(bool* defer) { - if (state_ != UNBLOCKED) { - state_ = BLOCKED; - *defer = true; - } else { - *defer = false; - } -} - -void CUResourceThrottle::WillRedirectRequest(const GURL& new_url, bool* defer) { - WillStartRequest(defer); -} - -void CUResourceThrottle::Unblock() { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - if (state_ == BLOCKED) - controller()->Resume(); - state_ = UNBLOCKED; -} - // The component update factory. Using the component updater as a singleton // is the job of the browser process. ComponentUpdateService* ComponentUpdateServiceFactory( diff --git a/chrome/browser/component_updater/component_updater_service.h b/chrome/browser/component_updater/component_updater_service.h index 41ddfb3..a4df001 100644 --- a/chrome/browser/component_updater/component_updater_service.h +++ b/chrome/browser/component_updater/component_updater_service.h @@ -18,11 +18,6 @@ class FilePath; namespace net { class URLRequestContextGetter; -class URLRequest; -} - -namespace content { -class ResourceThrottle; } class ComponentPatcher; @@ -193,12 +188,6 @@ class ComponentUpdateService { // Returns a list of registered components. virtual void GetComponents(std::vector<CrxComponentInfo>* components) = 0; - // Returns a network resource throttle. It means that a component will be - // downloaded and installed before the resource is unthrottled. This is the - // only function callable from the IO thread. - virtual content::ResourceThrottle* GetOnDemandResourceThrottle( - net::URLRequest* request, const std::string& crx_id) = 0; - virtual ~ComponentUpdateService() {} // TODO(waffles): Remove PNaCl as a friend once an alternative on-demand diff --git a/chrome/browser/component_updater/crx_update_item.h b/chrome/browser/component_updater/crx_update_item.h index 87bfafe..ba4e722 100644 --- a/chrome/browser/component_updater/crx_update_item.h +++ b/chrome/browser/component_updater/crx_update_item.h @@ -9,13 +9,10 @@ #include <vector> #include "base/basictypes.h" -#include "base/memory/weak_ptr.h" #include "base/time/time.h" #include "base/version.h" #include "chrome/browser/component_updater/component_updater_service.h" -class CUResourceThrottle; - // This is the one and only per-item state structure. Designed to be hosted // in a std::vector or a std::list. The two main members are |component| // which is supplied by the the component updater client and |status| which @@ -105,8 +102,6 @@ struct CrxUpdateItem { int diff_error_code; int diff_extra_code1; - std::vector<base::WeakPtr<CUResourceThrottle> > throttles; - CrxUpdateItem(); ~CrxUpdateItem(); diff --git a/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.cc b/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.cc index e58ab43..767b069 100644 --- a/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.cc +++ b/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.cc @@ -11,7 +11,6 @@ #include "base/metrics/histogram.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/chrome_notification_types.h" -#include "chrome/browser/component_updater/component_updater_service.h" #include "chrome/browser/content_settings/host_content_settings_map.h" #include "chrome/browser/download/download_request_limiter.h" #include "chrome/browser/download/download_resource_throttle.h" @@ -194,30 +193,6 @@ void ReportUnsupportedPrerenderScheme(const GURL& url) { } } -void AppendComponentUpdaterThrottles( - net::URLRequest* request, - content::ResourceContext* resource_context, - ResourceType::Type resource_type, - ScopedVector<content::ResourceThrottle>* throttles) { - const char* crx_id = NULL; - // Check for PNaCL nexe request. - if (resource_type == ResourceType::OBJECT) { - const net::HttpRequestHeaders& headers = request->extra_request_headers(); - std::string accept_headers; - if (headers.GetHeader("Accept", &accept_headers)) { - if (accept_headers.find("application/x-pnacl") != std::string::npos) - crx_id = "hnimpnehoodheedghdeeijklkeaacbdc"; - } - } - - if (crx_id) { - // We got a component we need to install, so throttle the resource - // until the component is installed. - ComponentUpdateService* cus = g_browser_process->component_updater(); - throttles->push_back(cus->GetOnDemandResourceThrottle(request, crx_id)); - } -} - } // end namespace ChromeResourceDispatcherHostDelegate::ChromeResourceDispatcherHostDelegate( @@ -344,12 +319,6 @@ void ChromeResourceDispatcherHostDelegate::RequestBeginning( resource_context, resource_type, throttles); - if (!is_prerendering) { - AppendComponentUpdaterThrottles(request, - resource_context, - resource_type, - throttles); - } if (io_data->resource_prefetch_predictor_observer()) { io_data->resource_prefetch_predictor_observer()->OnRequestStarted( |