diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-02 00:35:58 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-02 00:35:58 +0000 |
commit | 347867b7b712fb62a5340da298b69f30e3443c49 (patch) | |
tree | 1f17c40edbd22ec9037755b7d0524cc757499e22 | |
parent | 04e29603179d6f28ee6c83c4ff134879ead1549d (diff) | |
download | chromium_src-347867b7b712fb62a5340da298b69f30e3443c49.zip chromium_src-347867b7b712fb62a5340da298b69f30e3443c49.tar.gz chromium_src-347867b7b712fb62a5340da298b69f30e3443c49.tar.bz2 |
Split ExtraRequestInfo out of ResourceDispatcherHost so it isn't cluttering up
that header file. I added documentation and split out the accessors according
to Google-style.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/179046
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@25133 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/automation/url_request_automation_job.cc | 9 | ||||
-rw-r--r-- | chrome/browser/extensions/user_script_listener.cc | 11 | ||||
-rw-r--r-- | chrome/browser/login_prompt.cc | 9 | ||||
-rw-r--r-- | chrome/browser/privacy_blacklist/blacklist_observer.cc | 12 | ||||
-rw-r--r-- | chrome/browser/renderer_host/buffered_resource_handler.cc | 35 | ||||
-rw-r--r-- | chrome/browser/renderer_host/cross_site_resource_handler.cc | 19 | ||||
-rw-r--r-- | chrome/browser/renderer_host/resource_dispatcher_host.cc | 372 | ||||
-rw-r--r-- | chrome/browser/renderer_host/resource_dispatcher_host.h | 141 | ||||
-rw-r--r-- | chrome/browser/renderer_host/resource_dispatcher_host_request_info.cc | 50 | ||||
-rw-r--r-- | chrome/browser/renderer_host/resource_dispatcher_host_request_info.h | 225 | ||||
-rw-r--r-- | chrome/browser/renderer_host/resource_request_details.h | 15 | ||||
-rw-r--r-- | chrome/browser/ssl/ssl_error_handler.cc | 15 | ||||
-rw-r--r-- | chrome/browser/ssl/ssl_manager.cc | 28 | ||||
-rw-r--r-- | chrome/chrome.gyp | 2 |
14 files changed, 562 insertions, 381 deletions
diff --git a/chrome/browser/automation/url_request_automation_job.cc b/chrome/browser/automation/url_request_automation_job.cc index 01e7608..349d99e 100644 --- a/chrome/browser/automation/url_request_automation_job.cc +++ b/chrome/browser/automation/url_request_automation_job.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2009 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -9,6 +9,7 @@ #include "chrome/browser/automation/automation_resource_message_filter.h" #include "chrome/browser/renderer_host/render_view_host.h" #include "chrome/browser/renderer_host/resource_dispatcher_host.h" +#include "chrome/browser/renderer_host/resource_dispatcher_host_request_info.h" #include "chrome/test/automation/automation_messages.h" #include "net/base/io_buffer.h" #include "net/base/net_errors.h" @@ -64,12 +65,12 @@ class AutomationRequestInterceptor : public URLRequest::Interceptor { URLRequestJob* AutomationRequestInterceptor::MaybeIntercept( URLRequest* request) { if (request->url().SchemeIs("http") || request->url().SchemeIs("https")) { - ResourceDispatcherHost::ExtraRequestInfo* request_info = - ResourceDispatcherHost::ExtraInfoForRequest(request); + ResourceDispatcherHostRequestInfo* request_info = + ResourceDispatcherHost::InfoForRequest(request); if (request_info) { AutomationResourceMessageFilter::AutomationDetails details; if (AutomationResourceMessageFilter::LookupRegisteredRenderView( - request_info->child_id, request_info->route_id, &details)) { + request_info->child_id(), request_info->route_id(), &details)) { URLRequestAutomationJob* job = new URLRequestAutomationJob(request, details.tab_handle, details.filter); return job; diff --git a/chrome/browser/extensions/user_script_listener.cc b/chrome/browser/extensions/user_script_listener.cc index 086fc38..cc77296 100644 --- a/chrome/browser/extensions/user_script_listener.cc +++ b/chrome/browser/extensions/user_script_listener.cc @@ -6,6 +6,7 @@ #include "base/message_loop.h" #include "chrome/browser/extensions/extensions_service.h" +#include "chrome/browser/renderer_host/resource_dispatcher_host_request_info.h" #include "chrome/common/extensions/extension.h" #include "chrome/common/notification_service.h" #include "net/url_request/url_request.h" @@ -38,12 +39,12 @@ bool UserScriptListener::ShouldStartRequest(URLRequest* request) { // If it's a frame load, then we need to check the URL against the list of // user scripts to see if we need to wait. - ResourceDispatcherHost::ExtraRequestInfo* info = - ResourceDispatcherHost::ExtraInfoForRequest(request); + ResourceDispatcherHostRequestInfo* info = + ResourceDispatcherHost::InfoForRequest(request); DCHECK(info); - if (info->resource_type != ResourceType::MAIN_FRAME && - info->resource_type != ResourceType::SUB_FRAME) { + if (info->resource_type() != ResourceType::MAIN_FRAME && + info->resource_type() != ResourceType::SUB_FRAME) { return true; } @@ -66,7 +67,7 @@ bool UserScriptListener::ShouldStartRequest(URLRequest* request) { // Queue this request up. delayed_request_ids_.push_front(ResourceDispatcherHost::GlobalRequestID( - info->child_id, info->request_id)); + info->child_id(), info->request_id())); return false; } diff --git a/chrome/browser/login_prompt.cc b/chrome/browser/login_prompt.cc index 3a0a18a..934ba17 100644 --- a/chrome/browser/login_prompt.cc +++ b/chrome/browser/login_prompt.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2009 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -12,6 +12,7 @@ #include "chrome/browser/password_manager/password_manager.h" #include "chrome/browser/renderer_host/render_process_host.h" #include "chrome/browser/renderer_host/resource_dispatcher_host.h" +#include "chrome/browser/renderer_host/resource_dispatcher_host_request_info.h" #include "chrome/browser/tab_contents/constrained_window.h" #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/common/chrome_switches.h" @@ -26,12 +27,12 @@ class LoginHandlerImpl; // Helper to remove the ref from an URLRequest to the LoginHandler. // Should only be called from the IO thread, since it accesses an URLRequest. void ResetLoginHandlerForRequest(URLRequest* request) { - ResourceDispatcherHost::ExtraRequestInfo* info = - ResourceDispatcherHost::ExtraInfoForRequest(request); + ResourceDispatcherHostRequestInfo* info = + ResourceDispatcherHost::InfoForRequest(request); if (!info) return; - info->login_handler = NULL; + info->set_login_handler(NULL); } // Get the signon_realm under which this auth info should be stored. diff --git a/chrome/browser/privacy_blacklist/blacklist_observer.cc b/chrome/browser/privacy_blacklist/blacklist_observer.cc index 77f1177..46d117cc 100644 --- a/chrome/browser/privacy_blacklist/blacklist_observer.cc +++ b/chrome/browser/privacy_blacklist/blacklist_observer.cc @@ -11,6 +11,7 @@ #include "chrome/browser/privacy_blacklist/blacklist.h" #include "chrome/browser/renderer_host/render_view_host.h" #include "chrome/browser/renderer_host/resource_dispatcher_host.h" +#include "chrome/browser/renderer_host/resource_dispatcher_host_request_info.h" #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/common/notification_details.h" #include "chrome/common/notification_service.h" @@ -21,11 +22,11 @@ class BlockedContentNotice : public Task { public: BlockedContentNotice(const GURL& gurl, const Blacklist::Match* match, - const ResourceDispatcherHost::ExtraRequestInfo* info) + const ResourceDispatcherHostRequestInfo* info) : gurl_(gurl), match_(match), - child_id_(info->child_id), - route_id_(info->route_id) { + child_id_(info->child_id()), + route_id_(info->route_id()) { if (match_->attributes() & Blacklist::kDontStoreCookies) { // No cookies stored. reason_ = l10n_util::GetStringUTF16(IDS_BLACKLIST_BLOCKED_COOKIES); @@ -59,9 +60,8 @@ void BlacklistObserver::ContentBlocked(const URLRequest* request) { const URLRequest::UserData* d = request->GetUserData(&Blacklist::kRequestDataKey); const Blacklist::Match* match = static_cast<const Blacklist::Match*>(d); - const ResourceDispatcherHost::ExtraRequestInfo* info = - static_cast<const ResourceDispatcherHost::ExtraRequestInfo*>( - request->GetUserData(NULL)); + const ResourceDispatcherHostRequestInfo* info = + ResourceDispatcherHost::InfoForRequest(request); const GURL& gurl = request->url(); BlockedContentNotice* task = new BlockedContentNotice(gurl, match, info); diff --git a/chrome/browser/renderer_host/buffered_resource_handler.cc b/chrome/browser/renderer_host/buffered_resource_handler.cc index 5a5f750..cba1754 100644 --- a/chrome/browser/renderer_host/buffered_resource_handler.cc +++ b/chrome/browser/renderer_host/buffered_resource_handler.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2009 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -13,6 +13,7 @@ #include "chrome/browser/chrome_thread.h" #include "chrome/browser/renderer_host/download_throttling_resource_handler.h" #include "chrome/browser/renderer_host/resource_dispatcher_host.h" +#include "chrome/browser/renderer_host/resource_dispatcher_host_request_info.h" #include "chrome/common/url_constants.h" #include "net/base/mime_sniffer.h" #include "net/base/mime_util.h" @@ -276,10 +277,10 @@ bool BufferedResourceHandler::CompleteResponseStarted(int request_id, // Check to see if we should forward the data from this request to the // download thread. // TODO(paulg): Only download if the context from the renderer allows it. - ResourceDispatcherHost::ExtraRequestInfo* info = - ResourceDispatcherHost::ExtraInfoForRequest(request_); + ResourceDispatcherHostRequestInfo* info = + ResourceDispatcherHost::InfoForRequest(request_); - if (info->allow_download && ShouldDownload(NULL)) { + if (info->allow_download() && ShouldDownload(NULL)) { if (response_->response_head.headers && // Can be NULL if FTP. response_->response_head.headers->response_code() / 100 != 2) { // The response code indicates that this is an error page, but we don't @@ -291,14 +292,14 @@ bool BufferedResourceHandler::CompleteResponseStarted(int request_id, return false; } - info->is_download = true; + info->set_is_download(true); scoped_refptr<DownloadThrottlingResourceHandler> download_handler = new DownloadThrottlingResourceHandler(host_, request_, request_->url(), - info->child_id, - info->route_id, + info->child_id(), + info->route_id(), request_id, in_complete); if (bytes_read_) { @@ -313,9 +314,9 @@ bool BufferedResourceHandler::CompleteResponseStarted(int request_id, // Send the renderer a response that indicates that the request will be // handled by an external source (the browser's DownloadManager). - real_handler_->OnResponseStarted(info->request_id, response_); + real_handler_->OnResponseStarted(info->request_id(), response_); URLRequestStatus status(URLRequestStatus::HANDLED_EXTERNALLY, 0); - real_handler_->OnResponseCompleted(info->request_id, status, + real_handler_->OnResponseCompleted(info->request_id(), status, std::string()); // Ditch the old async handler that talks to the renderer for the new @@ -331,9 +332,9 @@ bool BufferedResourceHandler::ShouldWaitForPlugins() { return false; // We don't want to keep buffering as our buffer will fill up. - ResourceDispatcherHost::ExtraRequestInfo* info = - ResourceDispatcherHost::ExtraInfoForRequest(request_); - host_->PauseRequest(info->child_id, info->request_id, true); + ResourceDispatcherHostRequestInfo* info = + ResourceDispatcherHost::InfoForRequest(request_); + host_->PauseRequest(info->child_id(), info->request_id(), true); // Schedule plugin loading on the file thread. // Note: it's possible that the only reference to this object is the task. If @@ -431,11 +432,11 @@ void BufferedResourceHandler::NotifyPluginsLoaded( void BufferedResourceHandler::OnPluginsLoaded() { wait_for_plugins_ = false; if (request_) { - ResourceDispatcherHost::ExtraRequestInfo* info = - ResourceDispatcherHost::ExtraInfoForRequest(request_); - host_->PauseRequest(info->child_id, info->request_id, false); - if (!CompleteResponseStarted(info->request_id, false)) - host_->CancelRequest(info->child_id, info->request_id, false); + ResourceDispatcherHostRequestInfo* info = + ResourceDispatcherHost::InfoForRequest(request_); + host_->PauseRequest(info->child_id(), info->request_id(), false); + if (!CompleteResponseStarted(info->request_id(), false)) + host_->CancelRequest(info->child_id(), info->request_id(), false); } Release(); } diff --git a/chrome/browser/renderer_host/cross_site_resource_handler.cc b/chrome/browser/renderer_host/cross_site_resource_handler.cc index eb688e7..e6eed17 100644 --- a/chrome/browser/renderer_host/cross_site_resource_handler.cc +++ b/chrome/browser/renderer_host/cross_site_resource_handler.cc @@ -9,6 +9,7 @@ #include "base/logging.h" #include "base/message_loop.h" #include "chrome/browser/renderer_host/render_view_host.h" +#include "chrome/browser/renderer_host/resource_dispatcher_host_request_info.h" #include "net/base/io_buffer.h" namespace { @@ -110,13 +111,13 @@ bool CrossSiteResourceHandler::OnResponseStarted(int request_id, DLOG(WARNING) << "Request wasn't found"; return false; } - ResourceDispatcherHost::ExtraRequestInfo* info = - ResourceDispatcherHost::ExtraInfoForRequest(request); + ResourceDispatcherHostRequestInfo* info = + ResourceDispatcherHost::InfoForRequest(request); // If this is a download, just pass the response through without doing a // cross-site check. The renderer will see it is a download and abort the // request. - if (info->is_download) { + if (info->is_download()) { return next_handler_->OnResponseStarted(request_id, response); } @@ -202,8 +203,6 @@ void CrossSiteResourceHandler::ResumeResponse() { DLOG(WARNING) << "Resuming a request that wasn't found"; return; } - ResourceDispatcherHost::ExtraRequestInfo* info = - ResourceDispatcherHost::ExtraInfoForRequest(request); if (has_started_response_) { // Send OnResponseStarted to the new renderer. @@ -216,7 +215,9 @@ void CrossSiteResourceHandler::ResumeResponse() { } // Remove ourselves from the ExtraRequestInfo. - info->cross_site_handler = NULL; + ResourceDispatcherHostRequestInfo* info = + ResourceDispatcherHost::InfoForRequest(request); + info->set_cross_site_handler(NULL); // If the response completed during the transition, notify the next // event handler. @@ -248,9 +249,9 @@ void CrossSiteResourceHandler::StartCrossSiteTransition( DLOG(WARNING) << "Cross site response for a request that wasn't found"; return; } - ResourceDispatcherHost::ExtraRequestInfo* info = - ResourceDispatcherHost::ExtraInfoForRequest(request); - info->cross_site_handler = this; + ResourceDispatcherHostRequestInfo* info = + ResourceDispatcherHost::InfoForRequest(request); + info->set_cross_site_handler(this); if (has_started_response_) { // Pause the request until the old renderer is finished and the new diff --git a/chrome/browser/renderer_host/resource_dispatcher_host.cc b/chrome/browser/renderer_host/resource_dispatcher_host.cc index 669118b..bac4f62 100644 --- a/chrome/browser/renderer_host/resource_dispatcher_host.cc +++ b/chrome/browser/renderer_host/resource_dispatcher_host.cc @@ -37,6 +37,7 @@ #include "chrome/browser/renderer_host/download_resource_handler.h" #include "chrome/browser/renderer_host/render_view_host.h" #include "chrome/browser/renderer_host/render_view_host_delegate.h" +#include "chrome/browser/renderer_host/resource_dispatcher_host_request_info.h" #include "chrome/browser/renderer_host/resource_request_details.h" #include "chrome/browser/renderer_host/safe_browsing_resource_handler.h" #include "chrome/browser/renderer_host/save_file_resource_handler.h" @@ -307,6 +308,12 @@ void ResourceDispatcherHost::Shutdown() { io_loop_->PostTask(FROM_HERE, new ShutdownTask(this)); } +void ResourceDispatcherHost::SetRequestInfo( + URLRequest* request, + ResourceDispatcherHostRequestInfo* info) { + request->SetUserData(NULL, info); +} + void ResourceDispatcherHost::OnShutdown() { DCHECK(MessageLoop::current() == io_loop_); is_shutdown_ = true; @@ -572,19 +579,20 @@ void ResourceDispatcherHost::BeginRequest( handler = new BufferedResourceHandler(handler, this, request); // Make extra info and read footer (contains request ID). - ExtraRequestInfo* extra_info = - new ExtraRequestInfo(handler, - process_type, - child_id, - route_id, - request_id, - request_data.frame_origin, - request_data.main_frame_origin, - request_data.resource_type, - upload_size); - extra_info->allow_download = - ResourceType::IsFrame(request_data.resource_type); - SetExtraInfoForRequest(request, extra_info); // Request takes ownership. + ResourceDispatcherHostRequestInfo* extra_info = + new ResourceDispatcherHostRequestInfo( + handler, + process_type, + child_id, + route_id, + request_id, + request_data.frame_origin, + request_data.main_frame_origin, + request_data.resource_type, + upload_size, + false, // is download + ResourceType::IsFrame(request_data.resource_type)); // allow_download + SetRequestInfo(request, extra_info); // Request takes ownership. chrome_browser_net::SetOriginProcessUniqueIDForRequest( request_data.origin_child_id, request); @@ -607,16 +615,16 @@ void ResourceDispatcherHost::DataReceivedACK(int child_id, if (i == pending_requests_.end()) return; - ExtraRequestInfo* info = ExtraInfoForRequest(i->second); + ResourceDispatcherHostRequestInfo* info = InfoForRequest(i->second); // Decrement the number of pending data messages. - info->pending_data_count--; + info->DecrementPendingDataCount(); // If the pending data count was higher than the max, resume the request. - if (info->pending_data_count == kMaxPendingDataMessages) { + if (info->pending_data_count() == kMaxPendingDataMessages) { // Decrement the pending data count one more time because we also // incremented it before pausing the request. - info->pending_data_count--; + info->DecrementPendingDataCount(); // Resume the request. PauseRequest(child_id, request_id, false); @@ -630,8 +638,8 @@ void ResourceDispatcherHost::OnUploadProgressACK(int request_id) { if (i == pending_requests_.end()) return; - ExtraRequestInfo* info = ExtraInfoForRequest(i->second); - info->waiting_for_upload_progress_ack = false; + ResourceDispatcherHostRequestInfo* info = InfoForRequest(i->second); + info->set_waiting_for_upload_progress_ack(false); } void ResourceDispatcherHost::OnCancelRequest(int request_id) { @@ -652,9 +660,9 @@ void ResourceDispatcherHost::OnClosePageACK( PendingRequestList::iterator i = pending_requests_.find(global_id); if (i != pending_requests_.end()) { // The response we were meant to resume could have already been canceled. - ExtraRequestInfo* info = ExtraInfoForRequest(i->second); - if (info->cross_site_handler) - info->cross_site_handler->ResumeResponse(); + ResourceDispatcherHostRequestInfo* info = InfoForRequest(i->second); + if (info->cross_site_handler()) + info->cross_site_handler()->ResumeResponse(); } } else { // This is a tab close, so just forward the message to close it. @@ -724,21 +732,20 @@ void ResourceDispatcherHost::BeginDownload(const GURL& url, request->set_load_flags(request->load_flags() | net::LOAD_IS_DOWNLOAD); - ExtraRequestInfo* extra_info = - new ExtraRequestInfo(handler, - ChildProcessInfo::RENDER_PROCESS, - child_id, - route_id, - request_id_, - "null", // frame_origin - "null", // main_frame_origin - ResourceType::SUB_RESOURCE, - 0 /* upload_size */); - extra_info->allow_download = true; - extra_info->is_download = true; - SetExtraInfoForRequest(request, extra_info); // request takes ownership - chrome_browser_net::SetOriginProcessUniqueIDForRequest(child_id, - request); + ResourceDispatcherHostRequestInfo* extra_info = + new ResourceDispatcherHostRequestInfo(handler, + ChildProcessInfo::RENDER_PROCESS, + child_id, + route_id, + request_id_, + "null", // frame_origin + "null", // main_frame_origin + ResourceType::SUB_RESOURCE, + 0, // upload_size + true, // is_download + true); // allow_download + SetRequestInfo(request, extra_info); // Request takes ownership. + chrome_browser_net::SetOriginProcessUniqueIDForRequest(child_id, request); BeginRequestInternal(request); } @@ -780,20 +787,20 @@ void ResourceDispatcherHost::BeginSaveFile(const GURL& url, request->set_load_flags(net::LOAD_ONLY_FROM_CACHE); request->set_context(request_context); - ExtraRequestInfo* extra_info = - new ExtraRequestInfo(handler, - ChildProcessInfo::RENDER_PROCESS, - child_id, - route_id, - request_id_, - "null", // frame_origin - "null", // main_frame_origin - ResourceType::SUB_RESOURCE, - 0 /* upload_size */); - // Just saving some resources we need, disallow downloading. - extra_info->allow_download = false; - extra_info->is_download = false; - SetExtraInfoForRequest(request, extra_info); // request takes ownership + // Since we're just saving some resources we need, disallow downloading. + ResourceDispatcherHostRequestInfo* extra_info = + new ResourceDispatcherHostRequestInfo(handler, + ChildProcessInfo::RENDER_PROCESS, + child_id, + route_id, + request_id_, + "null", // frame_origin + "null", // main_frame_origin + ResourceType::SUB_RESOURCE, + 0, // upload_size + false, // is_download + false); // allow_download + SetRequestInfo(request, extra_info); // Request takes ownership. chrome_browser_net::SetOriginProcessUniqueIDForRequest(child_id, request); BeginRequestInternal(request); @@ -826,10 +833,10 @@ bool ResourceDispatcherHost::WillSendData(int child_id, return false; } - ExtraRequestInfo* info = ExtraInfoForRequest(i->second); + ResourceDispatcherHostRequestInfo* info = InfoForRequest(i->second); - info->pending_data_count++; - if (info->pending_data_count > kMaxPendingDataMessages) { + info->IncrementPendingDataCount(); + if (info->pending_data_count() > kMaxPendingDataMessages) { // We reached the max number of data messages that can be sent to // the renderer for a given request. Pause the request and wait for // the renderer to start processing them before resuming it. @@ -850,20 +857,19 @@ void ResourceDispatcherHost::PauseRequest(int child_id, return; } - ExtraRequestInfo* info = ExtraInfoForRequest(i->second); - - int pause_count = info->pause_count + (pause ? 1 : -1); + ResourceDispatcherHostRequestInfo* info = InfoForRequest(i->second); + int pause_count = info->pause_count() + (pause ? 1 : -1); if (pause_count < 0) { NOTREACHED(); // Unbalanced call to pause. return; } - info->pause_count = pause_count; + info->set_pause_count(pause_count); RESOURCE_LOG("To pause (" << pause << "): " << i->second->url().spec()); // If we're resuming, kick the request to start reading again. Run the read // asynchronously to avoid recursion problems. - if (info->pause_count == 0) { + if (info->pause_count() == 0) { MessageLoop::current()->PostTask(FROM_HERE, method_runner_.NewRunnableMethod( &ResourceDispatcherHost::ResumeRequest, global_id)); @@ -897,9 +903,9 @@ void ResourceDispatcherHost::CancelRequestsForRoute(int child_id, for (PendingRequestList::const_iterator i = pending_requests_.begin(); i != pending_requests_.end(); ++i) { if (i->first.child_id == child_id) { - ExtraRequestInfo* info = ExtraInfoForRequest(i->second); - if (!info->is_download && (route_id == -1 || - route_id == info->route_id)) { + ResourceDispatcherHostRequestInfo* info = InfoForRequest(i->second); + if (!info->is_download() && + (route_id == -1 || route_id == info->route_id())) { matching_requests.push_back( GlobalRequestID(child_id, i->first.request_id)); } @@ -960,16 +966,16 @@ void ResourceDispatcherHost::RemovePendingRequest(int child_id, void ResourceDispatcherHost::RemovePendingRequest( const PendingRequestList::iterator& iter) { - ExtraRequestInfo* info = ExtraInfoForRequest(iter->second); + ResourceDispatcherHostRequestInfo* info = InfoForRequest(iter->second); // Remove the memory credit that we added when pushing the request onto // the pending list. - IncrementOutstandingRequestsMemoryCost(-1 * info->memory_cost, - info->child_id); + IncrementOutstandingRequestsMemoryCost(-1 * info->memory_cost(), + info->child_id()); // Notify the login handler that this request object is going away. - if (info && info->login_handler) - info->login_handler->OnRequestCancelled(); + if (info && info->login_handler()) + info->login_handler()->OnRequestCancelled(); delete iter->second; pending_requests_.erase(iter); @@ -985,36 +991,37 @@ void ResourceDispatcherHost::OnReceivedRedirect(URLRequest* request, const GURL& new_url, bool* defer_redirect) { RESOURCE_LOG("OnReceivedRedirect: " << request->url().spec()); - ExtraRequestInfo* info = ExtraInfoForRequest(request); + ResourceDispatcherHostRequestInfo* info = InfoForRequest(request); DCHECK(request->status().is_success()); - if (info->process_type != ChildProcessInfo::PLUGIN_PROCESS && + if (info->process_type() != ChildProcessInfo::PLUGIN_PROCESS && !ChildProcessSecurityPolicy::GetInstance()-> - CanRequestURL(info->child_id, new_url)) { + CanRequestURL(info->child_id(), new_url)) { LOG(INFO) << "Denied unauthorized request for " << new_url.possibly_invalid_spec(); // Tell the renderer that this request was disallowed. - CancelRequest(info->child_id, info->request_id, false); + CancelRequest(info->child_id(), info->request_id(), false); return; } - NotifyReceivedRedirect(request, info->child_id, new_url); + NotifyReceivedRedirect(request, info->child_id(), new_url); - if (HandleExternalProtocol(info->request_id, info->child_id, - info->route_id, new_url, - info->resource_type, info->resource_handler)) { + if (HandleExternalProtocol(info->request_id(), info->child_id(), + info->route_id(), new_url, + info->resource_type(), info->resource_handler())) { // The request is complete so we can remove it. - RemovePendingRequest(info->child_id, info->request_id); + RemovePendingRequest(info->child_id(), info->request_id()); return; } scoped_refptr<ResourceResponse> response = new ResourceResponse; - PopulateResourceResponse(request, info->filter_policy, response); - if (!info->resource_handler->OnRequestRedirected(info->request_id, new_url, - response, defer_redirect)) - CancelRequest(info->child_id, info->request_id, false); + PopulateResourceResponse(request, info->filter_policy(), response); + if (!info->resource_handler()->OnRequestRedirected(info->request_id(), + new_url, + response, defer_redirect)) + CancelRequest(info->child_id(), info->request_id(), false); } void ResourceDispatcherHost::OnAuthRequired( @@ -1026,15 +1033,15 @@ void ResourceDispatcherHost::OnAuthRequired( // authentication. // That would also solve the problem of the URLRequest being cancelled // before we receive authentication. - ExtraRequestInfo* info = ExtraInfoForRequest(request); - DCHECK(!info->login_handler) << + ResourceDispatcherHostRequestInfo* info = InfoForRequest(request); + DCHECK(!info->login_handler()) << "OnAuthRequired called with login_handler pending"; - info->login_handler = CreateLoginPrompt(auth_info, request, ui_loop_); + info->set_login_handler(CreateLoginPrompt(auth_info, request, ui_loop_)); } void ResourceDispatcherHost::OnCertificateRequested( - URLRequest* request, - net::SSLCertRequestInfo* cert_request_info) { + URLRequest* request, + net::SSLCertRequestInfo* cert_request_info) { DCHECK(request); if (cert_request_info->client_certs.empty()) { @@ -1043,12 +1050,12 @@ void ResourceDispatcherHost::OnCertificateRequested( return; } - ExtraRequestInfo* info = ExtraInfoForRequest(request); - DCHECK(!info->ssl_client_auth_handler) << + ResourceDispatcherHostRequestInfo* info = InfoForRequest(request); + DCHECK(!info->ssl_client_auth_handler()) << "OnCertificateRequested called with ssl_client_auth_handler pending"; - info->ssl_client_auth_handler = - new SSLClientAuthHandler(request, cert_request_info, io_loop_, ui_loop_); - info->ssl_client_auth_handler->SelectCertificate(); + info->set_ssl_client_auth_handler( + new SSLClientAuthHandler(request, cert_request_info, io_loop_, ui_loop_)); + info->ssl_client_auth_handler()->SelectCertificate(); } void ResourceDispatcherHost::OnSSLCertificateError( @@ -1061,7 +1068,7 @@ void ResourceDispatcherHost::OnSSLCertificateError( void ResourceDispatcherHost::OnResponseStarted(URLRequest* request) { RESOURCE_LOG("OnResponseStarted: " << request->url().spec()); - ExtraRequestInfo* info = ExtraInfoForRequest(request); + ResourceDispatcherHostRequestInfo* info = InfoForRequest(request); if (PauseRequestIfNeeded(info)) { RESOURCE_LOG("OnResponseStarted pausing: " << request->url().spec()); return; @@ -1071,11 +1078,11 @@ void ResourceDispatcherHost::OnResponseStarted(URLRequest* request) { // We want to send a final upload progress message prior to sending // the response complete message even if we're waiting for an ack to // to a previous upload progress message. - info->waiting_for_upload_progress_ack = false; + info->set_waiting_for_upload_progress_ack(false); MaybeUpdateUploadProgress(info, request); if (!CompleteResponseStarted(request)) { - CancelRequest(info->child_id, info->request_id, false); + CancelRequest(info->child_id(), info->request_id(), false); } else { // Check if the handler paused the request in their OnResponseStarted. if (PauseRequestIfNeeded(info)) { @@ -1091,10 +1098,10 @@ void ResourceDispatcherHost::OnResponseStarted(URLRequest* request) { } bool ResourceDispatcherHost::CompleteResponseStarted(URLRequest* request) { - ExtraRequestInfo* info = ExtraInfoForRequest(request); + ResourceDispatcherHostRequestInfo* info = InfoForRequest(request); scoped_refptr<ResourceResponse> response = new ResourceResponse; - PopulateResourceResponse(request, info->filter_policy, response); + PopulateResourceResponse(request, info->filter_policy(), response); const URLRequest::UserData* d = request->GetUserData(&Blacklist::kRequestDataKey); @@ -1109,7 +1116,7 @@ bool ResourceDispatcherHost::CompleteResponseStarted(URLRequest* request) { if (request->ssl_info().cert) { int cert_id = CertStore::GetSharedInstance()->StoreCert(request->ssl_info().cert, - info->child_id); + info->child_id()); response->response_head.security_info = SSLManager::SerializeSecurityInfo(cert_id, request->ssl_info().cert_status, @@ -1121,10 +1128,10 @@ bool ResourceDispatcherHost::CompleteResponseStarted(URLRequest* request) { request->ssl_info().security_bits == 0)); } - NotifyResponseStarted(request, info->child_id); - info->called_on_response_started = true; - return info->resource_handler->OnResponseStarted(info->request_id, - response.get()); + NotifyResponseStarted(request, info->child_id()); + info->set_called_on_response_started(true); + return info->resource_handler()->OnResponseStarted(info->request_id(), + response.get()); } void ResourceDispatcherHost::CancelRequest(int child_id, @@ -1143,15 +1150,15 @@ void ResourceDispatcherHost::CancelRequest(int child_id, // WebKit will send us a cancel for downloads since it no longer handles them. // In this case, ignore the cancel since we handle downloads in the browser. - ExtraRequestInfo* info = ExtraInfoForRequest(i->second); - if (!from_renderer || !info->is_download) { - if (info->login_handler) { - info->login_handler->OnRequestCancelled(); - info->login_handler = NULL; + ResourceDispatcherHostRequestInfo* info = InfoForRequest(i->second); + if (!from_renderer || !info->is_download()) { + if (info->login_handler()) { + info->login_handler()->OnRequestCancelled(); + info->set_login_handler(NULL); } - if (info->ssl_client_auth_handler) { - info->ssl_client_auth_handler->OnRequestCancelled(); - info->ssl_client_auth_handler = NULL; + if (info->ssl_client_auth_handler()) { + info->ssl_client_auth_handler()->OnRequestCancelled(); + info->set_ssl_client_auth_handler(NULL); } if (!i->second->is_pending() && allow_delete) { // No io is pending, canceling the request won't notify us of anything, @@ -1159,7 +1166,7 @@ void ResourceDispatcherHost::CancelRequest(int child_id, // TODO(sky): removing the request in this manner means we're not // notifying anyone. We need make sure the event handlers and others are // notified so that everything is cleaned up properly. - RemovePendingRequest(info->child_id, info->request_id); + RemovePendingRequest(info->child_id(), info->request_id()); } else { i->second->Cancel(); } @@ -1230,12 +1237,12 @@ int ResourceDispatcherHost::CalculateApproximateMemoryCost( void ResourceDispatcherHost::BeginRequestInternal(URLRequest* request) { DCHECK(!request->is_pending()); - ExtraRequestInfo* info = ExtraInfoForRequest(request); + ResourceDispatcherHostRequestInfo* info = InfoForRequest(request); // Add the memory estimate that starting this request will consume. - info->memory_cost = CalculateApproximateMemoryCost(request); - int memory_cost = IncrementOutstandingRequestsMemoryCost(info->memory_cost, - info->child_id); + info->set_memory_cost(CalculateApproximateMemoryCost(request)); + int memory_cost = IncrementOutstandingRequestsMemoryCost(info->memory_cost(), + info->child_id()); // If enqueing/starting this request will exceed our per-process memory // bound, abort it right away. @@ -1246,13 +1253,13 @@ void ResourceDispatcherHost::BeginRequestInternal(URLRequest* request) { // TODO(eroman): this is kinda funky -- we insert the unstarted request into // |pending_requests_| simply to please OnResponseCompleted(). - GlobalRequestID global_id(info->child_id, info->request_id); + GlobalRequestID global_id(info->child_id(), info->request_id()); pending_requests_[global_id] = request; OnResponseCompleted(request); return; } - std::pair<int, int> pair_id(info->child_id, info->route_id); + std::pair<int, int> pair_id(info->child_id(), info->route_id()); BlockedRequestMap::const_iterator iter = blocked_requests_map_.find(pair_id); if (iter != blocked_requests_map_.end()) { // The request should be blocked. @@ -1260,7 +1267,7 @@ void ResourceDispatcherHost::BeginRequestInternal(URLRequest* request) { return; } - GlobalRequestID global_id(info->child_id, info->request_id); + GlobalRequestID global_id(info->child_id(), info->request_id()); pending_requests_[global_id] = request; if (!SSLManager::ShouldStartRequest(this, request, ui_loop_)) { // The SSLManager has told us that we shouldn't start the request yet. The @@ -1283,11 +1290,11 @@ void ResourceDispatcherHost::BeginRequestInternal(URLRequest* request) { } } -bool ResourceDispatcherHost::PauseRequestIfNeeded(ExtraRequestInfo* info) { - if (info->pause_count > 0) - info->is_paused = true; - - return info->is_paused; +bool ResourceDispatcherHost::PauseRequestIfNeeded( + ResourceDispatcherHostRequestInfo* info) { + if (info->pause_count() > 0) + info->set_is_paused(true); + return info->is_paused(); } void ResourceDispatcherHost::ResumeRequest(const GlobalRequestID& request_id) { @@ -1296,17 +1303,17 @@ void ResourceDispatcherHost::ResumeRequest(const GlobalRequestID& request_id) { return; URLRequest* request = i->second; - ExtraRequestInfo* info = ExtraInfoForRequest(request); - if (!info->is_paused) + ResourceDispatcherHostRequestInfo* info = InfoForRequest(request); + if (!info->is_paused()) return; RESOURCE_LOG("Resuming: " << i->second->url().spec()); - info->is_paused = false; + info->set_is_paused(false); - if (info->called_on_response_started) { - if (info->has_started_reading) { - OnReadCompleted(i->second, info->paused_read_bytes); + if (info->called_on_response_started()) { + if (info->has_started_reading()) { + OnReadCompleted(i->second, info->paused_read_bytes()); } else { StartReading(request); } @@ -1321,27 +1328,27 @@ void ResourceDispatcherHost::StartReading(URLRequest* request) { if (Read(request, &bytes_read)) { OnReadCompleted(request, bytes_read); } else if (!request->status().is_io_pending()) { - DCHECK(!ExtraInfoForRequest(request)->is_paused); + DCHECK(!InfoForRequest(request)->is_paused()); // If the error is not an IO pending, then we're done reading. OnResponseCompleted(request); } } bool ResourceDispatcherHost::Read(URLRequest* request, int* bytes_read) { - ExtraRequestInfo* info = ExtraInfoForRequest(request); - DCHECK(!info->is_paused); + ResourceDispatcherHostRequestInfo* info = InfoForRequest(request); + DCHECK(!info->is_paused()); net::IOBuffer* buf; int buf_size; - if (!info->resource_handler->OnWillRead(info->request_id, - &buf, &buf_size, -1)) { + if (!info->resource_handler()->OnWillRead(info->request_id(), + &buf, &buf_size, -1)) { return false; } DCHECK(buf); DCHECK(buf_size > 0); - info->has_started_reading = true; + info->set_has_started_reading(true); return request->Read(buf, buf_size, bytes_read); } @@ -1349,9 +1356,9 @@ void ResourceDispatcherHost::OnReadCompleted(URLRequest* request, int bytes_read) { DCHECK(request); RESOURCE_LOG("OnReadCompleted: " << request->url().spec()); - ExtraRequestInfo* info = ExtraInfoForRequest(request); + ResourceDispatcherHostRequestInfo* info = InfoForRequest(request); if (PauseRequestIfNeeded(info)) { - info->paused_read_bytes = bytes_read; + info->set_paused_read_bytes(bytes_read); RESOURCE_LOG("OnReadCompleted pausing: " << request->url().spec()); return; } @@ -1359,7 +1366,7 @@ void ResourceDispatcherHost::OnReadCompleted(URLRequest* request, if (request->status().is_success() && CompleteRead(request, &bytes_read)) { // The request can be paused if we realize that the renderer is not // servicing messages fast enough. - if (info->pause_count == 0 && + if (info->pause_count() == 0 && Read(request, &bytes_read) && request->status().is_success()) { if (bytes_read == 0) { @@ -1368,9 +1375,9 @@ void ResourceDispatcherHost::OnReadCompleted(URLRequest* request, // Force the next CompleteRead / Read pair to run as a separate task. // This avoids a fast, large network request from monopolizing the IO // thread and starving other IO operations from running. - info->paused_read_bytes = bytes_read; - info->is_paused = true; - GlobalRequestID id(info->child_id, info->request_id); + info->set_paused_read_bytes(bytes_read); + info->set_is_paused(true); + GlobalRequestID id(info->child_id(), info->request_id()); MessageLoop::current()->PostTask( FROM_HERE, method_runner_.NewRunnableMethod( @@ -1381,7 +1388,7 @@ void ResourceDispatcherHost::OnReadCompleted(URLRequest* request, } if (PauseRequestIfNeeded(info)) { - info->paused_read_bytes = bytes_read; + info->set_paused_read_bytes(bytes_read); RESOURCE_LOG("OnReadCompleted (CompleteRead) pausing: " << request->url().spec()); return; @@ -1400,13 +1407,13 @@ bool ResourceDispatcherHost::CompleteRead(URLRequest* request, return false; } - ExtraRequestInfo* info = ExtraInfoForRequest(request); - - if (!info->resource_handler->OnReadCompleted(info->request_id, bytes_read)) { + ResourceDispatcherHostRequestInfo* info = InfoForRequest(request); + if (!info->resource_handler()->OnReadCompleted(info->request_id(), + bytes_read)) { // Pass in false as the last arg to indicate we don't want |request| // deleted. We do this as callers of us assume |request| is valid after we // return. - CancelRequest(info->child_id, info->request_id, false, false); + CancelRequest(info->child_id(), info->request_id(), false, false); return false; } @@ -1415,43 +1422,45 @@ bool ResourceDispatcherHost::CompleteRead(URLRequest* request, void ResourceDispatcherHost::OnResponseCompleted(URLRequest* request) { RESOURCE_LOG("OnResponseCompleted: " << request->url().spec()); - ExtraRequestInfo* info = ExtraInfoForRequest(request); + ResourceDispatcherHostRequestInfo* info = InfoForRequest(request); std::string security_info; const net::SSLInfo& ssl_info = request->ssl_info(); if (ssl_info.cert != NULL) { int cert_id = CertStore::GetSharedInstance()->StoreCert(ssl_info.cert, - info->child_id); + info->child_id()); security_info = SSLManager::SerializeSecurityInfo(cert_id, ssl_info.cert_status, ssl_info.security_bits); } - if (info->resource_handler->OnResponseCompleted(info->request_id, - request->status(), - security_info)) { - NotifyResponseCompleted(request, info->child_id); + if (info->resource_handler()->OnResponseCompleted(info->request_id(), + request->status(), + security_info)) { + NotifyResponseCompleted(request, info->child_id()); // The request is complete so we can remove it. - RemovePendingRequest(info->child_id, info->request_id); + RemovePendingRequest(info->child_id(), info->request_id()); } // If the handler's OnResponseCompleted returns false, we are deferring the // call until later. We will notify the world and clean up when we resume. } // static -ResourceDispatcherHost::ExtraRequestInfo* -ResourceDispatcherHost::ExtraInfoForRequest(URLRequest* request) { +ResourceDispatcherHostRequestInfo* ResourceDispatcherHost::InfoForRequest( + URLRequest* request) { // Avoid writing this function twice by casting the cosnt version. const URLRequest* const_request = request; - return const_cast<ExtraRequestInfo*>(ExtraInfoForRequest(const_request)); + return const_cast<ResourceDispatcherHostRequestInfo*>( + InfoForRequest(const_request)); } // static -const ResourceDispatcherHost::ExtraRequestInfo* -ResourceDispatcherHost::ExtraInfoForRequest(const URLRequest* request) { - const ExtraRequestInfo* info = - static_cast<const ExtraRequestInfo*>(request->GetUserData(NULL)); +const ResourceDispatcherHostRequestInfo* ResourceDispatcherHost::InfoForRequest( + const URLRequest* request) { + const ResourceDispatcherHostRequestInfo* info = + static_cast<const ResourceDispatcherHostRequestInfo*>( + request->GetUserData(NULL)); DLOG_IF(WARNING, !info) << "Request doesn't seem to have our data"; return info; } @@ -1460,15 +1469,15 @@ ResourceDispatcherHost::ExtraInfoForRequest(const URLRequest* request) { bool ResourceDispatcherHost::RenderViewForRequest(const URLRequest* request, int* render_process_host_id, int* render_view_host_id) { - const ExtraRequestInfo* info = ExtraInfoForRequest(request); + const ResourceDispatcherHostRequestInfo* info = InfoForRequest(request); if (!info) { *render_process_host_id = -1; *render_view_host_id = -1; return false; } - *render_process_host_id = info->child_id; - *render_view_host_id = info->route_id; + *render_process_host_id = info->child_id(); + *render_view_host_id = info->route_id(); return true; } @@ -1602,16 +1611,16 @@ void ResourceDispatcherHost::UpdateLoadStates() { for (i = pending_requests_.begin(); i != pending_requests_.end(); ++i) { URLRequest* request = i->second; net::LoadState load_state = request->GetLoadState(); - ExtraRequestInfo* info = ExtraInfoForRequest(request); + ResourceDispatcherHostRequestInfo* info = InfoForRequest(request); // We also poll for upload progress on this timer and send upload // progress ipc messages to the plugin process. MaybeUpdateUploadProgress(info, request); - if (info->last_load_state != load_state) { - info->last_load_state = load_state; + if (info->last_load_state() != load_state) { + info->set_last_load_state(load_state); - std::pair<int, int> key(info->child_id, info->route_id); + std::pair<int, int> key(info->child_id(), info->route_id()); net::LoadState to_insert; LoadInfoMap::iterator existing = info_map.find(key); if (existing == info_map.end()) { @@ -1636,37 +1645,38 @@ void ResourceDispatcherHost::UpdateLoadStates() { ui_loop_->PostTask(FROM_HERE, task); } -void ResourceDispatcherHost::MaybeUpdateUploadProgress(ExtraRequestInfo *info, - URLRequest *request) { - if (!info->upload_size || info->waiting_for_upload_progress_ack || +void ResourceDispatcherHost::MaybeUpdateUploadProgress( + ResourceDispatcherHostRequestInfo *info, + URLRequest *request) { + if (!info->upload_size() || info->waiting_for_upload_progress_ack() || !(request->load_flags() & net::LOAD_ENABLE_UPLOAD_PROGRESS)) return; - uint64 size = info->upload_size; + uint64 size = info->upload_size(); uint64 position = request->GetUploadProgress(); - if (position == info->last_upload_position) + if (position == info->last_upload_position()) return; // no progress made since last time const uint64 kHalfPercentIncrements = 200; const TimeDelta kOneSecond = TimeDelta::FromMilliseconds(1000); - uint64 amt_since_last = position - info->last_upload_position; - TimeDelta time_since_last = TimeTicks::Now() - info->last_upload_ticks; + uint64 amt_since_last = position - info->last_upload_position(); + TimeDelta time_since_last = TimeTicks::Now() - info->last_upload_ticks(); bool is_finished = (size == position); bool enough_new_progress = (amt_since_last > (size / kHalfPercentIncrements)); bool too_much_time_passed = time_since_last > kOneSecond; if (is_finished || enough_new_progress || too_much_time_passed) { - info->resource_handler->OnUploadProgress(info->request_id, position, size); - info->waiting_for_upload_progress_ack = true; - info->last_upload_ticks = TimeTicks::Now(); - info->last_upload_position = position; + info->resource_handler()->OnUploadProgress(info->request_id(), + position, size); + info->set_waiting_for_upload_progress_ack(true); + info->set_last_upload_ticks(TimeTicks::Now()); + info->set_last_upload_position(position); } } -void ResourceDispatcherHost::BlockRequestsForRoute(int child_id, - int route_id) { +void ResourceDispatcherHost::BlockRequestsForRoute(int child_id, int route_id) { std::pair<int, int> key(child_id, route_id); DCHECK(blocked_requests_map_.find(key) == blocked_requests_map_.end()) << "BlockRequestsForRoute called multiple time for the same RVH"; @@ -1705,9 +1715,9 @@ void ResourceDispatcherHost::ProcessBlockedRequestsForRoute( // Remove the memory credit that we added when pushing the request onto // the blocked list. URLRequest* request = *req_iter; - ExtraRequestInfo* info = ExtraInfoForRequest(request); - IncrementOutstandingRequestsMemoryCost(-1 * info->memory_cost, - info->child_id); + ResourceDispatcherHostRequestInfo* info = InfoForRequest(request); + IncrementOutstandingRequestsMemoryCost(-1 * info->memory_cost(), + info->child_id()); if (cancel_requests) delete request; else diff --git a/chrome/browser/renderer_host/resource_dispatcher_host.h b/chrome/browser/renderer_host/resource_dispatcher_host.h index 1bd2441..98f59fe 100644 --- a/chrome/browser/renderer_host/resource_dispatcher_host.h +++ b/chrome/browser/renderer_host/resource_dispatcher_host.h @@ -23,7 +23,6 @@ #include "base/timer.h" #include "chrome/browser/renderer_host/resource_handler.h" #include "chrome/common/child_process_info.h" -#include "chrome/common/filter_policy.h" #include "ipc/ipc_message.h" #include "net/url_request/url_request.h" #include "webkit/glue/resource_type.h" @@ -34,6 +33,7 @@ class DownloadRequestManager; class LoginHandler; class MessageLoop; class PluginService; +class ResourceDispatcherHostRequestInfo; class SafeBrowsingService; class SaveFileManager; class SSLClientAuthHandler; @@ -72,125 +72,6 @@ class ResourceDispatcherHost : public URLRequest::Delegate { virtual ~Receiver() {} }; - // Holds the data we would like to associate with each request - class ExtraRequestInfo : public URLRequest::UserData { - friend class ResourceDispatcherHost; - public: - ExtraRequestInfo(ResourceHandler* handler, - ChildProcessInfo::ProcessType process_type, - int child_id, - int route_id, - int request_id, - std::string frame_origin, - std::string main_frame_origin, - ResourceType::Type resource_type, - uint64 upload_size) - : resource_handler(handler), - cross_site_handler(NULL), - login_handler(NULL), - ssl_client_auth_handler(NULL), - process_type(process_type), - child_id(child_id), - route_id(route_id), - request_id(request_id), - pending_data_count(0), - is_download(false), - pause_count(0), - frame_origin(frame_origin), - main_frame_origin(main_frame_origin), - resource_type(resource_type), - filter_policy(FilterPolicy::DONT_FILTER), - last_load_state(net::LOAD_STATE_IDLE), - upload_size(upload_size), - last_upload_position(0), - waiting_for_upload_progress_ack(false), - memory_cost(0), - is_paused(false), - called_on_response_started(false), - has_started_reading(false), - paused_read_bytes(0) { - } - virtual ~ExtraRequestInfo() { resource_handler->OnRequestClosed(); } - - // Top-level ResourceHandler servicing this request. - scoped_refptr<ResourceHandler> resource_handler; - - // CrossSiteResourceHandler for this request, if it is a cross-site request. - // (NULL otherwise.) This handler is part of the chain of ResourceHandlers - // pointed to by resource_handler. - CrossSiteResourceHandler* cross_site_handler; - - LoginHandler* login_handler; - - SSLClientAuthHandler* ssl_client_auth_handler; - - ChildProcessInfo::ProcessType process_type; - - // The child process unique ID of the requestor. This duplicates the value - // stored on the request by SetChildProcessUniqueIDForRequest in - // url_request_tracking. - int child_id; - - int route_id; - - int request_id; - - int pending_data_count; - - // Downloads allowed only as a top level request. - bool allow_download; - - // Whether this is a download. - bool is_download; - - // The number of clients that have called pause on this request. - int pause_count; - - // The security origin of the frame making this request. - std::string frame_origin; - - // The security origin of the main frame that contains the frame making - // this request. - std::string main_frame_origin; - - ResourceType::Type resource_type; - - // Whether the content for this request should be filtered (on the renderer - // side) to make it more secure: images are stamped, frame content is - // replaced with an error message and all other resources are entirely - // filtered out. - FilterPolicy::Type filter_policy; - - net::LoadState last_load_state; - - uint64 upload_size; - - uint64 last_upload_position; - - base::TimeTicks last_upload_ticks; - - bool waiting_for_upload_progress_ack; - - // The approximate in-memory size (bytes) that we credited this request - // as consuming in |outstanding_requests_memory_cost_map_|. - int memory_cost; - - private: - // Request is temporarily not handling network data. Should be used only - // by the ResourceDispatcherHost, not the event handlers. - bool is_paused; - - // Whether we called OnResponseStarted for this request or not. - bool called_on_response_started; - - // Whether this request has started reading any bytes from the response - // yet. Will be true after the first (unpaused) call to Read. - bool has_started_reading; - - // How many bytes have been read while this request has been paused. - int paused_read_bytes; - }; - class Observer { public: virtual ~Observer() {} @@ -340,8 +221,9 @@ class ResourceDispatcherHost : public URLRequest::Delegate { // Helper functions to get our extra data out of a request. The given request // must have been one we created so that it has the proper extra data pointer. - static ExtraRequestInfo* ExtraInfoForRequest(URLRequest* request); - static const ExtraRequestInfo* ExtraInfoForRequest(const URLRequest* request); + static ResourceDispatcherHostRequestInfo* InfoForRequest(URLRequest* request); + static const ResourceDispatcherHostRequestInfo* InfoForRequest( + const URLRequest* request); // Extracts the render view/process host's identifiers from the given request // and places them in the given out params (both required). If there are no @@ -409,15 +291,16 @@ class ResourceDispatcherHost : public URLRequest::Delegate { friend class ShutdownTask; - void SetExtraInfoForRequest(URLRequest* request, ExtraRequestInfo* info) { - request->SetUserData(NULL, info); - } + // Associates the given info with the given request. The info will then be + // owned by the request. + void SetRequestInfo(URLRequest* request, + ResourceDispatcherHostRequestInfo* info); // A shutdown helper that runs on the IO thread. void OnShutdown(); // Returns true if the request is paused. - bool PauseRequestIfNeeded(ExtraRequestInfo* info); + bool PauseRequestIfNeeded(ResourceDispatcherHostRequestInfo* info); // Resumes the given request by calling OnResponseStarted or OnReadCompleted. void ResumeRequest(const GlobalRequestID& request_id); @@ -493,9 +376,13 @@ class ResourceDispatcherHost : public URLRequest::Delegate { ResourceType::Type resource_type, ResourceHandler* handler); + // Checks all pending requests and updates the load states and upload + // progress if necessary. void UpdateLoadStates(); - void MaybeUpdateUploadProgress(ExtraRequestInfo *info, URLRequest *request); + // Checks the upload state and sends an update if one is necessary. + void MaybeUpdateUploadProgress(ResourceDispatcherHostRequestInfo *info, + URLRequest *request); // Resumes or cancels (if |cancel_requests| is true) any blocked requests. void ProcessBlockedRequestsForRoute(int process_unique_id, diff --git a/chrome/browser/renderer_host/resource_dispatcher_host_request_info.cc b/chrome/browser/renderer_host/resource_dispatcher_host_request_info.cc new file mode 100644 index 0000000..bd488e7 --- /dev/null +++ b/chrome/browser/renderer_host/resource_dispatcher_host_request_info.cc @@ -0,0 +1,50 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/renderer_host/resource_dispatcher_host_request_info.h" + +#include "chrome/browser/renderer_host/resource_handler.h" + +ResourceDispatcherHostRequestInfo::ResourceDispatcherHostRequestInfo( + ResourceHandler* handler, + ChildProcessInfo::ProcessType process_type, + int child_id, + int route_id, + int request_id, + const std::string& frame_origin, + const std::string& main_frame_origin, + ResourceType::Type resource_type, + uint64 upload_size, + bool is_download, + bool allow_download) + : resource_handler_(handler), + cross_site_handler_(NULL), + login_handler_(NULL), + ssl_client_auth_handler_(NULL), + process_type_(process_type), + child_id_(child_id), + route_id_(route_id), + request_id_(request_id), + pending_data_count_(0), + is_download_(is_download), + allow_download_(allow_download), + pause_count_(0), + frame_origin_(frame_origin), + main_frame_origin_(main_frame_origin), + resource_type_(resource_type), + filter_policy_(FilterPolicy::DONT_FILTER), + last_load_state_(net::LOAD_STATE_IDLE), + upload_size_(upload_size), + last_upload_position_(0), + waiting_for_upload_progress_ack_(false), + memory_cost_(0), + is_paused_(false), + called_on_response_started_(false), + has_started_reading_(false), + paused_read_bytes_(0) { +} + +ResourceDispatcherHostRequestInfo::~ResourceDispatcherHostRequestInfo() { + resource_handler_->OnRequestClosed(); +} diff --git a/chrome/browser/renderer_host/resource_dispatcher_host_request_info.h b/chrome/browser/renderer_host/resource_dispatcher_host_request_info.h new file mode 100644 index 0000000..fd0c322 --- /dev/null +++ b/chrome/browser/renderer_host/resource_dispatcher_host_request_info.h @@ -0,0 +1,225 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_RENDERER_HOST_RESOURCE_DISPATCHER_HOST_REQUEST_INFO_H_ +#define CHROME_BROWSER_RENDERER_HOST_RESOURCE_DISPATCHER_HOST_REQUEST_INFO_H_ + +#include <string> + +#include "base/basictypes.h" +#include "base/time.h" +#include "chrome/common/child_process_info.h" +#include "chrome/common/filter_policy.h" +#include "net/base/load_states.h" +#include "net/url_request/url_request.h" +#include "webkit/glue/resource_type.h" + +class CrossSiteResourceHandler; +class LoginHandler; +class ResourceDispatcherHost; +class ResourceHandler; +class SSLClientAuthHandler; + +// Holds the data ResourceDispatcherHost associates with each request. +// Retrieve this data by calling ResourceDispatcherHost::InfoForRequest. +class ResourceDispatcherHostRequestInfo : public URLRequest::UserData { + public: + // This will take a reference to the handler. + ResourceDispatcherHostRequestInfo( + ResourceHandler* handler, + ChildProcessInfo::ProcessType process_type, + int child_id, + int route_id, + int request_id, + const std::string& frame_origin, + const std::string& main_frame_origin, + ResourceType::Type resource_type, + uint64 upload_size, + bool is_download, + bool allow_download); + virtual ~ResourceDispatcherHostRequestInfo(); + + // Top-level ResourceHandler servicing this request. + ResourceHandler* resource_handler() { return resource_handler_.get(); } + + // CrossSiteResourceHandler for this request, if it is a cross-site request. + // (NULL otherwise.) This handler is part of the chain of ResourceHandlers + // pointed to by resource_handler, and is not owned by this class. + CrossSiteResourceHandler* cross_site_handler() { + return cross_site_handler_; + } + void set_cross_site_handler(CrossSiteResourceHandler* h) { + cross_site_handler_ = h; + } + + // Pointer to the login handler, or NULL if there is none for this request. + // This is a NON-OWNING pointer, and the caller is resounsible for the + // pointer after calling set. + LoginHandler* login_handler() const { return login_handler_; } + void set_login_handler(LoginHandler* lh) { login_handler_ = lh; } + + // Pointer to the SSL auth, or NULL if there is none for this request. + // This is a NON-OWNING pointer, and the caller is resounsible for the + // pointer after calling set. + SSLClientAuthHandler* ssl_client_auth_handler() const { + return ssl_client_auth_handler_; + } + void set_ssl_client_auth_handler(SSLClientAuthHandler* s) { + ssl_client_auth_handler_ = s; + } + + // Identifies the type of process (renderer, plugin, etc.) making the request. + ChildProcessInfo::ProcessType process_type() const { + return process_type_; + } + + // The child process unique ID of the requestor. This duplicates the value + // stored on the request by SetChildProcessUniqueIDForRequest in + // url_request_tracking. + int child_id() const { return child_id_; } + + // The IPC route identifier for this request (this identifies the RenderView + // or like-thing in the renderer that the request gets routed to). + int route_id() const { return route_id_; } + + // Unique identifier for this resource request. + int request_id() const { return request_id_; } + + // Number of messages we've sent to the renderer that we haven't gotten an + // ACK for. This allows us to avoid having too many messages in flight. + int pending_data_count() const { return pending_data_count_; } + void IncrementPendingDataCount() { pending_data_count_++; } + void DecrementPendingDataCount() { pending_data_count_--; } + + // Downloads are allowed only as a top level request. + bool allow_download() const { return allow_download_; } + + // Whether this is a download. + bool is_download() const { return is_download_; } + void set_is_download(bool download) { is_download_ = download; } + + // The number of clients that have called pause on this request. + int pause_count() const { return pause_count_; } + void set_pause_count(int count) { pause_count_ = count; } + + // The security origin of the frame making this request. + const std::string& frame_origin() const { return frame_origin_; } + + // The security origin of the main frame that contains the frame making + // this request. + const std::string& main_frame_origin() const { return main_frame_origin_; } + + // Identifies the type of resource, such as subframe, media, etc. + ResourceType::Type resource_type() const { return resource_type_; } + + // Whether the content for this request should be filtered (on the renderer + // side) to make it more secure: images are stamped, frame content is + // replaced with an error message and all other resources are entirely + // filtered out. + FilterPolicy::Type filter_policy() const { return filter_policy_; } + void set_filter_policy(FilterPolicy::Type policy) { filter_policy_ = policy; } + + // Returns the last updated state of the load. This is updated periodically + // by the ResourceDispatcherHost and tracked here so we don't send out + // unnecessary state change notifications. + net::LoadState last_load_state() const { return last_load_state_; } + void set_last_load_state(net::LoadState s) { last_load_state_ = s; } + + // When there is upload data, this is the byte count of that data. When there + // is no upload, this will be 0. + uint64 upload_size() const { return upload_size_; } + + // When we're uploading data, this is the the byte offset into the uploaded + // data that we've uploaded that we've send an upload progress update about. + // The ResourceDispatcherHost will periodically update this value to track + // upload progress and make sure it doesn't sent out duplicate updates. + uint64 last_upload_position() const { return last_upload_position_; } + void set_last_upload_position(uint64 p) { last_upload_position_ = p; } + + // Indicates when the ResourceDispatcherHost last update the upload + // position. This is used to make sure we don't send too many updates. + base::TimeTicks last_upload_ticks() const { return last_upload_ticks_; } + void set_last_upload_ticks(base::TimeTicks t) { last_upload_ticks_ = t; } + + // Set when the ResourceDispatcherHost has sent out an upload progress, and + // cleared whtn the ACK is received. This is used to throttle updates so + // multiple updates aren't in flight at once. + bool waiting_for_upload_progress_ack() const { + return waiting_for_upload_progress_ack_; + } + void set_waiting_for_upload_progress_ack(bool waiting) { + waiting_for_upload_progress_ack_ = waiting; + } + + // The approximate in-memory size (bytes) that we credited this request + // as consuming in |outstanding_requests_memory_cost_map_|. + int memory_cost() const { return memory_cost_; } + void set_memory_cost(int cost) { memory_cost_ = cost; } + + private: + friend class ResourceDispatcherHost; + + // Request is temporarily not handling network data. Should be used only + // by the ResourceDispatcherHost, not the event handlers (accessors are + // provided for consistency with the rest of the interface). + bool is_paused() const { return is_paused_; } + void set_is_paused(bool paused) { is_paused_ = paused; } + + // Whether we called OnResponseStarted for this request or not. Should be used + // only by the ResourceDispatcherHost, not the event handlers (accessors are + // provided for consistency with the rest of the interface). + bool called_on_response_started() const { + return called_on_response_started_; + } + void set_called_on_response_started(bool called) { + called_on_response_started_ = called; + } + + // Whether this request has started reading any bytes from the response + // yet. Will be true after the first (unpaused) call to Read. Should be used + // only by the ResourceDispatcherHost, not the event handlers (accessors are + // provided for consistency with the rest of the interface). + bool has_started_reading() const { return has_started_reading_; } + void set_has_started_reading(bool reading) { has_started_reading_ = reading; } + + // How many bytes have been read while this request has been paused. Should be + // used only by the ResourceDispatcherHost, not the event handlers (accessors + // are provided for consistency with the rest of the interface). + int paused_read_bytes() const { return paused_read_bytes_; } + void set_paused_read_bytes(int bytes) { paused_read_bytes_ = bytes; } + + scoped_refptr<ResourceHandler> resource_handler_; + CrossSiteResourceHandler* cross_site_handler_; // Non-owning, may be NULL. + LoginHandler* login_handler_; // Non-owning, may be NULL. + SSLClientAuthHandler* ssl_client_auth_handler_; // Non-owning, may be NULL. + ChildProcessInfo::ProcessType process_type_; + int child_id_; + int route_id_; + int request_id_; + int pending_data_count_; + bool is_download_; + bool allow_download_; + int pause_count_; + std::string frame_origin_; + std::string main_frame_origin_; + ResourceType::Type resource_type_; + FilterPolicy::Type filter_policy_; + net::LoadState last_load_state_; + uint64 upload_size_; + uint64 last_upload_position_; + base::TimeTicks last_upload_ticks_; + bool waiting_for_upload_progress_ack_; + int memory_cost_; + + // "Private" data accessible only to ResourceDispatcherHost (use the + // accessors above for consistency). + bool is_paused_; + bool called_on_response_started_; + bool has_started_reading_; + int paused_read_bytes_; + + DISALLOW_COPY_AND_ASSIGN(ResourceDispatcherHostRequestInfo); +}; + +#endif // CHROME_BROWSER_RENDERER_HOST_RESOURCE_DISPATCHER_HOST_REQUEST_INFO_H_ diff --git a/chrome/browser/renderer_host/resource_request_details.h b/chrome/browser/renderer_host/resource_request_details.h index e08e0b2..e7e1c02 100644 --- a/chrome/browser/renderer_host/resource_request_details.h +++ b/chrome/browser/renderer_host/resource_request_details.h @@ -13,6 +13,7 @@ #include "chrome/browser/cert_store.h" #include "chrome/browser/renderer_host/resource_dispatcher_host.h" +#include "chrome/browser/renderer_host/resource_dispatcher_host_request_info.h" #include "googleurl/src/gurl.h" #include "net/url_request/url_request_status.h" @@ -31,14 +32,14 @@ class ResourceRequestDetails { status_(request->status()), ssl_cert_id_(cert_id), ssl_cert_status_(request->ssl_info().cert_status) { - const ResourceDispatcherHost::ExtraRequestInfo* info = - ResourceDispatcherHost::ExtraInfoForRequest(request); + const ResourceDispatcherHostRequestInfo* info = + ResourceDispatcherHost::InfoForRequest(request); DCHECK(info); - resource_type_ = info->resource_type; - frame_origin_ = info->frame_origin; - main_frame_origin_ = info->main_frame_origin; - filter_policy_ = info->filter_policy; - origin_child_id_ = info->child_id; + resource_type_ = info->resource_type(); + frame_origin_ = info->frame_origin(); + main_frame_origin_ = info->main_frame_origin(); + filter_policy_ = info->filter_policy(); + origin_child_id_ = info->child_id(); } virtual ~ResourceRequestDetails() {} diff --git a/chrome/browser/ssl/ssl_error_handler.cc b/chrome/browser/ssl/ssl_error_handler.cc index ed04c6fb..13fce6c 100644 --- a/chrome/browser/ssl/ssl_error_handler.cc +++ b/chrome/browser/ssl/ssl_error_handler.cc @@ -6,6 +6,7 @@ #include "base/message_loop.h" #include "chrome/browser/renderer_host/resource_dispatcher_host.h" +#include "chrome/browser/renderer_host/resource_dispatcher_host_request_info.h" #include "chrome/browser/ssl/ssl_cert_error_handler.h" #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/browser/tab_contents/tab_util.h" @@ -30,10 +31,10 @@ SSLErrorHandler::SSLErrorHandler(ResourceDispatcherHost* rdh, request_has_been_notified_(false) { DCHECK(MessageLoop::current() != ui_loop); - ResourceDispatcherHost::ExtraRequestInfo* info = - ResourceDispatcherHost::ExtraInfoForRequest(request); - request_id_.child_id = info->child_id; - request_id_.request_id = info->request_id; + ResourceDispatcherHostRequestInfo* info = + ResourceDispatcherHost::InfoForRequest(request); + request_id_.child_id = info->child_id(); + request_id_.request_id = info->request_id(); if (!ResourceDispatcherHost::RenderViewForRequest(request, &render_process_host_id_, @@ -178,9 +179,9 @@ void SSLErrorHandler::CompleteStartRequest(FilterPolicy::Type filter_policy) { DLOG(INFO) << "CompleteStartRequest() url: " << request->url().spec(); // The request should not have been started (SUCCESS is the initial state). DCHECK(request->status().status() == URLRequestStatus::SUCCESS); - ResourceDispatcherHost::ExtraRequestInfo* info = - ResourceDispatcherHost::ExtraInfoForRequest(request); - info->filter_policy = filter_policy; + ResourceDispatcherHostRequestInfo* info = + ResourceDispatcherHost::InfoForRequest(request); + info->set_filter_policy(filter_policy); request->Start(); } request_has_been_notified_ = true; diff --git a/chrome/browser/ssl/ssl_manager.cc b/chrome/browser/ssl/ssl_manager.cc index 63e590d..73c3b02 100644 --- a/chrome/browser/ssl/ssl_manager.cc +++ b/chrome/browser/ssl/ssl_manager.cc @@ -69,8 +69,8 @@ void SSLManager::OnSSLCertificateError(ResourceDispatcherHost* rdh, DLOG(INFO) << "OnSSLCertificateError() cert_error: " << cert_error << " url: " << request->url().spec(); - ResourceDispatcherHost::ExtraRequestInfo* info = - ResourceDispatcherHost::ExtraInfoForRequest(request); + ResourceDispatcherHostRequestInfo* info = + ResourceDispatcherHost::InfoForRequest(request); DCHECK(info); // A certificate error occurred. Construct a SSLCertErrorHandler object and @@ -78,9 +78,9 @@ void SSLManager::OnSSLCertificateError(ResourceDispatcherHost* rdh, ui_loop->PostTask(FROM_HERE, NewRunnableMethod(new SSLCertErrorHandler(rdh, request, - info->resource_type, - info->frame_origin, - info->main_frame_origin, + info->resource_type(), + info->frame_origin(), + info->main_frame_origin(), cert_error, cert, ui_loop), @@ -91,26 +91,26 @@ void SSLManager::OnSSLCertificateError(ResourceDispatcherHost* rdh, bool SSLManager::ShouldStartRequest(ResourceDispatcherHost* rdh, URLRequest* request, MessageLoop* ui_loop) { - ResourceDispatcherHost::ExtraRequestInfo* info = - ResourceDispatcherHost::ExtraInfoForRequest(request); + ResourceDispatcherHostRequestInfo* info = + ResourceDispatcherHost::InfoForRequest(request); DCHECK(info); // We cheat here and talk to the SSLPolicy on the IO thread because we need // to respond synchronously to avoid delaying all network requests... if (!SSLPolicy::IsMixedContent(request->url(), - info->resource_type, - info->filter_policy, - info->frame_origin)) + info->resource_type(), + info->filter_policy(), + info->frame_origin())) return true; ui_loop->PostTask(FROM_HERE, NewRunnableMethod(new SSLMixedContentHandler(rdh, request, - info->resource_type, - info->frame_origin, - info->main_frame_origin, - info->child_id, + info->resource_type(), + info->frame_origin(), + info->main_frame_origin(), + info->child_id(), ui_loop), &SSLMixedContentHandler::Dispatch)); return false; diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp index b16ac73..edb89cc 100644 --- a/chrome/chrome.gyp +++ b/chrome/chrome.gyp @@ -1661,6 +1661,8 @@ 'browser/renderer_host/render_widget_host_view_win.h', 'browser/renderer_host/resource_dispatcher_host.cc', 'browser/renderer_host/resource_dispatcher_host.h', + 'browser/renderer_host/resource_dispatcher_host_request_info.cc', + 'browser/renderer_host/resource_dispatcher_host_request_info.h', 'browser/renderer_host/resource_handler.h', 'browser/renderer_host/resource_message_filter.cc', 'browser/renderer_host/resource_message_filter.h', |