| OLD | NEW |
| 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/worker/worker_thread.h" | 5 #include "content/worker/worker_thread.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
| 9 #include "base/threading/thread_local.h" | 9 #include "base/threading/thread_local.h" |
| 10 #include "content/child/appcache/appcache_dispatcher.h" | 10 #include "content/child/appcache/appcache_dispatcher.h" |
| 11 #include "content/child/appcache/appcache_frontend_impl.h" | 11 #include "content/child/appcache/appcache_frontend_impl.h" |
| 12 #include "content/child/db_message_filter.h" | 12 #include "content/child/db_message_filter.h" |
| 13 #include "content/child/indexed_db/indexed_db_message_filter.h" | 13 #include "content/child/indexed_db/indexed_db_message_filter.h" |
| 14 #include "content/child/runtime_features.h" | 14 #include "content/child/runtime_features.h" |
| 15 #include "content/child/web_database_observer_impl.h" | 15 #include "content/child/web_database_observer_impl.h" |
| 16 #include "content/common/child_process_messages.h" | |
| 17 #include "content/common/worker_messages.h" | 16 #include "content/common/worker_messages.h" |
| 18 #include "content/public/common/content_switches.h" | 17 #include "content/public/common/content_switches.h" |
| 19 #include "content/worker/websharedworker_stub.h" | 18 #include "content/worker/websharedworker_stub.h" |
| 20 #include "content/worker/worker_webkitplatformsupport_impl.h" | 19 #include "content/worker/worker_webkitplatformsupport_impl.h" |
| 21 #include "ipc/ipc_sync_channel.h" | 20 #include "ipc/ipc_sync_channel.h" |
| 22 #include "third_party/WebKit/public/platform/WebBlobRegistry.h" | 21 #include "third_party/WebKit/public/platform/WebBlobRegistry.h" |
| 23 #include "third_party/WebKit/public/web/WebDatabase.h" | 22 #include "third_party/WebKit/public/web/WebDatabase.h" |
| 24 #include "third_party/WebKit/public/web/WebKit.h" | 23 #include "third_party/WebKit/public/web/WebKit.h" |
| 25 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" | 24 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" |
| 26 #include "webkit/glue/webkit_glue.h" | 25 #include "webkit/glue/webkit_glue.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 50 channel()->AddFilter(db_message_filter_.get()); | 49 channel()->AddFilter(db_message_filter_.get()); |
| 51 | 50 |
| 52 indexed_db_message_filter_ = new IndexedDBMessageFilter( | 51 indexed_db_message_filter_ = new IndexedDBMessageFilter( |
| 53 thread_safe_sender()); | 52 thread_safe_sender()); |
| 54 channel()->AddFilter(indexed_db_message_filter_.get()); | 53 channel()->AddFilter(indexed_db_message_filter_.get()); |
| 55 | 54 |
| 56 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 55 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 57 SetRuntimeFeaturesDefaultsAndUpdateFromArgs(command_line); | 56 SetRuntimeFeaturesDefaultsAndUpdateFromArgs(command_line); |
| 58 } | 57 } |
| 59 | 58 |
| 60 void WorkerThread::OnShutdown() { | |
| 61 // The worker process is to be shut down gracefully. Ask the browser | |
| 62 // process to shut it down forcefully instead and wait on the message, so that | |
| 63 // there are no races between threads when the process is shutting down. | |
| 64 Send(new WorkerProcessHostMsg_ForceKillWorker()); | |
| 65 } | |
| 66 | |
| 67 WorkerThread::~WorkerThread() { | 59 WorkerThread::~WorkerThread() { |
| 68 } | 60 } |
| 69 | 61 |
| 70 void WorkerThread::Shutdown() { | 62 void WorkerThread::Shutdown() { |
| 71 ChildThread::Shutdown(); | 63 ChildThread::Shutdown(); |
| 72 | 64 |
| 73 // Shutdown in reverse of the initialization order. | 65 // Shutdown in reverse of the initialization order. |
| 74 channel()->RemoveFilter(indexed_db_message_filter_.get()); | 66 channel()->RemoveFilter(indexed_db_message_filter_.get()); |
| 75 indexed_db_message_filter_ = NULL; | 67 indexed_db_message_filter_ = NULL; |
| 76 | 68 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 91 return true; | 83 return true; |
| 92 | 84 |
| 93 bool handled = true; | 85 bool handled = true; |
| 94 IPC_BEGIN_MESSAGE_MAP(WorkerThread, msg) | 86 IPC_BEGIN_MESSAGE_MAP(WorkerThread, msg) |
| 95 IPC_MESSAGE_HANDLER(WorkerProcessMsg_CreateWorker, OnCreateWorker) | 87 IPC_MESSAGE_HANDLER(WorkerProcessMsg_CreateWorker, OnCreateWorker) |
| 96 IPC_MESSAGE_UNHANDLED(handled = false) | 88 IPC_MESSAGE_UNHANDLED(handled = false) |
| 97 IPC_END_MESSAGE_MAP() | 89 IPC_END_MESSAGE_MAP() |
| 98 return handled; | 90 return handled; |
| 99 } | 91 } |
| 100 | 92 |
| 101 bool WorkerThread::OnMessageReceived(const IPC::Message& msg) { | |
| 102 bool handled = true; | |
| 103 IPC_BEGIN_MESSAGE_MAP(WorkerThread, msg) | |
| 104 IPC_MESSAGE_HANDLER(ChildProcessMsg_Shutdown, OnShutdown) | |
| 105 IPC_MESSAGE_UNHANDLED(handled = ChildThread::OnMessageReceived(msg)) | |
| 106 IPC_END_MESSAGE_MAP() | |
| 107 return handled; | |
| 108 } | |
| 109 | |
| 110 void WorkerThread::OnCreateWorker( | 93 void WorkerThread::OnCreateWorker( |
| 111 const WorkerProcessMsg_CreateWorker_Params& params) { | 94 const WorkerProcessMsg_CreateWorker_Params& params) { |
| 112 WorkerAppCacheInitInfo appcache_init_info( | 95 WorkerAppCacheInitInfo appcache_init_info( |
| 113 params.creator_process_id, | 96 params.creator_process_id, |
| 114 params.shared_worker_appcache_id); | 97 params.shared_worker_appcache_id); |
| 115 | 98 |
| 116 // WebSharedWorkerStub own themselves. | 99 // WebSharedWorkerStub own themselves. |
| 117 new WebSharedWorkerStub(params.name, params.route_id, appcache_init_info); | 100 new WebSharedWorkerStub(params.name, params.route_id, appcache_init_info); |
| 118 } | 101 } |
| 119 | 102 |
| 120 // The browser process is likely dead. Terminate all workers. | 103 // The browser process is likely dead. Terminate all workers. |
| 121 void WorkerThread::OnChannelError() { | 104 void WorkerThread::OnChannelError() { |
| 122 set_on_channel_error_called(true); | 105 set_on_channel_error_called(true); |
| 123 | 106 |
| 124 for (WorkerStubsList::iterator it = worker_stubs_.begin(); | 107 for (WorkerStubsList::iterator it = worker_stubs_.begin(); |
| 125 it != worker_stubs_.end(); ++it) { | 108 it != worker_stubs_.end(); ++it) { |
| 126 (*it)->OnChannelError(); | 109 (*it)->OnChannelError(); |
| 127 } | 110 } |
| 128 } | 111 } |
| 129 | 112 |
| 130 void WorkerThread::RemoveWorkerStub(WebSharedWorkerStub* stub) { | 113 void WorkerThread::RemoveWorkerStub(WebSharedWorkerStub* stub) { |
| 131 worker_stubs_.erase(stub); | 114 worker_stubs_.erase(stub); |
| 132 } | 115 } |
| 133 | 116 |
| 134 void WorkerThread::AddWorkerStub(WebSharedWorkerStub* stub) { | 117 void WorkerThread::AddWorkerStub(WebSharedWorkerStub* stub) { |
| 135 worker_stubs_.insert(stub); | 118 worker_stubs_.insert(stub); |
| 136 } | 119 } |
| 137 | 120 |
| 138 } // namespace content | 121 } // namespace content |
| OLD | NEW |