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

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

Issue 238043002: Teach EmbeddedWorkerInstance to create a process when it needs one. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Handle 2 places where context_ could be NULL. Created 6 years, 7 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 #include <set> 9 #include <set>
10 #include <vector>
10 11
11 #include "base/basictypes.h" 12 #include "base/basictypes.h"
12 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/weak_ptr.h" 15 #include "base/memory/weak_ptr.h"
15 #include "base/strings/string16.h" 16 #include "base/strings/string16.h"
16 #include "content/common/content_export.h" 17 #include "content/common/content_export.h"
17 #include "content/common/service_worker/service_worker_status_code.h" 18 #include "content/common/service_worker/service_worker_status_code.h"
18 19
20 class EmbeddedWorkerMsg_StartWorker;
19 class GURL; 21 class GURL;
20 22
21 namespace IPC { 23 namespace IPC {
22 class Message; 24 class Message;
23 class Sender; 25 class Sender;
24 } 26 }
25 27
26 namespace content { 28 namespace content {
27 29
28 class EmbeddedWorkerInstance; 30 class EmbeddedWorkerInstance;
29 class ServiceWorkerContextCore; 31 class ServiceWorkerContextCore;
30 32
31 // Acts as a thin stub between MessageFilter and each EmbeddedWorkerInstance, 33 // Acts as a thin stub between MessageFilter and each EmbeddedWorkerInstance,
32 // which sends/receives messages to/from each EmbeddedWorker in child process. 34 // which sends/receives messages to/from each EmbeddedWorker in child process.
33 // 35 //
34 // Hangs off ServiceWorkerContextCore (its reference is also held by each 36 // Hangs off ServiceWorkerContextCore (its reference is also held by each
35 // EmbeddedWorkerInstance). Operated only on IO thread. 37 // EmbeddedWorkerInstance). Operated only on IO thread.
36 class CONTENT_EXPORT EmbeddedWorkerRegistry 38 class CONTENT_EXPORT EmbeddedWorkerRegistry
37 : public NON_EXPORTED_BASE(base::RefCounted<EmbeddedWorkerRegistry>) { 39 : public NON_EXPORTED_BASE(base::RefCounted<EmbeddedWorkerRegistry>) {
38 public: 40 public:
41 typedef base::Callback<void(ServiceWorkerStatusCode)> StatusCallback;
42
39 explicit EmbeddedWorkerRegistry( 43 explicit EmbeddedWorkerRegistry(
40 base::WeakPtr<ServiceWorkerContextCore> context); 44 base::WeakPtr<ServiceWorkerContextCore> context);
41 45
42 bool OnMessageReceived(const IPC::Message& message); 46 bool OnMessageReceived(const IPC::Message& message);
43 47
44 // Creates and removes a new worker instance entry for bookkeeping. 48 // Creates and removes a new worker instance entry for bookkeeping.
45 // This doesn't actually start or stop the worker. 49 // This doesn't actually start or stop the worker.
46 scoped_ptr<EmbeddedWorkerInstance> CreateWorker(); 50 scoped_ptr<EmbeddedWorkerInstance> CreateWorker();
47 51
48 // Called from EmbeddedWorkerInstance, relayed to the child process. 52 // Called from EmbeddedWorkerInstance, relayed to the child process.
49 ServiceWorkerStatusCode StartWorker(int process_id, 53 void StartWorker(const std::vector<int>& process_ids,
50 int embedded_worker_id, 54 int embedded_worker_id,
51 int64 service_worker_version_id, 55 int64 service_worker_version_id,
52 const GURL& scope, 56 const GURL& scope,
53 const GURL& script_url); 57 const GURL& script_url,
58 const StatusCallback& callback);
54 ServiceWorkerStatusCode StopWorker(int process_id, 59 ServiceWorkerStatusCode StopWorker(int process_id,
55 int embedded_worker_id); 60 int embedded_worker_id);
56 61
62 // Stop all active workers, even if they're handling events.
63 void Shutdown();
64
57 // Called back from EmbeddedWorker in the child process, relayed via 65 // Called back from EmbeddedWorker in the child process, relayed via
58 // ServiceWorkerDispatcherHost. 66 // ServiceWorkerDispatcherHost.
59 void OnWorkerStarted(int process_id, int thread_id, int embedded_worker_id); 67 void OnWorkerStarted(int process_id, int thread_id, int embedded_worker_id);
60 void OnWorkerStopped(int process_id, int embedded_worker_id); 68 void OnWorkerStopped(int process_id, int embedded_worker_id);
61 void OnReportException(int embedded_worker_id, 69 void OnReportException(int embedded_worker_id,
62 const base::string16& error_message, 70 const base::string16& error_message,
63 int line_number, 71 int line_number,
64 int column_number, 72 int column_number,
65 const GURL& source_url); 73 const GURL& source_url);
66 void OnReportConsoleMessage(int embedded_worker_id, 74 void OnReportConsoleMessage(int embedded_worker_id,
(...skipping 11 matching lines...) Expand all
78 EmbeddedWorkerInstance* GetWorker(int embedded_worker_id); 86 EmbeddedWorkerInstance* GetWorker(int embedded_worker_id);
79 87
80 private: 88 private:
81 friend class base::RefCounted<EmbeddedWorkerRegistry>; 89 friend class base::RefCounted<EmbeddedWorkerRegistry>;
82 friend class EmbeddedWorkerInstance; 90 friend class EmbeddedWorkerInstance;
83 91
84 typedef std::map<int, EmbeddedWorkerInstance*> WorkerInstanceMap; 92 typedef std::map<int, EmbeddedWorkerInstance*> WorkerInstanceMap;
85 typedef std::map<int, IPC::Sender*> ProcessToSenderMap; 93 typedef std::map<int, IPC::Sender*> ProcessToSenderMap;
86 94
87 ~EmbeddedWorkerRegistry(); 95 ~EmbeddedWorkerRegistry();
96
97 void StartWorkerWithProcessId(
98 int embedded_worker_id,
99 scoped_ptr<EmbeddedWorkerMsg_StartWorker> message,
100 const StatusCallback& callback,
101 ServiceWorkerStatusCode status,
102 int process_id);
103
88 ServiceWorkerStatusCode Send(int process_id, IPC::Message* message); 104 ServiceWorkerStatusCode Send(int process_id, IPC::Message* message);
89 105
90 // RemoveWorker is called when EmbeddedWorkerInstance is destructed. 106 // RemoveWorker is called when EmbeddedWorkerInstance is destructed.
91 // |process_id| could be invalid (i.e. -1) if it's not running. 107 // |process_id| could be invalid (i.e. -1) if it's not running.
92 void RemoveWorker(int process_id, int embedded_worker_id); 108 void RemoveWorker(int process_id, int embedded_worker_id);
93 109
94 base::WeakPtr<ServiceWorkerContextCore> context_; 110 base::WeakPtr<ServiceWorkerContextCore> context_;
95 111
96 WorkerInstanceMap worker_map_; 112 WorkerInstanceMap worker_map_;
97 ProcessToSenderMap process_sender_map_; 113 ProcessToSenderMap process_sender_map_;
98 114
99 // Map from process_id to embedded_worker_id. 115 // Map from process_id to embedded_worker_id.
100 // This map only contains running workers. 116 // This map only contains running workers.
101 std::map<int, std::set<int> > worker_process_map_; 117 std::map<int, std::set<int> > worker_process_map_;
102 118
103 int next_embedded_worker_id_; 119 int next_embedded_worker_id_;
104 120
105 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerRegistry); 121 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerRegistry);
106 }; 122 };
107 123
108 } // namespace content 124 } // namespace content
109 125
110 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_REGISTRY_H_ 126 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_REGISTRY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698