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