Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(290)

Unified Diff: content/browser/browser_main_loop.cc

Issue 9150016: Move creation and ownership of ResourceDispatcherHost and PluginService to content. This gives a ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix chromeos ui_tests Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/browser_main_loop.cc
===================================================================
--- content/browser/browser_main_loop.cc (revision 117096)
+++ content/browser/browser_main_loop.cc (working copy)
@@ -13,7 +13,11 @@
#include "base/metrics/histogram.h"
#include "base/threading/thread_restrictions.h"
#include "content/browser/browser_thread_impl.h"
+#include "content/browser/download/download_file_manager.h"
+#include "content/browser/download/save_file_manager.h"
#include "content/browser/in_process_webkit/webkit_thread.h"
+#include "content/browser/plugin_service_impl.h"
+#include "content/browser/renderer_host/resource_dispatcher_host.h"
#include "content/browser/trace_controller.h"
#include "content/common/hi_res_timer_manager.h"
#include "content/common/sandbox_policy.h"
@@ -290,6 +294,12 @@
system_message_window_.reset(new SystemMessageWindowWin);
#endif
+ // Prior to any processing happening on the io thread, we create the
+ // plugin service as it is predominantly used from the io thread,
+ // but must be created on the main thread. The service ctor is
+ // inexpensive and does not invoke the io_thread() accessor.
+ PluginService::GetInstance()->Init();
+
if (parts_.get())
parts_->PostMainMessageLoopStart();
}
@@ -358,9 +368,6 @@
BrowserThread::ID id = static_cast<BrowserThread::ID>(thread_id);
- if (parts_.get())
- parts_->PreStartThread(id);
-
if (thread_id == BrowserThread::WEBKIT_DEPRECATED) {
webkit_thread_.reset(new WebKitThread);
webkit_thread_->Initialize();
@@ -370,11 +377,10 @@
} else {
NOTREACHED();
}
-
- if (parts_.get())
- parts_->PostStartThread(id);
}
+ BrowserThreadsStarted();
+
if (parts_.get())
parts_->PreMainMessageLoopRun();
@@ -410,6 +416,10 @@
if (parts_.get())
parts_->PostMainMessageLoopRun();
+ // Cancel pending requests and prevent new requests.
+ if (resource_dispatcher_host_.get())
+ resource_dispatcher_host_.get()->Shutdown();
+
// Must be size_t so we can subtract from it.
for (size_t thread_id = BrowserThread::ID_COUNT - 1;
thread_id >= (BrowserThread::UI + 1);
@@ -445,12 +455,23 @@
case BrowserThread::WEBKIT_DEPRECATED:
// Special case as WebKitThread is a separate
// type. |thread_to_stop| is not used in this case.
+
+ // Need to destroy ResourceDispatcherHost before PluginService
+ // and since it caches a pointer to it.
+ resource_dispatcher_host_.reset();
break;
case BrowserThread::FILE_USER_BLOCKING:
thread_to_stop = &file_user_blocking_thread_;
break;
case BrowserThread::FILE:
thread_to_stop = &file_thread_;
+
+ // Clean up state that lives on or uses the file_thread_ before
+ // it goes away.
+ if (resource_dispatcher_host_.get()) {
+ resource_dispatcher_host_.get()->download_file_manager()->Shutdown();
+ resource_dispatcher_host_.get()->save_file_manager()->Shutdown();
+ }
break;
case BrowserThread::PROCESS_LAUNCHER:
thread_to_stop = &process_launcher_thread_;
@@ -470,9 +491,6 @@
BrowserThread::ID id = static_cast<BrowserThread::ID>(thread_id);
- if (parts_.get())
- parts_->PreStopThread(id);
-
if (id == BrowserThread::WEBKIT_DEPRECATED) {
webkit_thread_.reset();
} else if (thread_to_stop) {
@@ -480,9 +498,6 @@
} else {
NOTREACHED();
}
-
- if (parts_.get())
- parts_->PostStopThread(id);
}
if (parts_.get())
@@ -499,6 +514,12 @@
MessageLoop::current()));
}
+
+void BrowserMainLoop::BrowserThreadsStarted() {
+ // RDH needs the IO thread to be created.
+ resource_dispatcher_host_.reset(new ResourceDispatcherHost());
+}
+
void BrowserMainLoop::InitializeToolkit() {
// TODO(evan): this function is rather subtle, due to the variety
// of intersecting ifdefs we have. To keep it easy to follow, there

Powered by Google App Engine
This is Rietveld 408576698