Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(312)

Side by Side Diff: content/browser/service_worker/service_worker_script_cache_map.h

Issue 647953003: Service Worker script sizes in database. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git/+/master
Patch Set: Fixed crash where writer_ was null Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_WORKER_SCRIPT_CACHE_MAP_H_ 5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_SCRIPT_CACHE_MAP_H_
6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_SCRIPT_CACHE_MAP_H_ 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_SCRIPT_CACHE_MAP_H_
7 7
8 #include <map> 8 #include <map>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/memory/weak_ptr.h" 12 #include "base/memory/weak_ptr.h"
13 #include "content/browser/service_worker/service_worker_database.h" 13 #include "content/browser/service_worker/service_worker_database.h"
14 #include "content/common/content_export.h" 14 #include "content/common/content_export.h"
15 #include "net/url_request/url_request_status.h" 15 #include "net/url_request/url_request_status.h"
16 16
17 class GURL; 17 class GURL;
18 18
19 namespace content { 19 namespace content {
20 20
21 class ServiceWorkerContextCore; 21 class ServiceWorkerContextCore;
22 class ServiceWorkerVersion; 22 class ServiceWorkerVersion;
23 23
24 // Class that maintains the mapping between urls and a resource id 24 // Class that maintains the mapping between urls and a resource id
25 // for a particular version's implicit script resources. 25 // for a particular version's implicit script resources.
26 class CONTENT_EXPORT ServiceWorkerScriptCacheMap { 26 class CONTENT_EXPORT ServiceWorkerScriptCacheMap {
27 public: 27 public:
28 int64 Lookup(const GURL& url); 28 int64 LookupResourceId(const GURL& url);
29 // A size of -1 means that we don't know the size yet
30 // (it has not finished caching).
31 int64 LookupResourceSize(const GURL& url);
29 32
30 // Used during the initial run of a new version to build the map 33 // Used during the initial run of a new version to build the map
31 // of resources ids. 34 // of resources ids.
32 void NotifyStartedCaching(const GURL& url, int64 resource_id); 35 void NotifyStartedCaching(const GURL& url, int64 resource_id);
33 void NotifyFinishedCaching(const GURL& url, 36 void NotifyFinishedCaching(const GURL& url,
37 int64 size_bytes,
34 const net::URLRequestStatus& status); 38 const net::URLRequestStatus& status);
35 39
36 // Used to retrieve the results of the initial run of a new version. 40 // Used to retrieve the results of the initial run of a new version.
37 void GetResources( 41 void GetResources(
38 std::vector<ServiceWorkerDatabase::ResourceRecord>* resources); 42 std::vector<ServiceWorkerDatabase::ResourceRecord>* resources);
39 43
40 // Used when loading an existing version. 44 // Used when loading an existing version.
41 void SetResources( 45 void SetResources(
42 const std::vector<ServiceWorkerDatabase::ResourceRecord>& resources); 46 const std::vector<ServiceWorkerDatabase::ResourceRecord>& resources);
43 47
44 size_t size() const { return resource_ids_.size(); } 48 size_t size() const { return resource_map_.size(); }
45 49
46 const net::URLRequestStatus& main_script_status() const { 50 const net::URLRequestStatus& main_script_status() const {
47 return main_script_status_; 51 return main_script_status_;
48 } 52 }
49 53
50 private: 54 private:
51 typedef std::map<GURL, int64> ResourceIDMap; 55 typedef std::map<GURL, ServiceWorkerDatabase::ResourceRecord> ResourceMap;
52 56
53 // The version objects owns its script cache and provides a rawptr to it. 57 // The version objects owns its script cache and provides a rawptr to it.
54 friend class ServiceWorkerVersion; 58 friend class ServiceWorkerVersion;
55 ServiceWorkerScriptCacheMap( 59 ServiceWorkerScriptCacheMap(
56 ServiceWorkerVersion* owner, 60 ServiceWorkerVersion* owner,
57 base::WeakPtr<ServiceWorkerContextCore> context); 61 base::WeakPtr<ServiceWorkerContextCore> context);
58 ~ServiceWorkerScriptCacheMap(); 62 ~ServiceWorkerScriptCacheMap();
59 63
60 ServiceWorkerVersion* owner_; 64 ServiceWorkerVersion* owner_;
61 base::WeakPtr<ServiceWorkerContextCore> context_; 65 base::WeakPtr<ServiceWorkerContextCore> context_;
62 ResourceIDMap resource_ids_; 66 ResourceMap resource_map_;
63 net::URLRequestStatus main_script_status_; 67 net::URLRequestStatus main_script_status_;
64 68
65 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerScriptCacheMap); 69 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerScriptCacheMap);
66 }; 70 };
67 71
68 } // namespace content 72 } // namespace content
69 73
70 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_SCRIPT_CACHE_MAP_H_ 74 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_SCRIPT_CACHE_MAP_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698