Chromium Code Reviews| 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" |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/gtest_prod_util.h" | 12 #include "base/gtest_prod_util.h" |
| 13 #include "base/id_map.h" | 13 #include "base/id_map.h" |
| 14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 16 #include "content/browser/service_worker/embedded_worker_instance.h" | 16 #include "content/browser/service_worker/embedded_worker_instance.h" |
| 17 #include "content/common/content_export.h" | 17 #include "content/common/content_export.h" |
| 18 #include "content/common/service_worker/service_worker_status_code.h" | 18 #include "content/common/service_worker/service_worker_status_code.h" |
| 19 | 19 |
| 20 class GURL; | 20 class GURL; |
| 21 | 21 |
| 22 namespace content { | 22 namespace content { |
| 23 | 23 |
| 24 class EmbeddedWorkerRegistry; | 24 class EmbeddedWorkerRegistry; |
| 25 class ServiceWorkerRegistration; | 25 class ServiceWorkerRegistration; |
| 26 class ServiceWorkerVersionInfo; | |
| 26 struct ServiceWorkerFetchRequest; | 27 struct ServiceWorkerFetchRequest; |
| 27 struct ServiceWorkerFetchResponse; | 28 struct ServiceWorkerFetchResponse; |
| 28 | 29 |
| 29 // This class corresponds to a specific version of a ServiceWorker | 30 // This class corresponds to a specific version of a ServiceWorker |
| 30 // script for a given pattern. When a script is upgraded, there may be | 31 // script for a given pattern. When a script is upgraded, there may be |
| 31 // more than one ServiceWorkerVersion "running" at a time, but only | 32 // more than one ServiceWorkerVersion "running" at a time, but only |
| 32 // one of them is active. This class connects the actual script with a | 33 // one of them is active. This class connects the actual script with a |
| 33 // running worker. | 34 // running worker. |
| 34 // Instances of this class are in one of two install states: | 35 // Instances of this class are in one of two install states: |
| 35 // - Pending: The script is in the process of being installed. There | 36 // - Pending: The script is in the process of being installed. There |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 83 | 84 |
| 84 int64 version_id() const { return version_id_; } | 85 int64 version_id() const { return version_id_; } |
| 85 | 86 |
| 86 void Shutdown(); | 87 void Shutdown(); |
| 87 bool is_shutdown() const { return is_shutdown_; } | 88 bool is_shutdown() const { return is_shutdown_; } |
| 88 | 89 |
| 89 Status status() const { | 90 Status status() const { |
| 90 return static_cast<Status>(embedded_worker_->status()); | 91 return static_cast<Status>(embedded_worker_->status()); |
| 91 } | 92 } |
| 92 | 93 |
| 94 static ServiceWorkerVersionInfo GetInfo(const ServiceWorkerVersion*); | |
|
kinuko
2014/03/05 03:43:20
It feels having non-static method which takes Serv
alecflett
2014/03/05 21:41:20
So I've adjusted it to be this way - it was this w
| |
| 95 | |
| 93 // Starts an embedded worker for this version. | 96 // Starts an embedded worker for this version. |
| 94 // This returns OK (success) if the worker is already running. | 97 // This returns OK (success) if the worker is already running. |
| 95 void StartWorker(const StatusCallback& callback); | 98 void StartWorker(const StatusCallback& callback); |
| 96 | 99 |
| 97 // Starts an embedded worker for this version. | 100 // Starts an embedded worker for this version. |
| 98 // This returns OK (success) if the worker is already stopped. | 101 // This returns OK (success) if the worker is already stopped. |
| 99 void StopWorker(const StatusCallback& callback); | 102 void StopWorker(const StatusCallback& callback); |
| 100 | 103 |
| 101 // Sends an IPC message to the worker. | 104 // Sends an IPC message to the worker. |
| 102 // If the worker is not running this first tries to start it by | 105 // If the worker is not running this first tries to start it by |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 128 // |callback| with the response from the worker. | 131 // |callback| with the response from the worker. |
| 129 void DispatchFetchEvent(const ServiceWorkerFetchRequest& request, | 132 void DispatchFetchEvent(const ServiceWorkerFetchRequest& request, |
| 130 const FetchCallback& callback); | 133 const FetchCallback& callback); |
| 131 | 134 |
| 132 // These are expected to be called when a renderer process host for the | 135 // These are expected to be called when a renderer process host for the |
| 133 // same-origin as for this ServiceWorkerVersion is created. The added | 136 // same-origin as for this ServiceWorkerVersion is created. The added |
| 134 // processes are used to run an in-renderer embedded worker. | 137 // processes are used to run an in-renderer embedded worker. |
| 135 void AddProcessToWorker(int process_id); | 138 void AddProcessToWorker(int process_id); |
| 136 void RemoveProcessToWorker(int process_id); | 139 void RemoveProcessToWorker(int process_id); |
| 137 | 140 |
| 138 EmbeddedWorkerInstance* embedded_worker() { return embedded_worker_.get(); } | 141 EmbeddedWorkerInstance* embedded_worker() const { |
| 142 return embedded_worker_.get(); | |
|
kinuko
2014/03/05 03:43:20
nit: indent
Returning non-const ptr from const me
alecflett
2014/03/05 21:41:20
Yep.. I wonder if we could make embedded_worker_in
| |
| 143 } | |
| 139 | 144 |
| 140 // EmbeddedWorkerInstance::Observer overrides: | 145 // EmbeddedWorkerInstance::Observer overrides: |
| 141 virtual void OnStarted() OVERRIDE; | 146 virtual void OnStarted() OVERRIDE; |
| 142 virtual void OnStopped() OVERRIDE; | 147 virtual void OnStopped() OVERRIDE; |
| 143 virtual void OnMessageReceived(int request_id, | 148 virtual void OnMessageReceived(int request_id, |
| 144 const IPC::Message& message) OVERRIDE; | 149 const IPC::Message& message) OVERRIDE; |
| 145 | 150 |
| 146 private: | 151 private: |
| 147 typedef ServiceWorkerVersion self; | 152 typedef ServiceWorkerVersion self; |
| 148 friend class base::RefCounted<ServiceWorkerVersion>; | 153 friend class base::RefCounted<ServiceWorkerVersion>; |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 162 IDMap<MessageCallback, IDMapOwnPointer> message_callbacks_; | 167 IDMap<MessageCallback, IDMapOwnPointer> message_callbacks_; |
| 163 | 168 |
| 164 base::WeakPtrFactory<ServiceWorkerVersion> weak_factory_; | 169 base::WeakPtrFactory<ServiceWorkerVersion> weak_factory_; |
| 165 | 170 |
| 166 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerVersion); | 171 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerVersion); |
| 167 }; | 172 }; |
| 168 | 173 |
| 169 } // namespace content | 174 } // namespace content |
| 170 | 175 |
| 171 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ | 176 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ |
| OLD | NEW |