| 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 "base/observer_list.h" | 16 #include "base/observer_list.h" |
| 17 #include "content/browser/service_worker/embedded_worker_instance.h" | 17 #include "content/browser/service_worker/embedded_worker_instance.h" |
| 18 #include "content/browser/service_worker/service_worker_script_cache_map.h" |
| 18 #include "content/common/content_export.h" | 19 #include "content/common/content_export.h" |
| 19 #include "content/common/service_worker/service_worker_status_code.h" | 20 #include "content/common/service_worker/service_worker_status_code.h" |
| 20 #include "content/common/service_worker/service_worker_types.h" | 21 #include "content/common/service_worker/service_worker_types.h" |
| 21 #include "third_party/WebKit/public/platform/WebServiceWorkerEventResult.h" | 22 #include "third_party/WebKit/public/platform/WebServiceWorkerEventResult.h" |
| 22 | 23 |
| 23 class GURL; | 24 class GURL; |
| 24 | 25 |
| 25 namespace content { | 26 namespace content { |
| 26 | 27 |
| 27 class EmbeddedWorkerRegistry; | 28 class EmbeddedWorkerRegistry; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 const GURL& source_url) = 0; | 89 const GURL& source_url) = 0; |
| 89 }; | 90 }; |
| 90 | 91 |
| 91 ServiceWorkerVersion( | 92 ServiceWorkerVersion( |
| 92 ServiceWorkerRegistration* registration, | 93 ServiceWorkerRegistration* registration, |
| 93 int64 version_id, | 94 int64 version_id, |
| 94 base::WeakPtr<ServiceWorkerContextCore> context); | 95 base::WeakPtr<ServiceWorkerContextCore> context); |
| 95 | 96 |
| 96 int64 version_id() const { return version_id_; } | 97 int64 version_id() const { return version_id_; } |
| 97 int64 registration_id() const { return registration_id_; } | 98 int64 registration_id() const { return registration_id_; } |
| 98 | 99 const GURL& script_url() const { return script_url_; } |
| 99 RunningStatus running_status() const { | 100 RunningStatus running_status() const { |
| 100 return static_cast<RunningStatus>(embedded_worker_->status()); | 101 return static_cast<RunningStatus>(embedded_worker_->status()); |
| 101 } | 102 } |
| 102 | |
| 103 ServiceWorkerVersionInfo GetInfo(); | 103 ServiceWorkerVersionInfo GetInfo(); |
| 104 | |
| 105 Status status() const { return status_; } | 104 Status status() const { return status_; } |
| 106 | 105 |
| 107 // This sets the new status and also run status change callbacks | 106 // This sets the new status and also run status change callbacks |
| 108 // if there're any (see RegisterStatusChangeCallback). | 107 // if there're any (see RegisterStatusChangeCallback). |
| 109 void SetStatus(Status status); | 108 void SetStatus(Status status); |
| 110 | 109 |
| 111 // Registers status change callback. (This is for one-off observation, | 110 // Registers status change callback. (This is for one-off observation, |
| 112 // the consumer needs to re-register if it wants to continue observing | 111 // the consumer needs to re-register if it wants to continue observing |
| 113 // status changes) | 112 // status changes) |
| 114 void RegisterStatusChangeCallback(const base::Closure& callback); | 113 void RegisterStatusChangeCallback(const base::Closure& callback); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 void AddPendingControllee(ServiceWorkerProviderHost* provider_host); | 188 void AddPendingControllee(ServiceWorkerProviderHost* provider_host); |
| 190 void RemovePendingControllee(ServiceWorkerProviderHost* provider_host); | 189 void RemovePendingControllee(ServiceWorkerProviderHost* provider_host); |
| 191 | 190 |
| 192 // Returns if it has (non-pending) controllee. | 191 // Returns if it has (non-pending) controllee. |
| 193 bool HasControllee() const { return !controllee_map_.empty(); } | 192 bool HasControllee() const { return !controllee_map_.empty(); } |
| 194 | 193 |
| 195 // Adds and removes Listeners. | 194 // Adds and removes Listeners. |
| 196 void AddListener(Listener* listener); | 195 void AddListener(Listener* listener); |
| 197 void RemoveListener(Listener* listener); | 196 void RemoveListener(Listener* listener); |
| 198 | 197 |
| 198 ServiceWorkerScriptCacheMap* script_cache_map() { return &script_cache_map_; } |
| 199 EmbeddedWorkerInstance* embedded_worker() { return embedded_worker_.get(); } | 199 EmbeddedWorkerInstance* embedded_worker() { return embedded_worker_.get(); } |
| 200 | 200 |
| 201 private: |
| 202 typedef ServiceWorkerVersion self; |
| 203 typedef std::map<ServiceWorkerProviderHost*, int> ControlleeMap; |
| 204 typedef IDMap<ServiceWorkerProviderHost> ControlleeByIDMap; |
| 205 friend class base::RefCounted<ServiceWorkerVersion>; |
| 206 |
| 207 virtual ~ServiceWorkerVersion(); |
| 208 |
| 201 // EmbeddedWorkerInstance::Listener overrides: | 209 // EmbeddedWorkerInstance::Listener overrides: |
| 202 virtual void OnStarted() OVERRIDE; | 210 virtual void OnStarted() OVERRIDE; |
| 203 virtual void OnStopped() OVERRIDE; | 211 virtual void OnStopped() OVERRIDE; |
| 204 virtual void OnReportException(const base::string16& error_message, | 212 virtual void OnReportException(const base::string16& error_message, |
| 205 int line_number, | 213 int line_number, |
| 206 int column_number, | 214 int column_number, |
| 207 const GURL& source_url) OVERRIDE; | 215 const GURL& source_url) OVERRIDE; |
| 208 virtual void OnReportConsoleMessage(int source_identifier, | 216 virtual void OnReportConsoleMessage(int source_identifier, |
| 209 int message_level, | 217 int message_level, |
| 210 const base::string16& message, | 218 const base::string16& message, |
| 211 int line_number, | 219 int line_number, |
| 212 const GURL& source_url) OVERRIDE; | 220 const GURL& source_url) OVERRIDE; |
| 213 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 221 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
| 214 | 222 |
| 215 void AddToScriptCache(const GURL& url, int64 resource_id); | |
| 216 int64 LookupInScriptCache(const GURL& url); | |
| 217 | |
| 218 private: | |
| 219 typedef ServiceWorkerVersion self; | |
| 220 typedef std::map<ServiceWorkerProviderHost*, int> ControlleeMap; | |
| 221 typedef IDMap<ServiceWorkerProviderHost> ControlleeByIDMap; | |
| 222 typedef std::map<GURL, int64> ResourceIDMap; | |
| 223 friend class base::RefCounted<ServiceWorkerVersion>; | |
| 224 | |
| 225 virtual ~ServiceWorkerVersion(); | |
| 226 | |
| 227 void RunStartWorkerCallbacksOnError(ServiceWorkerStatusCode status); | 223 void RunStartWorkerCallbacksOnError(ServiceWorkerStatusCode status); |
| 228 | 224 |
| 229 void DispatchInstallEventAfterStartWorker(int active_version_id, | 225 void DispatchInstallEventAfterStartWorker(int active_version_id, |
| 230 const StatusCallback& callback); | 226 const StatusCallback& callback); |
| 231 void DispatchActivateEventAfterStartWorker(const StatusCallback& callback); | 227 void DispatchActivateEventAfterStartWorker(const StatusCallback& callback); |
| 232 | 228 |
| 233 // Message handlers. | 229 // Message handlers. |
| 234 void OnGetClientDocuments(int request_id); | 230 void OnGetClientDocuments(int request_id); |
| 235 void OnActivateEventFinished(int request_id, | 231 void OnActivateEventFinished(int request_id, |
| 236 blink::WebServiceWorkerEventResult result); | 232 blink::WebServiceWorkerEventResult result); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 257 // Message callbacks. | 253 // Message callbacks. |
| 258 IDMap<StatusCallback, IDMapOwnPointer> activate_callbacks_; | 254 IDMap<StatusCallback, IDMapOwnPointer> activate_callbacks_; |
| 259 IDMap<StatusCallback, IDMapOwnPointer> install_callbacks_; | 255 IDMap<StatusCallback, IDMapOwnPointer> install_callbacks_; |
| 260 IDMap<FetchCallback, IDMapOwnPointer> fetch_callbacks_; | 256 IDMap<FetchCallback, IDMapOwnPointer> fetch_callbacks_; |
| 261 IDMap<StatusCallback, IDMapOwnPointer> sync_callbacks_; | 257 IDMap<StatusCallback, IDMapOwnPointer> sync_callbacks_; |
| 262 | 258 |
| 263 ControlleeMap controllee_map_; | 259 ControlleeMap controllee_map_; |
| 264 ControlleeByIDMap controllee_by_id_; | 260 ControlleeByIDMap controllee_by_id_; |
| 265 base::WeakPtr<ServiceWorkerContextCore> context_; | 261 base::WeakPtr<ServiceWorkerContextCore> context_; |
| 266 ObserverList<Listener> listeners_; | 262 ObserverList<Listener> listeners_; |
| 267 | 263 ServiceWorkerScriptCacheMap script_cache_map_; |
| 268 ResourceIDMap script_cache_map_; | |
| 269 | 264 |
| 270 base::WeakPtrFactory<ServiceWorkerVersion> weak_factory_; | 265 base::WeakPtrFactory<ServiceWorkerVersion> weak_factory_; |
| 271 | 266 |
| 272 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerVersion); | 267 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerVersion); |
| 273 }; | 268 }; |
| 274 | 269 |
| 275 } // namespace content | 270 } // namespace content |
| 276 | 271 |
| 277 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ | 272 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ |
| OLD | NEW |