summaryrefslogtreecommitdiffstats
path: root/content/worker
diff options
context:
space:
mode:
authorhoro@chromium.org <horo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-02-05 06:04:58 +0000
committerhoro@chromium.org <horo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-02-05 06:04:58 +0000
commitd8f7d16ef3379f82b624f8256ab066045bba28d6 (patch)
treef5400ce1c5ca89b76409e5004468d35ff8e1050f /content/worker
parent415f99b18e6f14c53e08f6574a3bc653049fbaae (diff)
downloadchromium_src-d8f7d16ef3379f82b624f8256ab066045bba28d6.zip
chromium_src-d8f7d16ef3379f82b624f8256ab066045bba28d6.tar.gz
chromium_src-d8f7d16ef3379f82b624f8256ab066045bba28d6.tar.bz2
Move the worker script loading code to the worker process (phase:4/5)
- Stop sending the worker script from the renderer. - In this change we can remove the pending instances in WorkerServiceImpl. This is step 4 of moving the worker script loading code from the renderer process to the worker process. See: http://crbug.com/329786 BUG=329786 Review URL: https://codereview.chromium.org/133093003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@248869 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/worker')
-rw-r--r--content/worker/websharedworker_stub.cc51
-rw-r--r--content/worker/websharedworker_stub.h20
-rw-r--r--content/worker/websharedworkerclient_proxy.cc6
-rw-r--r--content/worker/worker_thread.cc7
-rw-r--r--content/worker/worker_webapplicationcachehost_impl.cc3
-rw-r--r--content/worker/worker_webapplicationcachehost_impl.h22
6 files changed, 32 insertions, 77 deletions
diff --git a/content/worker/websharedworker_stub.cc b/content/worker/websharedworker_stub.cc
index 5f40bab..19d3ec9 100644
--- a/content/worker/websharedworker_stub.cc
+++ b/content/worker/websharedworker_stub.cc
@@ -23,14 +23,11 @@ WebSharedWorkerStub::WebSharedWorkerStub(
const base::string16& name,
const base::string16& content_security_policy,
blink::WebContentSecurityPolicyType security_policy_type,
- int route_id,
- const WorkerAppCacheInitInfo& appcache_init_info)
+ int route_id)
: route_id_(route_id),
- appcache_init_info_(appcache_init_info),
client_(route_id, this),
- name_(name),
- started_(false),
- worker_script_loaded_(false) {
+ running_(false),
+ url_(url) {
WorkerThread* worker_thread = WorkerThread::current();
DCHECK(worker_thread);
@@ -42,6 +39,8 @@ WebSharedWorkerStub::WebSharedWorkerStub(
impl_ = blink::WebSharedWorker::create(client());
worker_devtools_agent_.reset(new SharedWorkerDevToolsAgent(route_id, impl_));
client()->set_devtools_agent(worker_devtools_agent_.get());
+ impl_->startWorkerContext(url_, name,
+ content_security_policy, security_policy_type);
}
WebSharedWorkerStub::~WebSharedWorkerStub() {
@@ -67,7 +66,6 @@ bool WebSharedWorkerStub::OnMessageReceived(const IPC::Message& message) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(WebSharedWorkerStub, message)
- IPC_MESSAGE_HANDLER(WorkerMsg_StartWorkerContext, OnStartWorkerContext)
IPC_MESSAGE_HANDLER(WorkerMsg_TerminateWorkerContext,
OnTerminateWorkerContext)
IPC_MESSAGE_HANDLER(WorkerMsg_Connect, OnConnect)
@@ -84,29 +82,16 @@ const GURL& WebSharedWorkerStub::url() {
return url_;
}
-void WebSharedWorkerStub::OnStartWorkerContext(
- const GURL& url, const base::string16& user_agent,
- const base::string16& source_code,
- const base::string16& content_security_policy,
- blink::WebContentSecurityPolicyType policy_type) {
- // Ignore multiple attempts to start this worker (can happen if two pages
- // try to start it simultaneously).
- if (started_)
- return;
-
- impl_->startWorkerContext(url, name_, user_agent, source_code,
- content_security_policy, policy_type, 0);
- started_ = true;
- url_ = url;
-}
-
void WebSharedWorkerStub::OnConnect(int sent_message_port_id, int routing_id) {
- blink::WebMessagePortChannel* channel =
+ WebMessagePortChannelImpl* channel =
new WebMessagePortChannelImpl(routing_id,
sent_message_port_id,
base::MessageLoopProxy::current().get());
- if (started_ && worker_script_loaded_) {
+ if (running_) {
impl_->connect(channel);
+ WorkerThread::current()->Send(
+ new WorkerHostMsg_WorkerConnected(channel->message_port_id(),
+ route_id_));
} else {
// If two documents try to load a SharedWorker at the same time, the
// WorkerMsg_Connect for one of the documents can come in before the
@@ -121,22 +106,32 @@ void WebSharedWorkerStub::OnTerminateWorkerContext() {
// Call the client to make sure context exits.
EnsureWorkerContextTerminates();
- started_ = false;
+ running_ = false;
}
void WebSharedWorkerStub::WorkerScriptLoaded() {
- worker_script_loaded_ = true;
+ running_ = true;
// Process any pending connections.
for (PendingChannelList::const_iterator iter = pending_channels_.begin();
iter != pending_channels_.end();
++iter) {
impl_->connect(*iter);
+ WorkerThread::current()->Send(
+ new WorkerHostMsg_WorkerConnected((*iter)->message_port_id(),
+ route_id_));
}
pending_channels_.clear();
}
void WebSharedWorkerStub::WorkerScriptLoadFailed() {
- // FIXME(horo): Implement this.
+ for (PendingChannelList::const_iterator iter = pending_channels_.begin();
+ iter != pending_channels_.end();
+ ++iter) {
+ blink::WebMessagePortChannel* channel = *iter;
+ channel->destroy();
+ }
+ pending_channels_.clear();
+ Shutdown();
}
} // namespace content
diff --git a/content/worker/websharedworker_stub.h b/content/worker/websharedworker_stub.h
index bde7cba..1f9aadd 100644
--- a/content/worker/websharedworker_stub.h
+++ b/content/worker/websharedworker_stub.h
@@ -14,7 +14,6 @@
#include "url/gurl.h"
namespace blink {
-class WebMessagePortChannel;
class WebSharedWorker;
}
@@ -31,8 +30,7 @@ class WebSharedWorkerStub : public IPC::Listener {
const base::string16& name,
const base::string16& content_security_policy,
blink::WebContentSecurityPolicyType security_policy_type,
- int route_id,
- const WorkerAppCacheInitInfo& appcache_init_info);
+ int route_id);
// IPC::Listener implementation.
virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
@@ -50,10 +48,6 @@ class WebSharedWorkerStub : public IPC::Listener {
WebSharedWorkerClientProxy* client() { return &client_; }
- const WorkerAppCacheInitInfo& appcache_init_info() const {
- return appcache_init_info_;
- }
-
// Returns the script url of this worker.
const GURL& url();
@@ -62,31 +56,23 @@ class WebSharedWorkerStub : public IPC::Listener {
virtual ~WebSharedWorkerStub();
void OnConnect(int sent_message_port_id, int routing_id);
- void OnStartWorkerContext(
- const GURL& url, const base::string16& user_agent,
- const base::string16& source_code,
- const base::string16& content_security_policy,
- blink::WebContentSecurityPolicyType policy_type);
void OnTerminateWorkerContext();
ScopedChildProcessReference process_ref_;
int route_id_;
- WorkerAppCacheInitInfo appcache_init_info_;
// WebSharedWorkerClient that responds to outgoing API calls
// from the worker object.
WebSharedWorkerClientProxy client_;
blink::WebSharedWorker* impl_;
- base::string16 name_;
- bool started_;
+ bool running_;
GURL url_;
- bool worker_script_loaded_;
scoped_ptr<SharedWorkerDevToolsAgent> worker_devtools_agent_;
- typedef std::vector<blink::WebMessagePortChannel*> PendingChannelList;
+ typedef std::vector<WebMessagePortChannelImpl*> PendingChannelList;
PendingChannelList pending_channels_;
DISALLOW_COPY_AND_ASSIGN(WebSharedWorkerStub);
diff --git a/content/worker/websharedworkerclient_proxy.cc b/content/worker/websharedworkerclient_proxy.cc
index 538657d..ade6fa6 100644
--- a/content/worker/websharedworkerclient_proxy.cc
+++ b/content/worker/websharedworkerclient_proxy.cc
@@ -61,11 +61,13 @@ void WebSharedWorkerClientProxy::workerContextDestroyed() {
}
void WebSharedWorkerClientProxy::workerScriptLoaded() {
+ Send(new WorkerHostMsg_WorkerScriptLoaded(route_id_));
if (stub_)
stub_->WorkerScriptLoaded();
}
void WebSharedWorkerClientProxy::workerScriptLoadFailed() {
+ Send(new WorkerHostMsg_WorkerScriptLoadFailed(route_id_));
if (stub_)
stub_->WorkerScriptLoadFailed();
}
@@ -91,9 +93,7 @@ WebSharedWorkerClientProxy::notificationPresenter() {
WebApplicationCacheHost* WebSharedWorkerClientProxy::createApplicationCacheHost(
blink::WebApplicationCacheHostClient* client) {
DCHECK(!app_cache_host_);
- app_cache_host_ =
- new WorkerWebApplicationCacheHostImpl(stub_->appcache_init_info(),
- client);
+ app_cache_host_ = new WorkerWebApplicationCacheHostImpl(client);
// Remember the id of the instance we create so we have access to that
// value when creating nested dedicated workers in createWorker.
appcache_host_id_ = app_cache_host_->host_id();
diff --git a/content/worker/worker_thread.cc b/content/worker/worker_thread.cc
index d19701a..8425c16 100644
--- a/content/worker/worker_thread.cc
+++ b/content/worker/worker_thread.cc
@@ -117,18 +117,13 @@ bool WorkerThread::OnMessageReceived(const IPC::Message& msg) {
void WorkerThread::OnCreateWorker(
const WorkerProcessMsg_CreateWorker_Params& params) {
- WorkerAppCacheInitInfo appcache_init_info(
- params.creator_process_id,
- params.shared_worker_appcache_id);
-
// WebSharedWorkerStub own themselves.
new WebSharedWorkerStub(
params.url,
params.name,
params.content_security_policy,
params.security_policy_type,
- params.route_id,
- appcache_init_info);
+ params.route_id);
}
// The browser process is likely dead. Terminate all workers.
diff --git a/content/worker/worker_webapplicationcachehost_impl.cc b/content/worker/worker_webapplicationcachehost_impl.cc
index 23201c8..b4ccb40 100644
--- a/content/worker/worker_webapplicationcachehost_impl.cc
+++ b/content/worker/worker_webapplicationcachehost_impl.cc
@@ -10,12 +10,9 @@
namespace content {
WorkerWebApplicationCacheHostImpl::WorkerWebApplicationCacheHostImpl(
- const WorkerAppCacheInitInfo& init_info,
blink::WebApplicationCacheHostClient* client)
: WebApplicationCacheHostImpl(client,
WorkerThread::current()->appcache_dispatcher()->backend_proxy()) {
- backend()->SelectCacheForSharedWorker(host_id(),
- init_info.main_resource_appcache_id);
}
void WorkerWebApplicationCacheHostImpl::willStartMainResourceRequest(
diff --git a/content/worker/worker_webapplicationcachehost_impl.h b/content/worker/worker_webapplicationcachehost_impl.h
index 6f8385c..9662559 100644
--- a/content/worker/worker_webapplicationcachehost_impl.h
+++ b/content/worker/worker_webapplicationcachehost_impl.h
@@ -9,31 +9,13 @@
namespace content {
-// Information used to construct and initialize an appcache host
-// for a worker.
-struct WorkerAppCacheInitInfo {
- int parent_process_id;
- int64 main_resource_appcache_id; // Only valid for shared workers.
-
- WorkerAppCacheInitInfo()
- : parent_process_id(0),
- main_resource_appcache_id(0) {
- }
- WorkerAppCacheInitInfo(
- int process_id, int64 cache_id)
- : parent_process_id(process_id),
- main_resource_appcache_id(cache_id) {
- }
-};
-
class WorkerWebApplicationCacheHostImpl : public WebApplicationCacheHostImpl {
public:
WorkerWebApplicationCacheHostImpl(
- const WorkerAppCacheInitInfo& init_info,
blink::WebApplicationCacheHostClient* client);
- // Main resource loading is different for workers. The resource is
- // loaded by the creator of the worker rather than the worker itself.
+ // Main resource loading is different for workers. The main resource is
+ // loaded by the worker using WorkerScriptLoader.
// These overrides are stubbed out.
virtual void willStartMainResourceRequest(
blink::WebURLRequest&, const blink::WebFrame*);