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

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

Issue 147593006: Refine error code returned by ServiceWorkerVersion::StartWorker (e.g. PROCESS_NOT_FOUND etc) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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"
11 #include "ipc/ipc_message.h" 11 #include "ipc/ipc_message.h"
12 #include "ipc/ipc_sender.h" 12 #include "ipc/ipc_sender.h"
13 13
14 namespace content { 14 namespace content {
15 15
16 EmbeddedWorkerRegistry::EmbeddedWorkerRegistry( 16 EmbeddedWorkerRegistry::EmbeddedWorkerRegistry(
17 base::WeakPtr<ServiceWorkerContextCore> context) 17 base::WeakPtr<ServiceWorkerContextCore> context)
18 : context_(context), 18 : context_(context),
19 next_embedded_worker_id_(0) {} 19 next_embedded_worker_id_(0) {}
20 20
21 scoped_ptr<EmbeddedWorkerInstance> EmbeddedWorkerRegistry::CreateWorker() { 21 scoped_ptr<EmbeddedWorkerInstance> EmbeddedWorkerRegistry::CreateWorker() {
22 scoped_ptr<EmbeddedWorkerInstance> worker( 22 scoped_ptr<EmbeddedWorkerInstance> worker(
23 new EmbeddedWorkerInstance(this, next_embedded_worker_id_)); 23 new EmbeddedWorkerInstance(this, next_embedded_worker_id_));
24 worker_map_[next_embedded_worker_id_++] = worker.get(); 24 worker_map_[next_embedded_worker_id_++] = worker.get();
25 return worker.Pass(); 25 return worker.Pass();
26 } 26 }
27 27
28 bool EmbeddedWorkerRegistry::StartWorker( 28 ServiceWorkerStatusCode EmbeddedWorkerRegistry::StartWorker(
29 int process_id, 29 int process_id,
30 int embedded_worker_id, 30 int embedded_worker_id,
31 int64 service_worker_version_id, 31 int64 service_worker_version_id,
32 const GURL& script_url) { 32 const GURL& script_url) {
33 return Send(process_id, 33 return Send(process_id,
34 new EmbeddedWorkerMsg_StartWorker(embedded_worker_id, 34 new EmbeddedWorkerMsg_StartWorker(embedded_worker_id,
35 service_worker_version_id, 35 service_worker_version_id,
36 script_url)); 36 script_url));
37 } 37 }
38 38
39 bool EmbeddedWorkerRegistry::StopWorker(int process_id, 39 ServiceWorkerStatusCode EmbeddedWorkerRegistry::StopWorker(
40 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 WorkerInstanceMap::iterator found = worker_map_.find(embedded_worker_id); 48 WorkerInstanceMap::iterator found = worker_map_.find(embedded_worker_id);
49 if (found == worker_map_.end()) { 49 if (found == worker_map_.end()) {
50 LOG(ERROR) << "Worker " << embedded_worker_id << " not registered"; 50 LOG(ERROR) << "Worker " << embedded_worker_id << " not registered";
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 EmbeddedWorkerInstance* EmbeddedWorkerRegistry::GetWorker( 100 EmbeddedWorkerInstance* EmbeddedWorkerRegistry::GetWorker(
101 int embedded_worker_id) { 101 int embedded_worker_id) {
102 WorkerInstanceMap::iterator found = worker_map_.find(embedded_worker_id); 102 WorkerInstanceMap::iterator found = worker_map_.find(embedded_worker_id);
103 if (found == worker_map_.end()) 103 if (found == worker_map_.end())
104 return NULL; 104 return NULL;
105 return found->second; 105 return found->second;
106 } 106 }
107 107
108 EmbeddedWorkerRegistry::~EmbeddedWorkerRegistry() {} 108 EmbeddedWorkerRegistry::~EmbeddedWorkerRegistry() {}
109 109
110 bool EmbeddedWorkerRegistry::Send(int process_id, IPC::Message* message) { 110 ServiceWorkerStatusCode EmbeddedWorkerRegistry::Send(
111 int process_id, IPC::Message* message) {
111 if (!context_) 112 if (!context_)
112 return false; 113 return SERVICE_WORKER_ERROR_ABORT;
113 ProcessToSenderMap::iterator found = process_sender_map_.find(process_id); 114 ProcessToSenderMap::iterator found = process_sender_map_.find(process_id);
114 if (found == process_sender_map_.end()) 115 if (found == process_sender_map_.end())
115 return false; 116 return SERVICE_WORKER_ERROR_PROCESS_NOT_FOUND;
116 return found->second->Send(message); 117 if (!found->second->Send(message))
118 return SERVICE_WORKER_ERROR_IPC_FAILED;
119 return SERVICE_WORKER_OK;
117 } 120 }
118 121
119 void EmbeddedWorkerRegistry::RemoveWorker(int process_id, 122 void EmbeddedWorkerRegistry::RemoveWorker(int process_id,
120 int embedded_worker_id) { 123 int embedded_worker_id) {
121 DCHECK(ContainsKey(worker_map_, embedded_worker_id)); 124 DCHECK(ContainsKey(worker_map_, embedded_worker_id));
122 worker_map_.erase(embedded_worker_id); 125 worker_map_.erase(embedded_worker_id);
123 worker_process_map_.erase(process_id); 126 worker_process_map_.erase(process_id);
124 } 127 }
125 128
126 } // namespace content 129 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698