OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROCESS_MANAGER_H_ | |
6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROCESS_MANAGER_H_ | |
7 | |
8 #include <vector> | |
9 | |
10 #include "base/callback.h" | |
11 #include "base/memory/scoped_ptr.h" | |
12 #include "base/memory/weak_ptr.h" | |
13 #include "content/common/service_worker/service_worker_status_code.h" | |
14 | |
15 class GURL; | |
16 | |
17 namespace content { | |
18 | |
19 class BrowserContext; | |
20 class ServiceWorkerContextWrapper; | |
21 | |
22 // Interacts with the UI thread to keep RenderProcessHosts alive while the | |
23 // ServiceWorker system is using them. | |
kinuko
2014/04/28 06:58:16
Can you also add a comment to note that an instanc
Jeffrey Yasskin
2014/04/28 20:47:40
Done.
| |
24 class CONTENT_EXPORT ServiceWorkerProcessManager { | |
25 public: | |
26 // |*this| must be scoped inside |context|. |increment_for_test| and | |
kinuko
2014/04/28 06:58:16
nit: |context| is a bit unclear in this context, |
Jeffrey Yasskin
2014/04/28 20:47:40
Whoops. That comment must be from when the Process
| |
27 // ||decrement_for_test| define how to look up a process by ID and increment | |
28 // |or decrement its worker reference count. | |
29 ServiceWorkerProcessManager( | |
30 ServiceWorkerContextWrapper* context_wrapper, | |
31 const base::Callback<bool(int)>& increment_for_test = | |
32 base::Callback<bool(int)>(), | |
33 const base::Callback<bool(int)>& decrement_for_test = | |
34 base::Callback<bool(int)>()); | |
kinuko
2014/04/28 06:58:16
In chromium we don't use optional parameters.. cou
Jeffrey Yasskin
2014/04/28 20:47:40
Done. Note that this makes it more complicated to
| |
35 | |
36 ~ServiceWorkerProcessManager(); | |
37 | |
38 // Returns a reference to a running process suitable for starting the Service | |
39 // Worker at |script_url|. Processes in |process_ids| will be checked in order | |
40 // for existence, and if none exist, then a new process will be created. Posts | |
41 // |callback| to the IO thread to indicate whether creation succeeded and the | |
42 // process ID that has a new reference. | |
43 // | |
44 // Allocation can fail with SERVICE_WORKER_ERROR_START_WORKER_FAILED if | |
45 // RenderProcessHost::Init fails. | |
46 void AllocateWorkerProcess( | |
47 const std::vector<int>& process_ids, | |
48 const GURL& script_url, | |
49 const base::Callback<void(ServiceWorkerStatusCode, int process_id)>& | |
50 callback) const; | |
51 | |
52 // Drops a reference to a process that was running a Service Worker. This | |
53 // must match a call to AllocateWorkerProcess. | |
54 void ReleaseWorkerProcess(int process_id); | |
55 | |
56 private: | |
57 bool IncrementWorkerRefcountByPid(int process_id) const; | |
58 bool DecrementWorkerRefcountByPid(int process_id) const; | |
59 | |
60 // These fields are only accessed on the UI thread after construction. | |
61 scoped_refptr<ServiceWorkerContextWrapper> context_wrapper_; | |
62 base::Callback<bool(int)> increment_for_test_; | |
63 base::Callback<bool(int)> decrement_for_test_; | |
64 | |
65 // Used to double-check that we don't access *this after it's destroyed. | |
66 base::WeakPtrFactory<ServiceWorkerProcessManager> weak_this_factory_; | |
67 base::WeakPtr<ServiceWorkerProcessManager> weak_this_; | |
68 }; | |
69 | |
70 } // namespace content | |
71 | |
72 namespace base { | |
73 // Specialized to post the deletion to the UI thread. | |
74 template <> | |
75 struct CONTENT_EXPORT DefaultDeleter<content::ServiceWorkerProcessManager> { | |
76 void operator()(content::ServiceWorkerProcessManager* ptr) const; | |
kinuko
2014/04/28 06:58:16
Aha, I'd just call DeleteSoon(BrowserThread::UI, F
Jeffrey Yasskin
2014/04/28 20:47:40
I was nervous about using a scoped_ptr that didn't
kinuko
2014/04/29 01:06:52
Yep, I can see some benefits here.
| |
77 }; | |
78 } // namespace base | |
79 | |
80 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROCESS_MANAGER_H_ | |
OLD | NEW |