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

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

Issue 140743012: Start EmbeddedWorker during registration - take 2 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Clean up log messages, tests Created 6 years, 10 months 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
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 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/browser/service_worker/embedded_worker_registry.h" 5 #include "content/browser/service_worker/embedded_worker_registry.h"
6 6
7 #include "base/stl_util.h" 7 #include "base/stl_util.h"
8 #include "content/browser/service_worker/embedded_worker_instance.h" 8 #include "content/browser/service_worker/embedded_worker_instance.h"
9 #include "content/browser/service_worker/service_worker_context_core.h" 9 #include "content/browser/service_worker/service_worker_context_core.h"
10 #include "content/common/service_worker/embedded_worker_messages.h" 10 #include "content/common/service_worker/embedded_worker_messages.h"
(...skipping 26 matching lines...) Expand all
37 } 37 }
38 38
39 ServiceWorkerStatusCode EmbeddedWorkerRegistry::StopWorker( 39 ServiceWorkerStatusCode EmbeddedWorkerRegistry::StopWorker(
40 int process_id, int embedded_worker_id) { 40 int process_id, int embedded_worker_id) {
41 return Send(process_id, 41 return Send(process_id,
42 new EmbeddedWorkerMsg_StopWorker(embedded_worker_id)); 42 new EmbeddedWorkerMsg_StopWorker(embedded_worker_id));
43 } 43 }
44 44
45 void EmbeddedWorkerRegistry::OnWorkerStarted( 45 void EmbeddedWorkerRegistry::OnWorkerStarted(
46 int process_id, int thread_id, int embedded_worker_id) { 46 int process_id, int thread_id, int embedded_worker_id) {
47 DCHECK(!ContainsKey(worker_process_map_, process_id)); 47 DCHECK(!ContainsKey(worker_process_map_, process_id) ||
48 worker_process_map_[process_id].count(embedded_worker_id) == 0);
48 WorkerInstanceMap::iterator found = worker_map_.find(embedded_worker_id); 49 WorkerInstanceMap::iterator found = worker_map_.find(embedded_worker_id);
49 if (found == worker_map_.end()) { 50 if (found == worker_map_.end()) {
50 LOG(ERROR) << "Worker " << embedded_worker_id << " not registered"; 51 LOG(ERROR) << "Worker " << embedded_worker_id << " not registered";
51 return; 52 return;
52 } 53 }
53 worker_process_map_[process_id] = embedded_worker_id; 54 worker_process_map_[process_id].insert(embedded_worker_id);
54 DCHECK_EQ(found->second->process_id(), process_id); 55 DCHECK_EQ(found->second->process_id(), process_id);
55 found->second->OnStarted(thread_id); 56 found->second->OnStarted(thread_id);
56 } 57 }
57 58
58 void EmbeddedWorkerRegistry::OnWorkerStopped( 59 void EmbeddedWorkerRegistry::OnWorkerStopped(
59 int process_id, int embedded_worker_id) { 60 int process_id, int embedded_worker_id) {
60 WorkerInstanceMap::iterator found = worker_map_.find(embedded_worker_id); 61 WorkerInstanceMap::iterator found = worker_map_.find(embedded_worker_id);
61 if (found == worker_map_.end()) { 62 if (found == worker_map_.end()) {
62 LOG(ERROR) << "Worker " << embedded_worker_id << " not registered"; 63 LOG(ERROR) << "Worker " << embedded_worker_id << " not registered";
63 return; 64 return;
64 } 65 }
65 DCHECK_EQ(found->second->process_id(), process_id); 66 DCHECK_EQ(found->second->process_id(), process_id);
66 worker_process_map_.erase(process_id); 67 worker_process_map_[process_id].erase(embedded_worker_id);
67 found->second->OnStopped(); 68 found->second->OnStopped();
68 } 69 }
69 70
70 void EmbeddedWorkerRegistry::OnSendMessageToBrowser( 71 void EmbeddedWorkerRegistry::OnSendMessageToBrowser(
71 int embedded_worker_id, const IPC::Message& message) { 72 int embedded_worker_id, const IPC::Message& message) {
72 WorkerInstanceMap::iterator found = worker_map_.find(embedded_worker_id); 73 WorkerInstanceMap::iterator found = worker_map_.find(embedded_worker_id);
73 if (found == worker_map_.end()) { 74 if (found == worker_map_.end()) {
74 LOG(ERROR) << "Worker " << embedded_worker_id << " not registered"; 75 LOG(ERROR) << "Worker " << embedded_worker_id << " not registered";
75 return; 76 return;
76 } 77 }
77 // TODO(kinuko): Filter out unexpected messages here and uncomment below 78 // TODO(kinuko): Filter out unexpected messages here and uncomment below
78 // when we actually define messages that are to be sent from child process 79 // when we actually define messages that are to be sent from child process
79 // to the browser via this channel. (We don't have any yet) 80 // to the browser via this channel. (We don't have any yet)
80 // found->second->OnMessageReceived(message); 81 // found->second->OnMessageReceived(message);
81 } 82 }
82 83
83 void EmbeddedWorkerRegistry::AddChildProcessSender( 84 void EmbeddedWorkerRegistry::AddChildProcessSender(
84 int process_id, IPC::Sender* sender) { 85 int process_id, IPC::Sender* sender) {
85 process_sender_map_[process_id] = sender; 86 process_sender_map_[process_id] = sender;
86 DCHECK(!ContainsKey(worker_process_map_, process_id)); 87 DCHECK(!ContainsKey(worker_process_map_, process_id));
87 } 88 }
88 89
89 void EmbeddedWorkerRegistry::RemoveChildProcessSender(int process_id) { 90 void EmbeddedWorkerRegistry::RemoveChildProcessSender(int process_id) {
90 process_sender_map_.erase(process_id); 91 process_sender_map_.erase(process_id);
91 std::map<int, int>::iterator found = worker_process_map_.find(process_id); 92 std::map<int, std::set<int> >::iterator found =
93 worker_process_map_.find(process_id);
92 if (found != worker_process_map_.end()) { 94 if (found != worker_process_map_.end()) {
kinuko 2014/02/04 03:37:53 nit: let's assign worker_process_map_[process_id]
alecflett 2014/02/04 20:09:04 Done.
93 int embedded_worker_id = found->second; 95 for (std::set<int>::const_iterator it =
94 DCHECK(ContainsKey(worker_map_, embedded_worker_id)); 96 worker_process_map_[process_id].begin();
95 worker_map_[embedded_worker_id]->OnStopped(); 97 it != worker_process_map_[process_id].end();
98 ++it) {
99 int embedded_worker_id = *it;
100 DCHECK(ContainsKey(worker_map_, embedded_worker_id));
101 worker_map_[embedded_worker_id]->OnStopped();
102 }
96 worker_process_map_.erase(found); 103 worker_process_map_.erase(found);
97 } 104 }
98 } 105 }
99 106
100 EmbeddedWorkerInstance* EmbeddedWorkerRegistry::GetWorker( 107 EmbeddedWorkerInstance* EmbeddedWorkerRegistry::GetWorker(
101 int embedded_worker_id) { 108 int embedded_worker_id) {
102 WorkerInstanceMap::iterator found = worker_map_.find(embedded_worker_id); 109 WorkerInstanceMap::iterator found = worker_map_.find(embedded_worker_id);
103 if (found == worker_map_.end()) 110 if (found == worker_map_.end())
104 return NULL; 111 return NULL;
105 return found->second; 112 return found->second;
(...skipping 14 matching lines...) Expand all
120 } 127 }
121 128
122 void EmbeddedWorkerRegistry::RemoveWorker(int process_id, 129 void EmbeddedWorkerRegistry::RemoveWorker(int process_id,
123 int embedded_worker_id) { 130 int embedded_worker_id) {
124 DCHECK(ContainsKey(worker_map_, embedded_worker_id)); 131 DCHECK(ContainsKey(worker_map_, embedded_worker_id));
125 worker_map_.erase(embedded_worker_id); 132 worker_map_.erase(embedded_worker_id);
126 worker_process_map_.erase(process_id); 133 worker_process_map_.erase(process_id);
127 } 134 }
128 135
129 } // namespace content 136 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698