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

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

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 #ifndef CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_REGISTRY_H_ 5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_REGISTRY_H_
6 #define CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_REGISTRY_H_ 6 #define CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_REGISTRY_H_
7 7
8 #include <map> 8 #include <map>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
14 #include "content/common/content_export.h" 14 #include "content/common/content_export.h"
15 #include "content/common/service_worker/service_worker_status_code.h"
15 16
16 class GURL; 17 class GURL;
17 18
18 namespace IPC { 19 namespace IPC {
19 class Message; 20 class Message;
20 class Sender; 21 class Sender;
21 } 22 }
22 23
23 namespace content { 24 namespace content {
24 25
25 class EmbeddedWorkerInstance; 26 class EmbeddedWorkerInstance;
26 class ServiceWorkerContextCore; 27 class ServiceWorkerContextCore;
27 28
28 // Acts as a thin stub between MessageFilter and each EmbeddedWorkerInstance, 29 // Acts as a thin stub between MessageFilter and each EmbeddedWorkerInstance,
29 // which sends/receives messages to/from each EmbeddedWorker in child process. 30 // which sends/receives messages to/from each EmbeddedWorker in child process.
30 // 31 //
31 // Hangs off ServiceWorkerContextCore (its reference is also held by each 32 // Hangs off ServiceWorkerContextCore (its reference is also held by each
32 // EmbeddedWorkerInstance). Operated only on IO thread. 33 // EmbeddedWorkerInstance). Operated only on IO thread.
33 class CONTENT_EXPORT EmbeddedWorkerRegistry 34 class CONTENT_EXPORT EmbeddedWorkerRegistry
34 : public NON_EXPORTED_BASE(base::RefCounted<EmbeddedWorkerRegistry>) { 35 : public NON_EXPORTED_BASE(base::RefCounted<EmbeddedWorkerRegistry>) {
35 public: 36 public:
36 explicit EmbeddedWorkerRegistry( 37 explicit EmbeddedWorkerRegistry(
37 base::WeakPtr<ServiceWorkerContextCore> context); 38 base::WeakPtr<ServiceWorkerContextCore> context);
38 39
39 // Creates and removes a new worker instance entry for bookkeeping. 40 // Creates and removes a new worker instance entry for bookkeeping.
40 // This doesn't actually start or stop the worker. 41 // This doesn't actually start or stop the worker.
41 scoped_ptr<EmbeddedWorkerInstance> CreateWorker(); 42 scoped_ptr<EmbeddedWorkerInstance> CreateWorker();
42 43
43 // Called from EmbeddedWorkerInstance, relayed to the child process. 44 // Called from EmbeddedWorkerInstance, relayed to the child process.
44 bool StartWorker(int process_id, 45 ServiceWorkerStatusCode StartWorker(int process_id,
45 int embedded_worker_id, 46 int embedded_worker_id,
46 int64 service_worker_version_id, 47 int64 service_worker_version_id,
47 const GURL& script_url); 48 const GURL& script_url);
48 bool StopWorker(int process_id, 49 ServiceWorkerStatusCode StopWorker(int process_id,
49 int embedded_worker_id); 50 int embedded_worker_id);
50 51
51 // Called back from EmbeddedWorker in the child process, relayed via 52 // Called back from EmbeddedWorker in the child process, relayed via
52 // ServiceWorkerDispatcherHost. 53 // ServiceWorkerDispatcherHost.
53 void OnWorkerStarted(int process_id, int thread_id, int embedded_worker_id); 54 void OnWorkerStarted(int process_id, int thread_id, int embedded_worker_id);
54 void OnWorkerStopped(int process_id, int embedded_worker_id); 55 void OnWorkerStopped(int process_id, int embedded_worker_id);
55 void OnSendMessageToBrowser(int embedded_worker_id, 56 void OnSendMessageToBrowser(int embedded_worker_id,
56 const IPC::Message& message); 57 const IPC::Message& message);
57 58
58 // Keeps a map from process_id to sender information. 59 // Keeps a map from process_id to sender information.
59 void AddChildProcessSender(int process_id, IPC::Sender* sender); 60 void AddChildProcessSender(int process_id, IPC::Sender* sender);
60 void RemoveChildProcessSender(int process_id); 61 void RemoveChildProcessSender(int process_id);
61 62
62 // Returns an embedded worker instance for given |embedded_worker_id|. 63 // Returns an embedded worker instance for given |embedded_worker_id|.
63 EmbeddedWorkerInstance* GetWorker(int embedded_worker_id); 64 EmbeddedWorkerInstance* GetWorker(int embedded_worker_id);
64 65
65 private: 66 private:
66 friend class base::RefCounted<EmbeddedWorkerRegistry>; 67 friend class base::RefCounted<EmbeddedWorkerRegistry>;
67 friend class EmbeddedWorkerInstance; 68 friend class EmbeddedWorkerInstance;
68 69
69 typedef std::map<int, EmbeddedWorkerInstance*> WorkerInstanceMap; 70 typedef std::map<int, EmbeddedWorkerInstance*> WorkerInstanceMap;
70 typedef std::map<int, IPC::Sender*> ProcessToSenderMap; 71 typedef std::map<int, IPC::Sender*> ProcessToSenderMap;
71 72
72 ~EmbeddedWorkerRegistry(); 73 ~EmbeddedWorkerRegistry();
73 bool Send(int process_id, IPC::Message* message); 74 ServiceWorkerStatusCode Send(int process_id, IPC::Message* message);
74 75
75 // RemoveWorker is called when EmbeddedWorkerInstance is destructed. 76 // RemoveWorker is called when EmbeddedWorkerInstance is destructed.
76 // |process_id| could be invalid (i.e. -1) if it's not running. 77 // |process_id| could be invalid (i.e. -1) if it's not running.
77 void RemoveWorker(int process_id, int embedded_worker_id); 78 void RemoveWorker(int process_id, int embedded_worker_id);
78 79
79 base::WeakPtr<ServiceWorkerContextCore> context_; 80 base::WeakPtr<ServiceWorkerContextCore> context_;
80 81
81 WorkerInstanceMap worker_map_; 82 WorkerInstanceMap worker_map_;
82 ProcessToSenderMap process_sender_map_; 83 ProcessToSenderMap process_sender_map_;
83 84
84 // Map from process_id to embedded_worker_id. 85 // Map from process_id to embedded_worker_id.
85 // This map only contains running workers. 86 // This map only contains running workers.
86 std::map<int, int> worker_process_map_; 87 std::map<int, int> worker_process_map_;
87 88
88 int next_embedded_worker_id_; 89 int next_embedded_worker_id_;
89 90
90 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerRegistry); 91 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerRegistry);
91 }; 92 };
92 93
93 } // namespace content 94 } // namespace content
94 95
95 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_REGISTRY_H_ 96 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_REGISTRY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698