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 "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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 79 const base::string16& error_message, | 80 const base::string16& error_message, |
| 80 int line_number, | 81 int line_number, |
| 81 int column_number, | 82 int column_number, |
| 82 const GURL& source_url) = 0; | 83 const GURL& source_url) = 0; |
| 83 virtual void OnReportConsoleMessage(ServiceWorkerVersion* version, | 84 virtual void OnReportConsoleMessage(ServiceWorkerVersion* version, |
| 84 int source_identifier, | 85 int source_identifier, |
| 85 int message_level, | 86 int message_level, |
| 86 const base::string16& message, | 87 const base::string16& message, |
| 87 int line_number, | 88 int line_number, |
| 88 const GURL& source_url) = 0; | 89 const GURL& source_url) = 0; |
| 90 | |
| 91 // Notification that the main script resource has been written to | |
| 92 // the disk cache. Only called when a version is being initially | |
| 93 // installed. | |
| 94 virtual void OnMainScriptCached(ServiceWorkerVersion* version, | |
| 95 bool success) = 0; | |
|
michaeln
2014/05/13 06:51:00
i'll have to track down derivatives in tests and f
kinuko
2014/05/13 16:14:25
Looks like these can be in a separate listener cla
kinuko
2014/05/13 16:14:25
Is this where we compare scripts to see if it's th
michaeln
2014/05/13 22:41:11
Yes. In the first time and update cases, a version
michaeln
2014/05/13 22:41:11
Done, ServiceWorkerScriptCacheMap::Observer.
| |
| 96 | |
| 97 // Notification that the main script resource and all imports have | |
| 98 // been written to the disk cache. Only called when a version is | |
| 99 // being initially installed. | |
| 100 virtual void OnAllScriptsCached(ServiceWorkerVersion* version, | |
| 101 bool success) = 0; | |
|
kinuko
2014/05/13 16:14:25
Is this where we actually commit the registration
michaeln
2014/05/13 22:41:11
I think so. There are at least two things of inter
| |
| 89 }; | 102 }; |
| 90 | 103 |
| 91 ServiceWorkerVersion( | 104 ServiceWorkerVersion( |
| 92 ServiceWorkerRegistration* registration, | 105 ServiceWorkerRegistration* registration, |
| 93 int64 version_id, | 106 int64 version_id, |
| 94 base::WeakPtr<ServiceWorkerContextCore> context); | 107 base::WeakPtr<ServiceWorkerContextCore> context); |
| 95 | 108 |
| 96 int64 version_id() const { return version_id_; } | 109 int64 version_id() const { return version_id_; } |
| 97 int64 registration_id() const { return registration_id_; } | 110 int64 registration_id() const { return registration_id_; } |
| 98 | 111 |
| 112 const GURL& script_url() const { return script_url_; } | |
| 113 const GURL& scope() const { return scope_; } | |
|
nhiroki
2014/05/13 07:44:34
scope() doesn't seem to be neccessary for this cha
michaeln
2014/05/13 22:41:11
Done.
| |
| 114 | |
| 99 RunningStatus running_status() const { | 115 RunningStatus running_status() const { |
| 100 return static_cast<RunningStatus>(embedded_worker_->status()); | 116 return static_cast<RunningStatus>(embedded_worker_->status()); |
| 101 } | 117 } |
| 102 | 118 |
| 103 ServiceWorkerVersionInfo GetInfo(); | 119 ServiceWorkerVersionInfo GetInfo(); |
| 104 | 120 |
| 105 Status status() const { return status_; } | 121 Status status() const { return status_; } |
| 106 | 122 |
| 107 // This sets the new status and also run status change callbacks | 123 // This sets the new status and also run status change callbacks |
| 108 // if there're any (see RegisterStatusChangeCallback). | 124 // if there're any (see RegisterStatusChangeCallback). |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 189 void AddPendingControllee(ServiceWorkerProviderHost* provider_host); | 205 void AddPendingControllee(ServiceWorkerProviderHost* provider_host); |
| 190 void RemovePendingControllee(ServiceWorkerProviderHost* provider_host); | 206 void RemovePendingControllee(ServiceWorkerProviderHost* provider_host); |
| 191 | 207 |
| 192 // Returns if it has (non-pending) controllee. | 208 // Returns if it has (non-pending) controllee. |
| 193 bool HasControllee() const { return !controllee_map_.empty(); } | 209 bool HasControllee() const { return !controllee_map_.empty(); } |
| 194 | 210 |
| 195 // Adds and removes Listeners. | 211 // Adds and removes Listeners. |
| 196 void AddListener(Listener* listener); | 212 void AddListener(Listener* listener); |
| 197 void RemoveListener(Listener* listener); | 213 void RemoveListener(Listener* listener); |
| 198 | 214 |
| 215 // Propagates script caching progress to listneners. | |
|
nhiroki
2014/05/13 07:44:34
nit: s/listneners/listeners/
michaeln
2014/05/13 22:41:11
removed these methods
| |
| 216 void NotifyMainScriptCached(bool success); | |
| 217 void NotifyAllScriptsCached(bool success); | |
| 218 | |
| 219 ServiceWorkerScriptCacheMap* script_cache_map() { return &script_cache_map_; } | |
| 220 | |
| 199 EmbeddedWorkerInstance* embedded_worker() { return embedded_worker_.get(); } | 221 EmbeddedWorkerInstance* embedded_worker() { return embedded_worker_.get(); } |
| 200 | 222 |
| 223 private: | |
| 224 typedef ServiceWorkerVersion self; | |
| 225 typedef std::map<ServiceWorkerProviderHost*, int> ControlleeMap; | |
| 226 typedef IDMap<ServiceWorkerProviderHost> ControlleeByIDMap; | |
| 227 friend class base::RefCounted<ServiceWorkerVersion>; | |
| 228 | |
| 229 virtual ~ServiceWorkerVersion(); | |
| 230 | |
| 201 // EmbeddedWorkerInstance::Listener overrides: | 231 // EmbeddedWorkerInstance::Listener overrides: |
| 202 virtual void OnStarted() OVERRIDE; | 232 virtual void OnStarted() OVERRIDE; |
| 203 virtual void OnStopped() OVERRIDE; | 233 virtual void OnStopped() OVERRIDE; |
| 204 virtual void OnReportException(const base::string16& error_message, | 234 virtual void OnReportException(const base::string16& error_message, |
| 205 int line_number, | 235 int line_number, |
| 206 int column_number, | 236 int column_number, |
| 207 const GURL& source_url) OVERRIDE; | 237 const GURL& source_url) OVERRIDE; |
| 208 virtual void OnReportConsoleMessage(int source_identifier, | 238 virtual void OnReportConsoleMessage(int source_identifier, |
| 209 int message_level, | 239 int message_level, |
| 210 const base::string16& message, | 240 const base::string16& message, |
| 211 int line_number, | 241 int line_number, |
| 212 const GURL& source_url) OVERRIDE; | 242 const GURL& source_url) OVERRIDE; |
| 213 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 243 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
| 214 | 244 |
| 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); | 245 void RunStartWorkerCallbacksOnError(ServiceWorkerStatusCode status); |
| 228 | 246 |
| 229 void DispatchInstallEventAfterStartWorker(int active_version_id, | 247 void DispatchInstallEventAfterStartWorker(int active_version_id, |
| 230 const StatusCallback& callback); | 248 const StatusCallback& callback); |
| 231 void DispatchActivateEventAfterStartWorker(const StatusCallback& callback); | 249 void DispatchActivateEventAfterStartWorker(const StatusCallback& callback); |
| 232 | 250 |
| 233 // Message handlers. | 251 // Message handlers. |
| 234 void OnGetClientDocuments(int request_id); | 252 void OnGetClientDocuments(int request_id); |
| 235 void OnActivateEventFinished(int request_id, | 253 void OnActivateEventFinished(int request_id, |
| 236 blink::WebServiceWorkerEventResult result); | 254 blink::WebServiceWorkerEventResult result); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 257 // Message callbacks. | 275 // Message callbacks. |
| 258 IDMap<StatusCallback, IDMapOwnPointer> activate_callbacks_; | 276 IDMap<StatusCallback, IDMapOwnPointer> activate_callbacks_; |
| 259 IDMap<StatusCallback, IDMapOwnPointer> install_callbacks_; | 277 IDMap<StatusCallback, IDMapOwnPointer> install_callbacks_; |
| 260 IDMap<FetchCallback, IDMapOwnPointer> fetch_callbacks_; | 278 IDMap<FetchCallback, IDMapOwnPointer> fetch_callbacks_; |
| 261 IDMap<StatusCallback, IDMapOwnPointer> sync_callbacks_; | 279 IDMap<StatusCallback, IDMapOwnPointer> sync_callbacks_; |
| 262 | 280 |
| 263 ControlleeMap controllee_map_; | 281 ControlleeMap controllee_map_; |
| 264 ControlleeByIDMap controllee_by_id_; | 282 ControlleeByIDMap controllee_by_id_; |
| 265 base::WeakPtr<ServiceWorkerContextCore> context_; | 283 base::WeakPtr<ServiceWorkerContextCore> context_; |
| 266 ObserverList<Listener> listeners_; | 284 ObserverList<Listener> listeners_; |
| 267 | 285 ServiceWorkerScriptCacheMap script_cache_map_; |
| 268 ResourceIDMap script_cache_map_; | |
| 269 | 286 |
| 270 base::WeakPtrFactory<ServiceWorkerVersion> weak_factory_; | 287 base::WeakPtrFactory<ServiceWorkerVersion> weak_factory_; |
| 271 | 288 |
| 272 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerVersion); | 289 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerVersion); |
| 273 }; | 290 }; |
| 274 | 291 |
| 275 } // namespace content | 292 } // namespace content |
| 276 | 293 |
| 277 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ | 294 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ |
| OLD | NEW |