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

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

Issue 443593002: ServiceWorker: Move worker candidate process knowledge to ServiceWorkerProcessManager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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
« no previous file with comments | « no previous file | content/browser/service_worker/embedded_worker_instance.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_INSTANCE_H_ 5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_INSTANCE_H_
6 #define CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_INSTANCE_H_ 6 #define CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_INSTANCE_H_
7 7
8 #include <map> 8 #include <map>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 ~EmbeddedWorkerInstance(); 69 ~EmbeddedWorkerInstance();
70 70
71 // Starts the worker. It is invalid to call this when the worker is not in 71 // Starts the worker. It is invalid to call this when the worker is not in
72 // STOPPED status. |callback| is invoked when the worker's process is created 72 // STOPPED status. |callback| is invoked when the worker's process is created
73 // if necessary and the IPC to evaluate the worker's script is sent. 73 // if necessary and the IPC to evaluate the worker's script is sent.
74 // Observer::OnStarted() is run when the worker is actually started. 74 // Observer::OnStarted() is run when the worker is actually started.
75 void Start(int64 service_worker_version_id, 75 void Start(int64 service_worker_version_id,
76 const GURL& scope, 76 const GURL& scope,
77 const GURL& script_url, 77 const GURL& script_url,
78 bool pause_after_download, 78 bool pause_after_download,
79 const std::vector<int>& possible_process_ids,
80 const StatusCallback& callback); 79 const StatusCallback& callback);
81 80
82 // Stops the worker. It is invalid to call this when the worker is 81 // Stops the worker. It is invalid to call this when the worker is
83 // not in STARTING or RUNNING status. 82 // not in STARTING or RUNNING status.
84 // This returns false if stopping a worker fails immediately, e.g. when 83 // This returns false if stopping a worker fails immediately, e.g. when
85 // IPC couldn't be sent to the worker. 84 // IPC couldn't be sent to the worker.
86 ServiceWorkerStatusCode Stop(); 85 ServiceWorkerStatusCode Stop();
87 86
88 // Sends |message| to the embedded worker running in the child process. 87 // Sends |message| to the embedded worker running in the child process.
89 // It is invalid to call this while the worker is not in RUNNING status. 88 // It is invalid to call this while the worker is not in RUNNING status.
90 ServiceWorkerStatusCode SendMessage(const IPC::Message& message); 89 ServiceWorkerStatusCode SendMessage(const IPC::Message& message);
91 90
92 void ResumeAfterDownload(); 91 void ResumeAfterDownload();
93 92
94 // Add or remove |process_id| to the internal process set where this
95 // worker can be started.
96 void AddProcessReference(int process_id);
97 void ReleaseProcessReference(int process_id);
98 bool HasProcessToRun() const { return !process_refs_.empty(); }
99
100 int embedded_worker_id() const { return embedded_worker_id_; } 93 int embedded_worker_id() const { return embedded_worker_id_; }
101 Status status() const { return status_; } 94 Status status() const { return status_; }
102 int process_id() const { return process_id_; } 95 int process_id() const { return process_id_; }
103 int thread_id() const { return thread_id_; } 96 int thread_id() const { return thread_id_; }
104 int worker_devtools_agent_route_id() const { 97 int worker_devtools_agent_route_id() const {
105 return worker_devtools_agent_route_id_; 98 return worker_devtools_agent_route_id_;
106 } 99 }
107 100
108 void AddListener(Listener* listener); 101 void AddListener(Listener* listener);
109 void RemoveListener(Listener* listener); 102 void RemoveListener(Listener* listener);
110 103
111 private: 104 private:
112 typedef ObserverList<Listener> ListenerList; 105 typedef ObserverList<Listener> ListenerList;
113 106
114 friend class EmbeddedWorkerRegistry; 107 friend class EmbeddedWorkerRegistry;
115 FRIEND_TEST_ALL_PREFIXES(EmbeddedWorkerInstanceTest, StartAndStop); 108 FRIEND_TEST_ALL_PREFIXES(EmbeddedWorkerInstanceTest, StartAndStop);
116 FRIEND_TEST_ALL_PREFIXES(EmbeddedWorkerInstanceTest, SortProcesses);
117
118 typedef std::map<int, int> ProcessRefMap;
119 109
120 // Constructor is called via EmbeddedWorkerRegistry::CreateWorker(). 110 // Constructor is called via EmbeddedWorkerRegistry::CreateWorker().
121 // This instance holds a ref of |registry|. 111 // This instance holds a ref of |registry|.
122 EmbeddedWorkerInstance(base::WeakPtr<ServiceWorkerContextCore> context, 112 EmbeddedWorkerInstance(base::WeakPtr<ServiceWorkerContextCore> context,
123 int embedded_worker_id); 113 int embedded_worker_id);
124 114
125 // Called back from ServiceWorkerProcessManager after Start() passes control 115 // Called back from ServiceWorkerProcessManager after Start() passes control
126 // to the UI thread to acquire a reference to the process. 116 // to the UI thread to acquire a reference to the process.
127 static void RunProcessAllocated( 117 static void RunProcessAllocated(
128 base::WeakPtr<EmbeddedWorkerInstance> instance, 118 base::WeakPtr<EmbeddedWorkerInstance> instance,
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 int column_number, 168 int column_number,
179 const GURL& source_url); 169 const GURL& source_url);
180 170
181 // Called back from Registry when the worker instance reports to the console. 171 // Called back from Registry when the worker instance reports to the console.
182 void OnReportConsoleMessage(int source_identifier, 172 void OnReportConsoleMessage(int source_identifier,
183 int message_level, 173 int message_level,
184 const base::string16& message, 174 const base::string16& message,
185 int line_number, 175 int line_number,
186 const GURL& source_url); 176 const GURL& source_url);
187 177
188 // Chooses a list of processes to try to start this worker in, ordered by how
189 // many clients are currently in those processes.
190 std::vector<int> SortProcesses(
191 const std::vector<int>& possible_process_ids) const;
192
193 base::WeakPtr<ServiceWorkerContextCore> context_; 178 base::WeakPtr<ServiceWorkerContextCore> context_;
194 scoped_refptr<EmbeddedWorkerRegistry> registry_; 179 scoped_refptr<EmbeddedWorkerRegistry> registry_;
195 const int embedded_worker_id_; 180 const int embedded_worker_id_;
196 Status status_; 181 Status status_;
197 182
198 // Current running information. -1 indicates the worker is not running. 183 // Current running information. -1 indicates the worker is not running.
199 int process_id_; 184 int process_id_;
200 int thread_id_; 185 int thread_id_;
201 int worker_devtools_agent_route_id_; 186 int worker_devtools_agent_route_id_;
202 187
203 ProcessRefMap process_refs_;
204 ListenerList listener_list_; 188 ListenerList listener_list_;
205 189
206 base::WeakPtrFactory<EmbeddedWorkerInstance> weak_factory_; 190 base::WeakPtrFactory<EmbeddedWorkerInstance> weak_factory_;
207 191
208 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerInstance); 192 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerInstance);
209 }; 193 };
210 194
211 } // namespace content 195 } // namespace content
212 196
213 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_INSTANCE_H_ 197 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_INSTANCE_H_
OLDNEW
« no previous file with comments | « no previous file | content/browser/service_worker/embedded_worker_instance.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698