OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_SCRIPT_CACHE_MAP_H_ | 5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_SCRIPT_CACHE_MAP_H_ |
6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_SCRIPT_CACHE_MAP_H_ | 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_SCRIPT_CACHE_MAP_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
| 9 #include <vector> |
9 | 10 |
10 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
11 #include "base/observer_list.h" | 12 #include "content/browser/service_worker/service_worker_database.h" |
12 | 13 |
13 class GURL; | 14 class GURL; |
14 | 15 |
15 namespace content { | 16 namespace content { |
16 | 17 |
17 class ServiceWorkerVersion; | 18 class ServiceWorkerVersion; |
18 | 19 |
19 // Class that maintains the mapping between urls and a resource id | 20 // Class that maintains the mapping between urls and a resource id |
20 // for a particular versions implicit script resources. | 21 // for a particular versions implicit script resources. |
21 class ServiceWorkerScriptCacheMap { | 22 class ServiceWorkerScriptCacheMap { |
22 public: | 23 public: |
23 class Observer { | |
24 public: | |
25 // Notification that the main script resource has been written to | |
26 // the disk cache. Only called when a version is being initially | |
27 // installed. | |
28 virtual void OnMainScriptCached(ServiceWorkerVersion* version, | |
29 bool success) = 0; | |
30 | |
31 // Notification that the main script resource and all imports have | |
32 // been written to the disk cache. Only called when a version is | |
33 // being initially installed. | |
34 virtual void OnAllScriptsCached(ServiceWorkerVersion* version, | |
35 bool success) = 0; | |
36 }; | |
37 | |
38 int64 Lookup(const GURL& url); | 24 int64 Lookup(const GURL& url); |
39 | 25 |
40 // Adds and removes Observers. | |
41 void AddObserver(Observer* observer); | |
42 void RemoveObserver(Observer* observer); | |
43 | |
44 // Used during the initial run of a new version to build the map | 26 // Used during the initial run of a new version to build the map |
45 // of resources ids. | 27 // of resources ids. |
46 // TODO(michaeln): Need more info about errors in Finished. | |
47 void NotifyStartedCaching(const GURL& url, int64 resource_id); | 28 void NotifyStartedCaching(const GURL& url, int64 resource_id); |
48 void NotifyFinishedCaching(const GURL& url, bool success); | 29 void NotifyFinishedCaching(const GURL& url, bool success); |
49 void NotifyEvalCompletion(); | 30 |
| 31 // Used to retrieve the results of the initial run of a new version. |
| 32 bool HasError() const { return has_error_; } |
| 33 void GetResources( |
| 34 std::vector<ServiceWorkerDatabase::ResourceRecord>* resources); |
| 35 |
| 36 // Used when loading an existing version. |
| 37 void SetResources( |
| 38 const std::vector<ServiceWorkerDatabase::ResourceRecord>& resources); |
50 | 39 |
51 private: | 40 private: |
52 typedef std::map<GURL, int64> ResourceIDMap; | 41 typedef std::map<GURL, int64> ResourceIDMap; |
53 | 42 |
54 // The version objects owns its script cache and provides a rawptr to it. | 43 // The version objects owns its script cache and provides a rawptr to it. |
55 friend class ServiceWorkerVersion; | 44 friend class ServiceWorkerVersion; |
56 explicit ServiceWorkerScriptCacheMap(ServiceWorkerVersion* owner); | 45 explicit ServiceWorkerScriptCacheMap(ServiceWorkerVersion* owner); |
57 ~ServiceWorkerScriptCacheMap(); | 46 ~ServiceWorkerScriptCacheMap(); |
58 | 47 |
59 ServiceWorkerVersion* owner_; | 48 ServiceWorkerVersion* owner_; |
60 ResourceIDMap resource_ids_; | 49 ResourceIDMap resource_ids_; |
61 | |
62 // Members used only during initial install. | |
63 bool is_eval_complete_; | |
64 int resources_started_; | |
65 int resources_finished_; | |
66 bool has_error_; | 50 bool has_error_; |
67 ObserverList<Observer> observers_; | |
68 | 51 |
69 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerScriptCacheMap); | 52 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerScriptCacheMap); |
70 }; | 53 }; |
71 | 54 |
72 } // namespace content | 55 } // namespace content |
73 | 56 |
74 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_SCRIPT_CACHE_MAP_H_ | 57 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_SCRIPT_CACHE_MAP_H_ |
OLD | NEW |