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

Side by Side Diff: content/browser/service_worker/embedded_worker_registry.cc

Issue 85023003: EmbeddedWorker, browser side code (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: build fix Created 7 years 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
(Empty)
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "content/browser/service_worker/embedded_worker_registry.h"
6
7 #include "base/stl_util.h"
8 #include "content/browser/service_worker/embedded_worker_instance.h"
9 #include "content/browser/service_worker/service_worker_context_core.h"
10 #include "content/common/service_worker_messages.h"
11 #include "ipc/ipc_message.h"
12 #include "ipc/ipc_sender.h"
13
14 namespace content {
15
16 EmbeddedWorkerRegistry::EmbeddedWorkerRegistry(
17 base::WeakPtr<ServiceWorkerContextCore> context)
18 : context_(context),
19 next_embedded_worker_id_(0) {}
20
21 scoped_ptr<EmbeddedWorkerInstance> EmbeddedWorkerRegistry::CreateWorker() {
22 return scoped_ptr<EmbeddedWorkerInstance>(
23 new EmbeddedWorkerInstance(this, next_embedded_worker_id_++));
24 }
25
26 void EmbeddedWorkerRegistry::RemoveWorker(int embedded_worker_id) {
27 DCHECK(ContainsKey(worker_map_, embedded_worker_id));
28 worker_map_.erase(embedded_worker_id);
29 }
30
31 bool EmbeddedWorkerRegistry::StartWorker(
32 int process_id,
33 int embedded_worker_id,
34 int64 service_worker_version_id,
35 const GURL& script_url) {
36 return Send(process_id,
37 new ServiceWorkerMsg_StartWorker(embedded_worker_id,
38 service_worker_version_id,
39 script_url));
40 }
41
42 bool EmbeddedWorkerRegistry::StopWorker(int process_id,
43 int embedded_worker_id) {
44 return Send(process_id,
45 new ServiceWorkerMsg_TerminateWorker(embedded_worker_id));
46 }
47
48 void EmbeddedWorkerRegistry::AddChildProcessSender(
49 int process_id, IPC::Sender* sender) {
50 process_sender_map_[process_id] = sender;
51 }
52
53 void EmbeddedWorkerRegistry::RemoveChildProcessSender(int process_id) {
54 process_sender_map_.erase(process_id);
55 }
56
57 EmbeddedWorkerRegistry::~EmbeddedWorkerRegistry() {}
58
59 bool EmbeddedWorkerRegistry::Send(int process_id, IPC::Message* message) {
60 if (!context_)
61 return false;
62 ProcessToSenderMap::iterator found = process_sender_map_.find(process_id);
63 if (found == process_sender_map_.end())
64 return false;
65 return found->second->Send(message);
66 }
67
68 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698