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

Unified Diff: content/child/child_thread.cc

Issue 17741010: Make ChildThread::current() and ChildProcess::current() only work on the main thread of the child... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: sync and also fix gpu single process case Created 7 years, 6 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
« no previous file with comments | « content/child/child_thread.h ('k') | content/renderer/pepper/pepper_hung_plugin_filter.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/child/child_thread.cc
===================================================================
--- content/child/child_thread.cc (revision 208740)
+++ content/child/child_thread.cc (working copy)
@@ -6,10 +6,12 @@
#include "base/allocator/allocator_extension.h"
#include "base/command_line.h"
+#include "base/lazy_instance.h"
#include "base/message_loop.h"
#include "base/process.h"
#include "base/process_util.h"
#include "base/strings/string_util.h"
+#include "base/threading/thread_local.h"
#include "base/tracked_objects.h"
#include "components/tracing/child_trace_message_filter.h"
#include "content/child/child_histogram_message_filter.h"
@@ -40,6 +42,9 @@
// How long to wait for a connection to the browser process before giving up.
const int kConnectionTimeoutS = 15;
+base::LazyInstance<base::ThreadLocalPointer<ChildThread> > g_lazy_tls =
+ LAZY_INSTANCE_INITIALIZER;
+
// This isn't needed on Windows because there the sandbox's job object
// terminates child processes automatically. For unsandboxed processes (i.e.
// plugins), PluginThread has EnsureTerminateMessageFilter.
@@ -80,6 +85,15 @@
#endif // OS(POSIX)
+#if defined(OS_ANDROID)
+ChildThread* g_child_thread;
Feng Qian 2013/06/28 17:12:14 @jam, won't this be a race condition when both Ren
jam 2013/07/01 19:29:26 this is only called by content/app/android/child_p
+
+void QuitMainThreadMessageLoop() {
+ base::MessageLoop::current()->Quit();
+}
+
+#endif
+
} // namespace
ChildThread::ChildThread()
@@ -96,6 +110,7 @@
}
void ChildThread::Init() {
+ g_lazy_tls.Pointer()->Set(this);
on_channel_error_called_ = false;
message_loop_ = base::MessageLoop::current();
channel_.reset(
@@ -140,6 +155,10 @@
base::Bind(&ChildThread::EnsureConnected,
channel_connected_factory_.GetWeakPtr()),
base::TimeDelta::FromSeconds(kConnectionTimeoutS));
+
+#if defined(OS_ANDROID)
+ g_child_thread = this;
+#endif
}
ChildThread::~ChildThread() {
@@ -159,6 +178,7 @@
// automatically. We used to watch the object handle on Windows to do this,
// but it wasn't possible to do so on POSIX.
channel_->ClearIPCTaskRunner();
+ g_lazy_tls.Pointer()->Set(NULL);
}
void ChildThread::OnChannelConnected(int32 peer_pid) {
@@ -328,15 +348,18 @@
#endif
ChildThread* ChildThread::current() {
- return ChildProcess::current() ?
- ChildProcess::current()->main_thread() : NULL;
+ return g_lazy_tls.Pointer()->Get();
}
-bool ChildThread::IsWebFrameValid(WebKit::WebFrame* frame) {
- // Return false so that it is overridden in any process in which it is used.
- return false;
+#if defined(OS_ANDROID)
+void ChildThread::ShutdownThread() {
+ DCHECK_NE(base::MessageLoop::current(), g_child_thread->message_loop());
+ g_child_thread->message_loop()->PostTask(
+ FROM_HERE, base::Bind(&QuitMainThreadMessageLoop));
}
+#endif
+
void ChildThread::OnProcessFinalRelease() {
if (on_channel_error_called_) {
base::MessageLoop::current()->Quit();
« no previous file with comments | « content/child/child_thread.h ('k') | content/renderer/pepper/pepper_hung_plugin_filter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698