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

Side by Side Diff: content/browser/service_worker/service_worker_context_wrapper.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: Null out browser_context_ in Shutdown 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_SERVICE_WORKER_CONTEXT_WRAPPER_H_ 5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_WRAPPER_H_
6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_WRAPPER_H_ 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_WRAPPER_H_
7 7
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "content/browser/service_worker/service_worker_context_core.h" 11 #include "content/browser/service_worker/service_worker_context_core.h"
12 #include "content/common/content_export.h" 12 #include "content/common/content_export.h"
13 #include "content/public/browser/service_worker_context.h" 13 #include "content/public/browser/service_worker_context.h"
14 14
15 namespace base { 15 namespace base {
16 class FilePath; 16 class FilePath;
17 } 17 }
18 18
19 namespace quota { 19 namespace quota {
20 class QuotaManagerProxy; 20 class QuotaManagerProxy;
21 } 21 }
22 22
23 namespace content { 23 namespace content {
24 24
25 class BrowserContext;
26 class ServiceWorkerContextCore;
25 class ServiceWorkerContextObserver; 27 class ServiceWorkerContextObserver;
26 28
27 // A refcounted wrapper class for our core object. Higher level content lib 29 // A refcounted wrapper class for our core object. Higher level content lib
28 // classes keep references to this class on mutliple threads. The inner core 30 // classes keep references to this class on mutliple threads. The inner core
29 // instance is strictly single threaded and is not refcounted, the core object 31 // instance is strictly single threaded and is not refcounted, the core object
30 // is what is used internally in the service worker lib. 32 // is what is used internally in the service worker lib.
31 class CONTENT_EXPORT ServiceWorkerContextWrapper 33 class CONTENT_EXPORT ServiceWorkerContextWrapper
32 : NON_EXPORTED_BASE(public ServiceWorkerContext), 34 : NON_EXPORTED_BASE(public ServiceWorkerContext),
33 public base::RefCountedThreadSafe<ServiceWorkerContextWrapper> { 35 public base::RefCountedThreadSafe<ServiceWorkerContextWrapper> {
34 public: 36 public:
35 ServiceWorkerContextWrapper(); 37 ServiceWorkerContextWrapper();
36 38
37 // Init and Shutdown are for use on the UI thread when the profile, 39 // Init and Shutdown are for use on the UI thread when the profile,
38 // storagepartition is being setup and torn down. 40 // storagepartition is being setup and torn down.
39 void Init(const base::FilePath& user_data_directory, 41 void Init(const base::FilePath& user_data_directory,
40 quota::QuotaManagerProxy* quota_manager_proxy); 42 quota::QuotaManagerProxy* quota_manager_proxy);
41 void Shutdown(); 43 void Shutdown();
42 44
43 // The core context is only for use on the IO thread. 45 // The core context is only for use on the IO thread.
44 ServiceWorkerContextCore* context(); 46 ServiceWorkerContextCore* context();
45 47
48 // Call this on the UI thread to get a reference to a running process suitable
49 // for starting the Service Worker at |script_url|. Processes in |process_ids|
50 // will be checked in order for existence, and if none exist, then a new
51 // process will be created. Posts |callback| to the IO thread to indicate
52 // whether creation succeeded and the process ID that has a new reference.
53 //
54 // Process creation can fail with SERVICE_WORKER_ERROR_START_WORKER_FAILED if
55 // RenderProcessHost::Init fails.
56 void IncrementWorkerRef(
kinuko 2014/04/25 13:46:35 Could these method be factored out into its own cl
Jeffrey Yasskin 2014/04/26 03:52:19 Done.
57 const std::vector<int>& process_ids,
58 const GURL& script_url,
59 const base::Callback<void(ServiceWorkerStatusCode, int process_id)>&
60 callback) const;
61
62 // Call this on the UI thread to drop a reference to a process that was
63 // running a Service Worker. This must match a call to IncrementWorkerRef.
64 static void DecrementWorkerRef(int process_id);
65
46 // ServiceWorkerContext implementation: 66 // ServiceWorkerContext implementation:
47 virtual void RegisterServiceWorker(const GURL& pattern, 67 virtual void RegisterServiceWorker(
48 const GURL& script_url, 68 const GURL& pattern,
49 int source_process_id, 69 const GURL& script_url,
50 const ResultCallback& continuation) 70 BrowserContext* context,
51 OVERRIDE; 71 const ResultCallback& continuation) OVERRIDE;
52
53 virtual void UnregisterServiceWorker(const GURL& pattern, 72 virtual void UnregisterServiceWorker(const GURL& pattern,
54 int source_process_id, 73 int source_process_id,
55 const ResultCallback& continuation) 74 const ResultCallback& continuation)
56 OVERRIDE; 75 OVERRIDE;
57 76
58 void AddObserver(ServiceWorkerContextObserver* observer); 77 void AddObserver(ServiceWorkerContextObserver* observer);
59 void RemoveObserver(ServiceWorkerContextObserver* observer); 78 void RemoveObserver(ServiceWorkerContextObserver* observer);
60 79
80 // These functions will be called on the UI thread, take a process ID to
81 // Increment/DecrementWorkerRefCount(), and should return whether the process
82 // existed. Null Callbacks reset the behavior to the default.
83 static void ResetWorkerRefCountOperationsForTest(
84 const base::Callback<bool(int)>& increment = base::Callback<bool(int)>(),
85 const base::Callback<bool(int)>& decrement = base::Callback<bool(int)>());
86
61 private: 87 private:
62 friend class base::RefCountedThreadSafe<ServiceWorkerContextWrapper>; 88 friend class base::RefCountedThreadSafe<ServiceWorkerContextWrapper>;
63 virtual ~ServiceWorkerContextWrapper(); 89 virtual ~ServiceWorkerContextWrapper();
64 90
91 BrowserContext* browser_context_; // UI thread-only; cleared in Shutdown().
65 scoped_ptr<ServiceWorkerContextCore> context_core_; 92 scoped_ptr<ServiceWorkerContextCore> context_core_;
66 scoped_refptr<ObserverListThreadSafe<ServiceWorkerContextObserver> > 93 scoped_refptr<ObserverListThreadSafe<ServiceWorkerContextObserver> >
67 observer_list_; 94 observer_list_;
68 }; 95 };
69 96
70 } // namespace content 97 } // namespace content
71 98
72 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_WRAPPER_H_ 99 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_WRAPPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698