| OLD | NEW |
| 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_VERSION_H_ | 5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ |
| 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ | 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 // if there're any (see RegisterStatusChangeCallback). | 108 // if there're any (see RegisterStatusChangeCallback). |
| 109 void SetStatus(Status status); | 109 void SetStatus(Status status); |
| 110 | 110 |
| 111 // Registers status change callback. (This is for one-off observation, | 111 // Registers status change callback. (This is for one-off observation, |
| 112 // the consumer needs to re-register if it wants to continue observing | 112 // the consumer needs to re-register if it wants to continue observing |
| 113 // status changes) | 113 // status changes) |
| 114 void RegisterStatusChangeCallback(const base::Closure& callback); | 114 void RegisterStatusChangeCallback(const base::Closure& callback); |
| 115 | 115 |
| 116 // Starts an embedded worker for this version. | 116 // Starts an embedded worker for this version. |
| 117 // This returns OK (success) if the worker is already running. | 117 // This returns OK (success) if the worker is already running. |
| 118 void StartWorker(const StatusCallback& callback); | 118 // |potential_process_ids| is a list of processes in which to start the |
| 119 // worker. |
| 120 void StartWorker(const StatusCallback& callback, |
| 121 const std::vector<int>& potential_process_ids); |
| 119 | 122 |
| 120 // Starts an embedded worker for this version. | 123 // Starts an embedded worker for this version. |
| 121 // This returns OK (success) if the worker is already stopped. | 124 // This returns OK (success) if the worker is already stopped. |
| 122 void StopWorker(const StatusCallback& callback); | 125 void StopWorker(const StatusCallback& callback); |
| 123 | 126 |
| 124 // Sends an IPC message to the worker. | 127 // Sends an IPC message to the worker. |
| 125 // If the worker is not running this first tries to start it by | 128 // If the worker is not running this first tries to start it by |
| 126 // calling StartWorker internally. | 129 // calling StartWorker internally. |
| 127 // |callback| can be null if the sender does not need to know if the | 130 // |callback| can be null if the sender does not need to know if the |
| 128 // message is successfully sent or not. | 131 // message is successfully sent or not. |
| 129 void SendMessage(const IPC::Message& message, const StatusCallback& callback); | 132 void SendMessage(const IPC::Message& message, const StatusCallback& callback); |
| 130 | 133 |
| 131 // Sends install event to the associated embedded worker and asynchronously | 134 // Sends install event to the associated embedded worker and asynchronously |
| 132 // calls |callback| when it errors out or it gets response from the worker | 135 // calls |callback| when it errors out or it gets response from the worker |
| 133 // to notify install completion. | 136 // to notify install completion. |
| 134 // |active_version_id| must be a valid positive ID | 137 // |active_version_id| must be a valid positive ID |
| 135 // if there's an active (previous) version running. | 138 // if there's an active (previous) version running. |
| 136 // | 139 // |
| 137 // This must be called when the status() is NEW. Calling this changes | 140 // This must be called when the status() is NEW. Calling this changes |
| 138 // the version's status to INSTALLING. | 141 // the version's status to INSTALLING. |
| 139 // Upon completion, the version's status will be changed to INSTALLED | 142 // Upon completion, the version's status will be changed to INSTALLED |
| 140 // on success, or back to NEW on failure. | 143 // on success, or back to NEW on failure. |
| 144 // |second_call| is for internal use. |
| 141 void DispatchInstallEvent(int active_version_id, | 145 void DispatchInstallEvent(int active_version_id, |
| 142 const StatusCallback& callback); | 146 const StatusCallback& callback, |
| 147 bool second_call = false); |
| 143 | 148 |
| 144 // Sends activate event to the associated embedded worker and asynchronously | 149 // Sends activate event to the associated embedded worker and asynchronously |
| 145 // calls |callback| when it errors out or it gets response from the worker | 150 // calls |callback| when it errors out or it gets response from the worker |
| 146 // to notify activation completion. | 151 // to notify activation completion. |
| 147 // | 152 // |
| 148 // This must be called when the status() is INSTALLED. Calling this changes | 153 // This must be called when the status() is INSTALLED. Calling this changes |
| 149 // the version's status to ACTIVATING. | 154 // the version's status to ACTIVATING. |
| 150 // Upon completion, the version's status will be changed to ACTIVE | 155 // Upon completion, the version's status will be changed to ACTIVE |
| 151 // on success, or back to INSTALLED on failure. | 156 // on success, or back to INSTALLED on failure. |
| 152 void DispatchActivateEvent(const StatusCallback& callback); | 157 // |second_call| is for internal use. |
| 158 void DispatchActivateEvent(const StatusCallback& callback, |
| 159 bool second_call = false); |
| 153 | 160 |
| 154 // Sends fetch event to the associated embedded worker and calls | 161 // Sends fetch event to the associated embedded worker and calls |
| 155 // |callback| with the response from the worker. | 162 // |callback| with the response from the worker. |
| 156 // | 163 // |
| 157 // This must be called when the status() is ACTIVE. Calling this in other | 164 // This must be called when the status() is ACTIVE. Calling this in other |
| 158 // statuses will result in an error SERVICE_WORKER_ERROR_FAILED. | 165 // statuses will result in an error SERVICE_WORKER_ERROR_FAILED. |
| 159 void DispatchFetchEvent(const ServiceWorkerFetchRequest& request, | 166 void DispatchFetchEvent(const ServiceWorkerFetchRequest& request, |
| 160 const FetchCallback& callback); | 167 const FetchCallback& callback); |
| 161 | 168 |
| 162 // Sends sync event to the associated embedded worker and asynchronously calls | 169 // Sends sync event to the associated embedded worker and asynchronously calls |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 212 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
| 206 | 213 |
| 207 private: | 214 private: |
| 208 typedef ServiceWorkerVersion self; | 215 typedef ServiceWorkerVersion self; |
| 209 typedef std::map<ServiceWorkerProviderHost*, int> ControlleeMap; | 216 typedef std::map<ServiceWorkerProviderHost*, int> ControlleeMap; |
| 210 typedef IDMap<ServiceWorkerProviderHost> ControlleeByIDMap; | 217 typedef IDMap<ServiceWorkerProviderHost> ControlleeByIDMap; |
| 211 friend class base::RefCounted<ServiceWorkerVersion>; | 218 friend class base::RefCounted<ServiceWorkerVersion>; |
| 212 | 219 |
| 213 virtual ~ServiceWorkerVersion(); | 220 virtual ~ServiceWorkerVersion(); |
| 214 | 221 |
| 222 void RunStartWorkerCallbacksOnError(ServiceWorkerStatusCode status); |
| 223 |
| 215 // Message handlers. | 224 // Message handlers. |
| 216 void OnGetClientDocuments(int request_id); | 225 void OnGetClientDocuments(int request_id); |
| 217 void OnActivateEventFinished(int request_id, | 226 void OnActivateEventFinished(int request_id, |
| 218 blink::WebServiceWorkerEventResult result); | 227 blink::WebServiceWorkerEventResult result); |
| 219 void OnInstallEventFinished(int request_id, | 228 void OnInstallEventFinished(int request_id, |
| 220 blink::WebServiceWorkerEventResult result); | 229 blink::WebServiceWorkerEventResult result); |
| 221 void OnFetchEventFinished(int request_id, | 230 void OnFetchEventFinished(int request_id, |
| 222 ServiceWorkerFetchEventResult result, | 231 ServiceWorkerFetchEventResult result, |
| 223 const ServiceWorkerResponse& response); | 232 const ServiceWorkerResponse& response); |
| 224 void OnSyncEventFinished(int request_id); | 233 void OnSyncEventFinished(int request_id); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 245 ObserverList<Listener> listeners_; | 254 ObserverList<Listener> listeners_; |
| 246 | 255 |
| 247 base::WeakPtrFactory<ServiceWorkerVersion> weak_factory_; | 256 base::WeakPtrFactory<ServiceWorkerVersion> weak_factory_; |
| 248 | 257 |
| 249 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerVersion); | 258 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerVersion); |
| 250 }; | 259 }; |
| 251 | 260 |
| 252 } // namespace content | 261 } // namespace content |
| 253 | 262 |
| 254 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ | 263 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ |
| OLD | NEW |