diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-30 22:25:37 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-30 22:25:37 +0000 |
commit | 336870f3ec778c3677edc16395aaaa042f05e140 (patch) | |
tree | 0efe3357e2464be8f6a6843cebe6c671a9d3ceb2 /chrome/browser | |
parent | da71fd2d44c8f5367de6b921948d9e19bdf58b8d (diff) | |
download | chromium_src-336870f3ec778c3677edc16395aaaa042f05e140.zip chromium_src-336870f3ec778c3677edc16395aaaa042f05e140.tar.gz chromium_src-336870f3ec778c3677edc16395aaaa042f05e140.tar.bz2 |
Move GetTabContentsID out of tab util because it has nothing to do with tabs or
TabContents. I put a more accurately named static function in
ResourceDispatcherHost which is what really controls this request data.
I also moved a couple of static functions from the header to the cc in
resource_dispatcher.
Review URL: http://codereview.chromium.org/150124
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@19675 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/login_prompt_gtk.cc | 7 | ||||
-rw-r--r-- | chrome/browser/login_prompt_win.cc | 6 | ||||
-rw-r--r-- | chrome/browser/renderer_host/resource_dispatcher_host.cc | 37 | ||||
-rw-r--r-- | chrome/browser/renderer_host/resource_dispatcher_host.h | 24 | ||||
-rw-r--r-- | chrome/browser/ssl/ssl_error_handler.cc | 7 | ||||
-rw-r--r-- | chrome/browser/tab_contents/tab_util.cc | 19 | ||||
-rw-r--r-- | chrome/browser/tab_contents/tab_util.h | 5 | ||||
-rw-r--r-- | chrome/browser/task_manager.cc | 7 |
8 files changed, 62 insertions, 50 deletions
diff --git a/chrome/browser/login_prompt_gtk.cc b/chrome/browser/login_prompt_gtk.cc index 74d879e..b99c412 100644 --- a/chrome/browser/login_prompt_gtk.cc +++ b/chrome/browser/login_prompt_gtk.cc @@ -10,9 +10,9 @@ #include "base/message_loop.h" #include "chrome/browser/gtk/constrained_window_gtk.h" #include "chrome/browser/password_manager/password_manager.h" +#include "chrome/browser/renderer_host/resource_dispatcher_host.h" #include "chrome/browser/tab_contents/navigation_controller.h" #include "chrome/browser/tab_contents/tab_contents.h" -#include "chrome/browser/tab_contents/tab_util.h" #include "chrome/common/gtk_util.h" #include "chrome/common/notification_service.h" #include "grit/generated_resources.h" @@ -41,8 +41,9 @@ class LoginHandlerGtk : public LoginHandler, DCHECK(request_) << "LoginHandlerGtk constructed with NULL request"; AddRef(); // matched by ReleaseLater. - if (!tab_util::GetTabContentsID(request_, &render_process_host_id_, - &tab_contents_id_)) { + if (!ResourceDispatcherHost::RenderViewForRequest(request_, + &render_process_host_id_, + &tab_contents_id_)) { NOTREACHED(); } } diff --git a/chrome/browser/login_prompt_win.cc b/chrome/browser/login_prompt_win.cc index 4437737..b74024b 100644 --- a/chrome/browser/login_prompt_win.cc +++ b/chrome/browser/login_prompt_win.cc @@ -7,6 +7,7 @@ #include "app/l10n_util.h"
#include "base/message_loop.h"
#include "chrome/browser/password_manager/password_manager.h"
+#include "chrome/browser/renderer_host/resource_dispatcher_host.h" #include "chrome/browser/tab_contents/navigation_controller.h"
#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/browser/tab_contents/tab_util.h"
@@ -40,8 +41,9 @@ class LoginHandlerWin : public LoginHandler, DCHECK(request_) << "LoginHandler constructed with NULL request";
AddRef(); // matched by ReleaseLater.
- if (!tab_util::GetTabContentsID(request_, &render_process_host_id_,
- &tab_contents_id_)) {
+ if (!ResourceDispatcherHost::RenderViewForRequest(request_,
+ &render_process_host_id_,
+ &tab_contents_id_)) {
NOTREACHED();
}
}
diff --git a/chrome/browser/renderer_host/resource_dispatcher_host.cc b/chrome/browser/renderer_host/resource_dispatcher_host.cc index 8ffa2ca..b157622 100644 --- a/chrome/browser/renderer_host/resource_dispatcher_host.cc +++ b/chrome/browser/renderer_host/resource_dispatcher_host.cc @@ -1271,6 +1271,39 @@ void ResourceDispatcherHost::OnResponseCompleted(URLRequest* request) { // call until later. We will notify the world and clean up when we resume. } +// static +ResourceDispatcherHost::ExtraRequestInfo* +ResourceDispatcherHost::ExtraInfoForRequest(URLRequest* request) { + // Avoid writing this function twice by casting the cosnt version. + const URLRequest* const_request = request; + return const_cast<ExtraRequestInfo*>(ExtraRequestForRequest(const_request)); +} + +// static +const ResourceDispatcherHost::ExtraRequestInfo* +ResourceDispatcherHost::ExtraInfoForRequest(const URLRequest* request) { + const ExtraRequestInfo* info = + static_cast<const ExtraRequestInfo*>(request->GetUserData(NULL)); + DLOG_IF(WARNING, !info) << "Request doesn't seem to have our data"; + return info; +} + +// static +bool ResourceDispatcherHost::RenderViewForRequest(const URLRequest* request, + int* render_process_host_id, + int* render_view_host_id) { + const ExtraRequestInfo* info = ExtraInfoForRequest(request); + if (!info) { + *render_process_host_id = -1; + *render_view_host_id = -1; + return false; + } + + *render_process_host_id = info->process_id; + *render_view_host_id = info->route_id; + return true; +} + void ResourceDispatcherHost::AddObserver(Observer* obs) { observer_list_.AddObserver(obs); } @@ -1302,7 +1335,9 @@ class NotificationTask : public Task { ResourceRequestDetails* details) : type_(type), details_(details) { - if (!tab_util::GetTabContentsID(request, &process_id_, &tab_contents_id_)) + if (!ResourceDispatcherHost::RenderViewForRequest(request, + &process_id_, + &tab_contents_id_)) NOTREACHED(); } diff --git a/chrome/browser/renderer_host/resource_dispatcher_host.h b/chrome/browser/renderer_host/resource_dispatcher_host.h index ee07f53..03e59ff 100644 --- a/chrome/browser/renderer_host/resource_dispatcher_host.h +++ b/chrome/browser/renderer_host/resource_dispatcher_host.h @@ -323,20 +323,16 @@ 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) { - ExtraRequestInfo* info - = static_cast<ExtraRequestInfo*>(request->GetUserData(NULL)); - DLOG_IF(WARNING, !info) << "Request doesn't seem to have our data"; - return info; - } - - static const ExtraRequestInfo* ExtraInfoForRequest( - const URLRequest* request) { - const ExtraRequestInfo* info = - static_cast<const ExtraRequestInfo*>(request->GetUserData(NULL)); - DLOG_IF(WARNING, !info) << "Request doesn't seem to have our data"; - return info; - } + static ExtraRequestInfo* ExtraInfoForRequest(URLRequest* request); + static const ExtraRequestInfo* ExtraInfoForRequest(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 + // such IDs associated with the request (such as non-page-related requests), + // this function will return false and both out params will be -1. + static bool RenderViewForRequest(const URLRequest* request, + int* render_process_host_id, + int* render_view_host_id); // Adds an observer. The observer will be called on the IO thread. To // observe resource events on the UI thread, subscribe to the diff --git a/chrome/browser/ssl/ssl_error_handler.cc b/chrome/browser/ssl/ssl_error_handler.cc index 3319f26..b7f3fd2 100644 --- a/chrome/browser/ssl/ssl_error_handler.cc +++ b/chrome/browser/ssl/ssl_error_handler.cc @@ -5,6 +5,7 @@ #include "chrome/browser/ssl/ssl_error_handler.h" #include "base/message_loop.h" +#include "chrome/browser/renderer_host/resource_dispatcher_host.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" @@ -34,9 +35,9 @@ SSLErrorHandler::SSLErrorHandler(ResourceDispatcherHost* rdh, request_id_.process_id = info->process_id; request_id_.request_id = info->request_id; - if (!tab_util::GetTabContentsID(request, - &render_process_host_id_, - &tab_contents_id_)) + if (!ResourceDispatcherHost::RenderViewForRequest(request, + &render_process_host_id_, + &tab_contents_id_)) NOTREACHED(); // This makes sure we don't disappear on the IO thread until we've given an diff --git a/chrome/browser/tab_contents/tab_util.cc b/chrome/browser/tab_contents/tab_util.cc index 93b75fc..454ce39 100644 --- a/chrome/browser/tab_contents/tab_util.cc +++ b/chrome/browser/tab_contents/tab_util.cc @@ -6,26 +6,7 @@ #include "chrome/browser/renderer_host/render_process_host.h" #include "chrome/browser/renderer_host/render_view_host.h" -#include "chrome/browser/renderer_host/resource_dispatcher_host.h" #include "chrome/browser/tab_contents/tab_contents.h" -#include "net/url_request/url_request.h" - -bool tab_util::GetTabContentsID(URLRequest* request, - int* render_process_id, - int* render_view_id) { - - if (!request || !render_process_id || !render_view_id) - return false; - - ResourceDispatcherHost::ExtraRequestInfo* info = - ResourceDispatcherHost::ExtraInfoForRequest(request); - if (!info) - return false; - - *render_process_id = info->process_id; - *render_view_id = info->route_id; - return true; -} TabContents* tab_util::GetTabContentsByID(int render_process_id, int render_view_id) { diff --git a/chrome/browser/tab_contents/tab_util.h b/chrome/browser/tab_contents/tab_util.h index cbe9acd..2a19442 100644 --- a/chrome/browser/tab_contents/tab_util.h +++ b/chrome/browser/tab_contents/tab_util.h @@ -10,11 +10,6 @@ class TabContents; namespace tab_util { -// Helper to get the IDs necessary for looking up a TabContents. -// Should only be called from the IO thread, since it accesses an URLRequest. -bool GetTabContentsID(URLRequest* request, int* render_process_host_id, - int* routing_id); - // Helper to find the TabContents that originated the given request. Can be // NULL if the tab has been closed or some other error occurs. // Should only be called from the UI thread, since it accesses TabContent. diff --git a/chrome/browser/task_manager.cc b/chrome/browser/task_manager.cc index 0a671e3..d80d51c 100644 --- a/chrome/browser/task_manager.cc +++ b/chrome/browser/task_manager.cc @@ -14,8 +14,8 @@ #include "chrome/browser/browser_list.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/renderer_host/render_process_host.h" +#include "chrome/browser/renderer_host/resource_dispatcher_host.h" #include "chrome/browser/task_manager_resource_providers.h" -#include "chrome/browser/tab_contents/tab_util.h" #include "chrome/common/pref_names.h" #include "chrome/common/pref_service.h" #include "grit/app_resources.h" @@ -654,8 +654,9 @@ void TaskManagerModel::OnJobRedirect(URLRequestJob* job, void TaskManagerModel::OnBytesRead(URLRequestJob* job, int byte_count) { int render_process_host_id = -1, routing_id = -1; - tab_util::GetTabContentsID(job->request(), - &render_process_host_id, &routing_id); + ResourceDispatcherHost::RenderViewForRequest(job->request(), + &render_process_host_id, + &routing_id); // This happens in the IO thread, post it to the UI thread. ui_loop_->PostTask(FROM_HERE, NewRunnableMethod( |