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

Side by Side Diff: content/child/child_thread.cc

Issue 20015002: Make Platform::queryStorageUsageAndQuota work from worker threads (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/child/child_thread.h" 5 #include "content/child/child_thread.h"
6 6
7 #include "base/allocator/allocator_extension.h" 7 #include "base/allocator/allocator_extension.h"
8 #include "base/base_switches.h" 8 #include "base/base_switches.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "base/process.h" 12 #include "base/process.h"
13 #include "base/process_util.h" 13 #include "base/process_util.h"
14 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
15 #include "base/threading/thread_local.h" 15 #include "base/threading/thread_local.h"
16 #include "base/tracked_objects.h" 16 #include "base/tracked_objects.h"
17 #include "components/tracing/child_trace_message_filter.h" 17 #include "components/tracing/child_trace_message_filter.h"
18 #include "content/child/child_histogram_message_filter.h" 18 #include "content/child/child_histogram_message_filter.h"
19 #include "content/child/child_process.h" 19 #include "content/child/child_process.h"
20 #include "content/child/child_resource_message_filter.h" 20 #include "content/child/child_resource_message_filter.h"
21 #include "content/child/fileapi/file_system_dispatcher.h" 21 #include "content/child/fileapi/file_system_dispatcher.h"
22 #include "content/child/quota_dispatcher.h" 22 #include "content/child/quota_dispatcher.h"
23 #include "content/child/quota_message_filter.h"
23 #include "content/child/resource_dispatcher.h" 24 #include "content/child/resource_dispatcher.h"
24 #include "content/child/socket_stream_dispatcher.h" 25 #include "content/child/socket_stream_dispatcher.h"
25 #include "content/child/thread_safe_sender.h" 26 #include "content/child/thread_safe_sender.h"
26 #include "content/common/child_process_messages.h" 27 #include "content/common/child_process_messages.h"
27 #include "content/public/common/content_switches.h" 28 #include "content/public/common/content_switches.h"
28 #include "ipc/ipc_logging.h" 29 #include "ipc/ipc_logging.h"
29 #include "ipc/ipc_switches.h" 30 #include "ipc/ipc_switches.h"
30 #include "ipc/ipc_sync_channel.h" 31 #include "ipc/ipc_sync_channel.h"
31 #include "ipc/ipc_sync_message_filter.h" 32 #include "ipc/ipc_sync_message_filter.h"
32 #include "webkit/glue/webkit_glue.h" 33 #include "webkit/glue/webkit_glue.h"
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 new IPC::SyncChannel(channel_name_, 119 new IPC::SyncChannel(channel_name_,
119 IPC::Channel::MODE_CLIENT, 120 IPC::Channel::MODE_CLIENT,
120 this, 121 this,
121 ChildProcess::current()->io_message_loop_proxy(), 122 ChildProcess::current()->io_message_loop_proxy(),
122 true, 123 true,
123 ChildProcess::current()->GetShutDownEvent())); 124 ChildProcess::current()->GetShutDownEvent()));
124 #ifdef IPC_MESSAGE_LOG_ENABLED 125 #ifdef IPC_MESSAGE_LOG_ENABLED
125 IPC::Logging::GetInstance()->SetIPCSender(this); 126 IPC::Logging::GetInstance()->SetIPCSender(this);
126 #endif 127 #endif
127 128
128 resource_dispatcher_.reset(new ResourceDispatcher(this));
129 socket_stream_dispatcher_.reset(new SocketStreamDispatcher());
130 file_system_dispatcher_.reset(new FileSystemDispatcher());
131 quota_dispatcher_.reset(new QuotaDispatcher());
132
133 sync_message_filter_ = 129 sync_message_filter_ =
134 new IPC::SyncMessageFilter(ChildProcess::current()->GetShutDownEvent()); 130 new IPC::SyncMessageFilter(ChildProcess::current()->GetShutDownEvent());
135 thread_safe_sender_ = new ThreadSafeSender( 131 thread_safe_sender_ = new ThreadSafeSender(
136 base::MessageLoopProxy::current().get(), sync_message_filter_.get()); 132 base::MessageLoopProxy::current().get(), sync_message_filter_.get());
133
134 resource_dispatcher_.reset(new ResourceDispatcher(this));
135 socket_stream_dispatcher_.reset(new SocketStreamDispatcher());
136 file_system_dispatcher_.reset(new FileSystemDispatcher());
137 quota_dispatcher_.reset(new QuotaDispatcher(thread_safe_sender_.get()));
138
137 histogram_message_filter_ = new ChildHistogramMessageFilter(); 139 histogram_message_filter_ = new ChildHistogramMessageFilter();
138 resource_message_filter_ = 140 resource_message_filter_ =
139 new ChildResourceMessageFilter(resource_dispatcher()); 141 new ChildResourceMessageFilter(resource_dispatcher());
142 quota_message_filter_ =
143 new QuotaMessageFilter(thread_safe_sender_.get());
140 144
141 channel_->AddFilter(histogram_message_filter_.get()); 145 channel_->AddFilter(histogram_message_filter_.get());
142 channel_->AddFilter(sync_message_filter_.get()); 146 channel_->AddFilter(sync_message_filter_.get());
143 channel_->AddFilter(new tracing::ChildTraceMessageFilter( 147 channel_->AddFilter(new tracing::ChildTraceMessageFilter(
144 ChildProcess::current()->io_message_loop_proxy())); 148 ChildProcess::current()->io_message_loop_proxy()));
145 channel_->AddFilter(resource_message_filter_.get()); 149 channel_->AddFilter(resource_message_filter_.get());
150 channel_->AddFilter(quota_message_filter_.get());
146 151
147 #if defined(OS_POSIX) 152 #if defined(OS_POSIX)
148 // Check that --process-type is specified so we don't do this in unit tests 153 // Check that --process-type is specified so we don't do this in unit tests
149 // and single-process mode. 154 // and single-process mode.
150 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kProcessType)) 155 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kProcessType))
151 channel_->AddFilter(new SuicideOnChannelErrorFilter()); 156 channel_->AddFilter(new SuicideOnChannelErrorFilter());
152 #endif 157 #endif
153 158
154 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kTraceToConsole)) { 159 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kTraceToConsole)) {
155 std::string category_string = 160 std::string category_string =
(...skipping 17 matching lines...) Expand all
173 #if defined(OS_ANDROID) 178 #if defined(OS_ANDROID)
174 g_child_thread = this; 179 g_child_thread = this;
175 #endif 180 #endif
176 } 181 }
177 182
178 ChildThread::~ChildThread() { 183 ChildThread::~ChildThread() {
179 #ifdef IPC_MESSAGE_LOG_ENABLED 184 #ifdef IPC_MESSAGE_LOG_ENABLED
180 IPC::Logging::GetInstance()->SetIPCSender(NULL); 185 IPC::Logging::GetInstance()->SetIPCSender(NULL);
181 #endif 186 #endif
182 187
188 channel_->RemoveFilter(quota_message_filter_.get());
183 channel_->RemoveFilter(histogram_message_filter_.get()); 189 channel_->RemoveFilter(histogram_message_filter_.get());
184 channel_->RemoveFilter(sync_message_filter_.get()); 190 channel_->RemoveFilter(sync_message_filter_.get());
185 191
186 // The ChannelProxy object caches a pointer to the IPC thread, so need to 192 // The ChannelProxy object caches a pointer to the IPC thread, so need to
187 // reset it as it's not guaranteed to outlive this object. 193 // reset it as it's not guaranteed to outlive this object.
188 // NOTE: this also has the side-effect of not closing the main IPC channel to 194 // NOTE: this also has the side-effect of not closing the main IPC channel to
189 // the browser process. This is needed because this is the signal that the 195 // the browser process. This is needed because this is the signal that the
190 // browser uses to know that this process has died, so we need it to be alive 196 // browser uses to know that this process has died, so we need it to be alive
191 // until this process is shut down, and the OS closes the handle 197 // until this process is shut down, and the OS closes the handle
192 // automatically. We used to watch the object handle on Windows to do this, 198 // automatically. We used to watch the object handle on Windows to do this,
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 } 277 }
272 278
273 bool ChildThread::OnMessageReceived(const IPC::Message& msg) { 279 bool ChildThread::OnMessageReceived(const IPC::Message& msg) {
274 // Resource responses are sent to the resource dispatcher. 280 // Resource responses are sent to the resource dispatcher.
275 if (resource_dispatcher_->OnMessageReceived(msg)) 281 if (resource_dispatcher_->OnMessageReceived(msg))
276 return true; 282 return true;
277 if (socket_stream_dispatcher_->OnMessageReceived(msg)) 283 if (socket_stream_dispatcher_->OnMessageReceived(msg))
278 return true; 284 return true;
279 if (file_system_dispatcher_->OnMessageReceived(msg)) 285 if (file_system_dispatcher_->OnMessageReceived(msg))
280 return true; 286 return true;
281 if (quota_dispatcher_->OnMessageReceived(msg))
282 return true;
283 287
284 bool handled = true; 288 bool handled = true;
285 IPC_BEGIN_MESSAGE_MAP(ChildThread, msg) 289 IPC_BEGIN_MESSAGE_MAP(ChildThread, msg)
286 IPC_MESSAGE_HANDLER(ChildProcessMsg_Shutdown, OnShutdown) 290 IPC_MESSAGE_HANDLER(ChildProcessMsg_Shutdown, OnShutdown)
287 #if defined(IPC_MESSAGE_LOG_ENABLED) 291 #if defined(IPC_MESSAGE_LOG_ENABLED)
288 IPC_MESSAGE_HANDLER(ChildProcessMsg_SetIPCLoggingEnabled, 292 IPC_MESSAGE_HANDLER(ChildProcessMsg_SetIPCLoggingEnabled,
289 OnSetIPCLoggingEnabled) 293 OnSetIPCLoggingEnabled)
290 #endif 294 #endif
291 IPC_MESSAGE_HANDLER(ChildProcessMsg_SetProfilerStatus, 295 IPC_MESSAGE_HANDLER(ChildProcessMsg_SetProfilerStatus,
292 OnSetProfilerStatus) 296 OnSetProfilerStatus)
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 // inflight that would addref it. 392 // inflight that would addref it.
389 Send(new ChildProcessHostMsg_ShutdownRequest); 393 Send(new ChildProcessHostMsg_ShutdownRequest);
390 } 394 }
391 395
392 void ChildThread::EnsureConnected() { 396 void ChildThread::EnsureConnected() {
393 LOG(INFO) << "ChildThread::EnsureConnected()"; 397 LOG(INFO) << "ChildThread::EnsureConnected()";
394 base::KillProcess(base::GetCurrentProcessHandle(), 0, false); 398 base::KillProcess(base::GetCurrentProcessHandle(), 0, false);
395 } 399 }
396 400
397 } // namespace content 401 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698