| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "chrome/worker/worker_thread.h" | 5 #include "chrome/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/thread_local.h" | 9 #include "base/thread_local.h" |
| 10 #include "chrome/common/appcache/appcache_dispatcher.h" |
| 10 #include "chrome/common/chrome_switches.h" | 11 #include "chrome/common/chrome_switches.h" |
| 11 #include "chrome/common/db_message_filter.h" | 12 #include "chrome/common/db_message_filter.h" |
| 12 #include "chrome/common/web_database_observer_impl.h" | 13 #include "chrome/common/web_database_observer_impl.h" |
| 13 #include "chrome/common/worker_messages.h" | 14 #include "chrome/common/worker_messages.h" |
| 14 #include "chrome/worker/webworker_stub.h" | 15 #include "chrome/worker/webworker_stub.h" |
| 15 #include "chrome/worker/websharedworker_stub.h" | 16 #include "chrome/worker/websharedworker_stub.h" |
| 16 #include "chrome/worker/worker_webkitclient_impl.h" | 17 #include "chrome/worker/worker_webkitclient_impl.h" |
| 17 #include "third_party/WebKit/WebKit/chromium/public/WebDatabase.h" | 18 #include "third_party/WebKit/WebKit/chromium/public/WebDatabase.h" |
| 18 #include "third_party/WebKit/WebKit/chromium/public/WebKit.h" | 19 #include "third_party/WebKit/WebKit/chromium/public/WebKit.h" |
| 19 #include "third_party/WebKit/WebKit/chromium/public/WebRuntimeFeatures.h" | 20 #include "third_party/WebKit/WebKit/chromium/public/WebRuntimeFeatures.h" |
| 20 | 21 |
| 21 using WebKit::WebRuntimeFeatures; | 22 using WebKit::WebRuntimeFeatures; |
| 22 | 23 |
| 23 static base::LazyInstance<base::ThreadLocalPointer<WorkerThread> > lazy_tls( | 24 static base::LazyInstance<base::ThreadLocalPointer<WorkerThread> > lazy_tls( |
| 24 base::LINKER_INITIALIZED); | 25 base::LINKER_INITIALIZED); |
| 25 | 26 |
| 26 | 27 |
| 27 WorkerThread::WorkerThread() { | 28 WorkerThread::WorkerThread() { |
| 28 lazy_tls.Pointer()->Set(this); | 29 lazy_tls.Pointer()->Set(this); |
| 29 webkit_client_.reset(new WorkerWebKitClientImpl); | 30 webkit_client_.reset(new WorkerWebKitClientImpl); |
| 30 WebKit::initialize(webkit_client_.get()); | 31 WebKit::initialize(webkit_client_.get()); |
| 31 | 32 |
| 33 appcache_dispatcher_.reset(new AppCacheDispatcher(this)); |
| 34 |
| 32 web_database_observer_impl_.reset(new WebDatabaseObserverImpl(this)); | 35 web_database_observer_impl_.reset(new WebDatabaseObserverImpl(this)); |
| 33 WebKit::WebDatabase::setObserver(web_database_observer_impl_.get()); | 36 WebKit::WebDatabase::setObserver(web_database_observer_impl_.get()); |
| 37 db_message_filter_ = new DBMessageFilter(); |
| 38 channel()->AddFilter(db_message_filter_.get()); |
| 34 | 39 |
| 35 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 40 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 36 | 41 |
| 37 WebKit::WebRuntimeFeatures::enableDatabase( | 42 WebKit::WebRuntimeFeatures::enableDatabase( |
| 38 !command_line.HasSwitch(switches::kDisableDatabases)); | 43 !command_line.HasSwitch(switches::kDisableDatabases)); |
| 39 | 44 |
| 40 db_message_filter_ = new DBMessageFilter(); | 45 // TODO(michaeln): Enable once the browser process is ready to receive |
| 41 channel()->AddFilter(db_message_filter_.get()); | 46 // the appcache messages. |
| 47 WebKit::WebRuntimeFeatures::enableApplicationCache(false && |
| 48 !command_line.HasSwitch(switches::kDisableApplicationCache)); |
| 42 | 49 |
| 43 #if defined(OS_WIN) | 50 #if defined(OS_WIN) |
| 44 // We don't yet support notifications on non-Windows, so hide it from pages. | 51 // We don't yet support notifications on non-Windows, so hide it from pages. |
| 45 WebRuntimeFeatures::enableNotifications( | 52 WebRuntimeFeatures::enableNotifications( |
| 46 !command_line.HasSwitch(switches::kDisableDesktopNotifications)); | 53 !command_line.HasSwitch(switches::kDisableDesktopNotifications)); |
| 47 #endif | 54 #endif |
| 48 | 55 |
| 49 WebRuntimeFeatures::enableSockets( | 56 WebRuntimeFeatures::enableSockets( |
| 50 !command_line.HasSwitch(switches::kDisableWebSockets)); | 57 !command_line.HasSwitch(switches::kDisableWebSockets)); |
| 51 } | 58 } |
| 52 | 59 |
| 53 WorkerThread::~WorkerThread() { | 60 WorkerThread::~WorkerThread() { |
| 54 // Shutdown in reverse of the initialization order. | 61 // Shutdown in reverse of the initialization order. |
| 55 channel()->RemoveFilter(db_message_filter_.get()); | 62 channel()->RemoveFilter(db_message_filter_.get()); |
| 56 db_message_filter_ = NULL; | 63 db_message_filter_ = NULL; |
| 57 | 64 |
| 58 WebKit::shutdown(); | 65 WebKit::shutdown(); |
| 59 lazy_tls.Pointer()->Set(NULL); | 66 lazy_tls.Pointer()->Set(NULL); |
| 60 } | 67 } |
| 61 | 68 |
| 62 WorkerThread* WorkerThread::current() { | 69 WorkerThread* WorkerThread::current() { |
| 63 return lazy_tls.Pointer()->Get(); | 70 return lazy_tls.Pointer()->Get(); |
| 64 } | 71 } |
| 65 | 72 |
| 66 void WorkerThread::OnControlMessageReceived(const IPC::Message& msg) { | 73 void WorkerThread::OnControlMessageReceived(const IPC::Message& msg) { |
| 74 // Appcache messages are handled by a delegate. |
| 75 if (appcache_dispatcher_->OnMessageReceived(msg)) |
| 76 return; |
| 77 |
| 67 IPC_BEGIN_MESSAGE_MAP(WorkerThread, msg) | 78 IPC_BEGIN_MESSAGE_MAP(WorkerThread, msg) |
| 68 IPC_MESSAGE_HANDLER(WorkerProcessMsg_CreateWorker, OnCreateWorker) | 79 IPC_MESSAGE_HANDLER(WorkerProcessMsg_CreateWorker, OnCreateWorker) |
| 69 IPC_END_MESSAGE_MAP() | 80 IPC_END_MESSAGE_MAP() |
| 70 } | 81 } |
| 71 | 82 |
| 72 void WorkerThread::OnCreateWorker(const GURL& url, | 83 void WorkerThread::OnCreateWorker( |
| 73 bool is_shared, | 84 const WorkerProcessMsg_CreateWorker_Params& params) { |
| 74 const string16& name, | 85 WorkerAppCacheInitInfo appcache_init_info( |
| 75 int route_id) { | 86 params.is_shared, params.creator_process_id, |
| 87 params.creator_appcache_host_id, |
| 88 params.shared_worker_appcache_id); |
| 89 |
| 76 // WebWorkerStub and WebSharedWorkerStub own themselves. | 90 // WebWorkerStub and WebSharedWorkerStub own themselves. |
| 77 if (is_shared) | 91 if (params.is_shared) |
| 78 new WebSharedWorkerStub(name, route_id); | 92 new WebSharedWorkerStub(params.name, params.route_id, appcache_init_info); |
| 79 else | 93 else |
| 80 new WebWorkerStub(url, route_id); | 94 new WebWorkerStub(params.url, params.route_id, appcache_init_info); |
| 81 } | 95 } |
| 82 | 96 |
| 83 // The browser process is likely dead. Terminate all workers. | 97 // The browser process is likely dead. Terminate all workers. |
| 84 void WorkerThread::OnChannelError() { | 98 void WorkerThread::OnChannelError() { |
| 85 set_on_channel_error_called(true); | 99 set_on_channel_error_called(true); |
| 86 | 100 |
| 87 for (WorkerStubsList::iterator it = worker_stubs_.begin(); | 101 for (WorkerStubsList::iterator it = worker_stubs_.begin(); |
| 88 it != worker_stubs_.end(); ++it) { | 102 it != worker_stubs_.end(); ++it) { |
| 89 (*it)->OnChannelError(); | 103 (*it)->OnChannelError(); |
| 90 } | 104 } |
| 91 } | 105 } |
| 92 | 106 |
| 93 void WorkerThread::RemoveWorkerStub(WebWorkerStubBase* stub) { | 107 void WorkerThread::RemoveWorkerStub(WebWorkerStubBase* stub) { |
| 94 worker_stubs_.erase(stub); | 108 worker_stubs_.erase(stub); |
| 95 } | 109 } |
| 96 | 110 |
| 97 void WorkerThread::AddWorkerStub(WebWorkerStubBase* stub) { | 111 void WorkerThread::AddWorkerStub(WebWorkerStubBase* stub) { |
| 98 worker_stubs_.insert(stub); | 112 worker_stubs_.insert(stub); |
| 99 } | 113 } |
| 100 | 114 |
| OLD | NEW |