| 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 NEW, // The version is just created. | 60 NEW, // The version is just created. |
| 61 INSTALLING, // Install event is dispatched and being handled. | 61 INSTALLING, // Install event is dispatched and being handled. |
| 62 INSTALLED, // Install event is finished and is ready to be activated. | 62 INSTALLED, // Install event is finished and is ready to be activated. |
| 63 ACTIVATING, // Activate event is dispatched and being handled. | 63 ACTIVATING, // Activate event is dispatched and being handled. |
| 64 ACTIVE, // Activation is finished and can run as active. | 64 ACTIVE, // Activation is finished and can run as active. |
| 65 DEACTIVATED, // The version is no longer running as active, due to | 65 DEACTIVATED, // The version is no longer running as active, due to |
| 66 // unregistration or replace. (TODO(kinuko): we may need | 66 // unregistration or replace. (TODO(kinuko): we may need |
| 67 // different states for different termination sequences) | 67 // different states for different termination sequences) |
| 68 }; | 68 }; |
| 69 | 69 |
| 70 class Listener { |
| 71 public: |
| 72 virtual void OnVersionStateChanged(ServiceWorkerVersion* version) = 0; |
| 73 }; |
| 74 |
| 70 ServiceWorkerVersion( | 75 ServiceWorkerVersion( |
| 71 ServiceWorkerRegistration* registration, | 76 ServiceWorkerRegistration* registration, |
| 72 int64 version_id, | 77 int64 version_id, |
| 73 base::WeakPtr<ServiceWorkerContextCore> context); | 78 base::WeakPtr<ServiceWorkerContextCore> context); |
| 74 | 79 |
| 75 int64 version_id() const { return version_id_; } | 80 int64 version_id() const { return version_id_; } |
| 76 ServiceWorkerRegistration* registration() { return registration_.get(); } | 81 int64 registration_id() const { return registration_id_; } |
| 77 | |
| 78 void Shutdown(); | |
| 79 bool is_shutdown() const { return is_shutdown_; } | |
| 80 | 82 |
| 81 RunningStatus running_status() const { | 83 RunningStatus running_status() const { |
| 82 return static_cast<RunningStatus>(embedded_worker_->status()); | 84 return static_cast<RunningStatus>(embedded_worker_->status()); |
| 83 } | 85 } |
| 84 | 86 |
| 85 ServiceWorkerVersionInfo GetInfo(); | 87 ServiceWorkerVersionInfo GetInfo(); |
| 86 | 88 |
| 87 Status status() const { return status_; } | 89 Status status() const { return status_; } |
| 88 | 90 |
| 89 // This sets the new status and also run status change callbacks | 91 // This sets the new status and also run status change callbacks |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 // |callback| when it errors out or it gets response from the worker to notify | 158 // |callback| when it errors out or it gets response from the worker to notify |
| 157 // completion. | 159 // completion. |
| 158 // | 160 // |
| 159 // This must be called when the status() is ACTIVE. | 161 // This must be called when the status() is ACTIVE. |
| 160 void DispatchSyncEvent(const StatusCallback& callback); | 162 void DispatchSyncEvent(const StatusCallback& callback); |
| 161 | 163 |
| 162 // These are expected to be called when a renderer process host for the | 164 // These are expected to be called when a renderer process host for the |
| 163 // same-origin as for this ServiceWorkerVersion is created. The added | 165 // same-origin as for this ServiceWorkerVersion is created. The added |
| 164 // processes are used to run an in-renderer embedded worker. | 166 // processes are used to run an in-renderer embedded worker. |
| 165 void AddProcessToWorker(int process_id); | 167 void AddProcessToWorker(int process_id); |
| 166 void RemoveProcessToWorker(int process_id); | 168 void RemoveProcessFromWorker(int process_id); |
| 167 | 169 |
| 168 EmbeddedWorkerInstance* embedded_worker() { return embedded_worker_.get(); } | 170 EmbeddedWorkerInstance* embedded_worker() { return embedded_worker_.get(); } |
| 169 | 171 |
| 170 // EmbeddedWorkerInstance::Observer overrides: | 172 // EmbeddedWorkerInstance::Observer overrides: |
| 171 virtual void OnStarted() OVERRIDE; | 173 virtual void OnStarted() OVERRIDE; |
| 172 virtual void OnStopped() OVERRIDE; | 174 virtual void OnStopped() OVERRIDE; |
| 173 virtual void OnMessageReceived(int request_id, | 175 virtual void OnMessageReceived(int request_id, |
| 174 const IPC::Message& message) OVERRIDE; | 176 const IPC::Message& message) OVERRIDE; |
| 175 | 177 |
| 176 private: | 178 private: |
| 177 typedef ServiceWorkerVersion self; | 179 typedef ServiceWorkerVersion self; |
| 178 friend class base::RefCounted<ServiceWorkerVersion>; | 180 friend class base::RefCounted<ServiceWorkerVersion>; |
| 179 | 181 |
| 180 virtual ~ServiceWorkerVersion(); | 182 virtual ~ServiceWorkerVersion(); |
| 181 | 183 |
| 182 const int64 version_id_; | 184 const int64 version_id_; |
| 185 int64 registration_id_; |
| 186 GURL script_url_; |
| 183 Status status_; | 187 Status status_; |
| 184 bool is_shutdown_; | |
| 185 scoped_refptr<ServiceWorkerRegistration> registration_; | |
| 186 scoped_ptr<EmbeddedWorkerInstance> embedded_worker_; | 188 scoped_ptr<EmbeddedWorkerInstance> embedded_worker_; |
| 187 std::vector<StatusCallback> start_callbacks_; | 189 std::vector<StatusCallback> start_callbacks_; |
| 188 std::vector<StatusCallback> stop_callbacks_; | 190 std::vector<StatusCallback> stop_callbacks_; |
| 189 std::vector<base::Closure> status_change_callbacks_; | 191 std::vector<base::Closure> status_change_callbacks_; |
| 190 IDMap<MessageCallback, IDMapOwnPointer> message_callbacks_; | 192 IDMap<MessageCallback, IDMapOwnPointer> message_callbacks_; |
| 191 base::WeakPtrFactory<ServiceWorkerVersion> weak_factory_; | 193 base::WeakPtrFactory<ServiceWorkerVersion> weak_factory_; |
| 192 base::WeakPtr<ServiceWorkerContextCore> context_; | 194 base::WeakPtr<ServiceWorkerContextCore> context_; |
| 193 | 195 |
| 194 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerVersion); | 196 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerVersion); |
| 195 }; | 197 }; |
| 196 | 198 |
| 197 } // namespace content | 199 } // namespace content |
| 198 | 200 |
| 199 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ | 201 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ |
| OLD | NEW |