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

Side by Side Diff: content/public/browser/service_worker_context.h

Issue 2166523003: Add ref count to service workers for extension API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments from Devlin & MichaelN Created 4 years, 2 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 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_PUBLIC_BROWSER_SERVICE_WORKER_CONTEXT_H_ 5 #ifndef CONTENT_PUBLIC_BROWSER_SERVICE_WORKER_CONTEXT_H_
6 #define CONTENT_PUBLIC_BROWSER_SERVICE_WORKER_CONTEXT_H_ 6 #define CONTENT_PUBLIC_BROWSER_SERVICE_WORKER_CONTEXT_H_
7 7
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 10
(...skipping 15 matching lines...) Expand all
26 typedef GURL Scope; 26 typedef GURL Scope;
27 27
28 typedef base::Callback<void(bool success)> ResultCallback; 28 typedef base::Callback<void(bool success)> ResultCallback;
29 29
30 typedef base::Callback<void(const std::vector<ServiceWorkerUsageInfo>& 30 typedef base::Callback<void(const std::vector<ServiceWorkerUsageInfo>&
31 usage_info)> GetUsageInfoCallback; 31 usage_info)> GetUsageInfoCallback;
32 32
33 typedef base::Callback<void(bool has_service_worker)> 33 typedef base::Callback<void(bool has_service_worker)>
34 CheckHasServiceWorkerCallback; 34 CheckHasServiceWorkerCallback;
35 35
36 typedef base::Callback<void(size_t external_request_count)>
37 GetPendingExternalRequestCountCallback;
38
36 // Registers the header name which should not be passed to the ServiceWorker. 39 // Registers the header name which should not be passed to the ServiceWorker.
37 // Must be called from the IO thread. 40 // Must be called from the IO thread.
38 CONTENT_EXPORT static void AddExcludedHeadersForFetchEvent( 41 CONTENT_EXPORT static void AddExcludedHeadersForFetchEvent(
39 const std::set<std::string>& header_names); 42 const std::set<std::string>& header_names);
40 43
41 // Returns true if the header name should not be passed to the ServiceWorker. 44 // Returns true if the header name should not be passed to the ServiceWorker.
42 // Must be called from the IO thread. 45 // Must be called from the IO thread.
43 static bool IsExcludedHeaderNameForFetchEvent(const std::string& header_name); 46 static bool IsExcludedHeaderNameForFetchEvent(const std::string& header_name);
44 47
45 // Equivalent to calling navigator.serviceWorker.register(script_url, {scope: 48 // Equivalent to calling navigator.serviceWorker.register(script_url, {scope:
46 // pattern}) from a renderer, except that |pattern| is an absolute URL instead 49 // pattern}) from a renderer, except that |pattern| is an absolute URL instead
47 // of relative to some current origin. |callback| is passed true when the JS 50 // of relative to some current origin. |callback| is passed true when the JS
48 // promise is fulfilled or false when the JS promise is rejected. 51 // promise is fulfilled or false when the JS promise is rejected.
49 // 52 //
50 // The registration can fail if: 53 // The registration can fail if:
51 // * |script_url| is on a different origin from |pattern| 54 // * |script_url| is on a different origin from |pattern|
52 // * Fetching |script_url| fails. 55 // * Fetching |script_url| fails.
53 // * |script_url| fails to parse or its top-level execution fails. 56 // * |script_url| fails to parse or its top-level execution fails.
54 // TODO: The error message for this needs to be available to developers. 57 // TODO: The error message for this needs to be available to developers.
55 // * Something unexpected goes wrong, like a renderer crash or a full disk. 58 // * Something unexpected goes wrong, like a renderer crash or a full disk.
56 // 59 //
57 // This function can be called from any thread, but the callback will always 60 // This function can be called from any thread, but the callback will always
58 // be called on the UI thread. 61 // be called on the UI thread.
59 virtual void RegisterServiceWorker(const Scope& pattern, 62 virtual void RegisterServiceWorker(const Scope& pattern,
60 const GURL& script_url, 63 const GURL& script_url,
61 const ResultCallback& callback) = 0; 64 const ResultCallback& callback) = 0;
62 65
66 // Ref count mechanism for embedder to increment/decrement activity count of a
67 // service worker.
68 // Must be called from the IO thread. Returns whether or not changing the
69 // activity count succeeded.
70 virtual bool IncrementPendingActivity(int64_t service_worker_version_id,
Devlin 2016/10/07 15:13:22 Drive-by: Since these are all associated with a sp
lazyboy 2016/10/07 18:50:10 OK, will do before sending out to content/public r
michaeln 2016/10/07 20:10:30 i was thinking a rename would be good too, maybe m
lazyboy 2016/10/07 21:28:41 Changed the names to reflect this is request inste
71 const std::string& request_uuid) = 0;
72 virtual bool DecrementPendingActivity(int64_t service_worker_version_id,
73 const std::string& request_uuid) = 0;
74
63 // Equivalent to calling navigator.serviceWorker.unregister(pattern) from a 75 // Equivalent to calling navigator.serviceWorker.unregister(pattern) from a
64 // renderer, except that |pattern| is an absolute URL instead of relative to 76 // renderer, except that |pattern| is an absolute URL instead of relative to
65 // some current origin. |callback| is passed true when the JS promise is 77 // some current origin. |callback| is passed true when the JS promise is
66 // fulfilled or false when the JS promise is rejected. 78 // fulfilled or false when the JS promise is rejected.
67 // 79 //
68 // Unregistration can fail if: 80 // Unregistration can fail if:
69 // * No Service Worker was registered for |pattern|. 81 // * No Service Worker was registered for |pattern|.
70 // * Something unexpected goes wrong, like a renderer crash. 82 // * Something unexpected goes wrong, like a renderer crash.
71 // 83 //
72 // This function can be called from any thread, but the callback will always 84 // This function can be called from any thread, but the callback will always
(...skipping 16 matching lines...) Expand all
89 // this still returns true even if there is a Service Worker registration 101 // this still returns true even if there is a Service Worker registration
90 // which has a longer match for |other_url|. 102 // which has a longer match for |other_url|.
91 // 103 //
92 // This function can be called from any thread, but the callback will always 104 // This function can be called from any thread, but the callback will always
93 // be called on the UI thread. 105 // be called on the UI thread.
94 virtual void CheckHasServiceWorker( 106 virtual void CheckHasServiceWorker(
95 const GURL& url, 107 const GURL& url,
96 const GURL& other_url, 108 const GURL& other_url,
97 const CheckHasServiceWorkerCallback& callback) = 0; 109 const CheckHasServiceWorkerCallback& callback) = 0;
98 110
111 // Returns the pending activity count for the worker with the specified
112 // |origin| via |callback|.
113 virtual void GetPendingExternalRequestCountForTest(
michaeln 2016/10/07 20:10:30 and this could be something like CountExternalRequ
lazyboy 2016/10/07 21:28:41 Done.
114 const GURL& origin,
115 const GetPendingExternalRequestCountCallback& callback) = 0;
116
99 // Stops all running workers on the given |origin|. 117 // Stops all running workers on the given |origin|.
100 // 118 //
101 // This function can be called from any thread. 119 // This function can be called from any thread.
102 virtual void StopAllServiceWorkersForOrigin(const GURL& origin) = 0; 120 virtual void StopAllServiceWorkersForOrigin(const GURL& origin) = 0;
103 121
104 // Stops all running service workers and unregisters all service worker 122 // Stops all running service workers and unregisters all service worker
105 // registrations. This method is used in LayoutTests to make sure that the 123 // registrations. This method is used in LayoutTests to make sure that the
106 // existing service worker will not affect the succeeding tests. 124 // existing service worker will not affect the succeeding tests.
107 // 125 //
108 // This function can be called from any thread, but the callback will always 126 // This function can be called from any thread, but the callback will always
(...skipping 13 matching lines...) Expand all
122 const ResultCallback& callback) = 0; 140 const ResultCallback& callback) = 0;
123 141
124 protected: 142 protected:
125 ServiceWorkerContext() {} 143 ServiceWorkerContext() {}
126 virtual ~ServiceWorkerContext() {} 144 virtual ~ServiceWorkerContext() {}
127 }; 145 };
128 146
129 } // namespace content 147 } // namespace content
130 148
131 #endif // CONTENT_PUBLIC_BROWSER_SERVICE_WORKER_CONTEXT_H_ 149 #endif // CONTENT_PUBLIC_BROWSER_SERVICE_WORKER_CONTEXT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698