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

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

Issue 931173002: Implement EmbeddedWorkerContextClient.setCachedMetadata/clearCachedMetadata (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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/base/completion_callback.h"
15 #include "net/url_request/url_request_status.h" 16 #include "net/url_request/url_request_status.h"
16 17
17 class GURL; 18 class GURL;
18 19
19 namespace content { 20 namespace content {
20 21
21 class ServiceWorkerContextCore; 22 class ServiceWorkerContextCore;
22 class ServiceWorkerVersion; 23 class ServiceWorkerVersion;
24 class ServiceWorkerResponseMetadataWriter;
23 25
24 // Class that maintains the mapping between urls and a resource id 26 // Class that maintains the mapping between urls and a resource id
25 // for a particular version's implicit script resources. 27 // for a particular version's implicit script resources.
26 class CONTENT_EXPORT ServiceWorkerScriptCacheMap { 28 class CONTENT_EXPORT ServiceWorkerScriptCacheMap {
27 public: 29 public:
28 int64 LookupResourceId(const GURL& url); 30 int64 LookupResourceId(const GURL& url);
29 // A size of -1 means that we don't know the size yet 31 // A size of -1 means that we don't know the size yet
30 // (it has not finished caching). 32 // (it has not finished caching).
31 int64 LookupResourceSize(const GURL& url); 33 int64 LookupResourceSize(const GURL& url);
32 34
33 // Used during the initial run of a new version to build the map 35 // Used during the initial run of a new version to build the map
34 // of resources ids. 36 // of resources ids.
35 void NotifyStartedCaching(const GURL& url, int64 resource_id); 37 void NotifyStartedCaching(const GURL& url, int64 resource_id);
36 void NotifyFinishedCaching(const GURL& url, 38 void NotifyFinishedCaching(const GURL& url,
37 int64 size_bytes, 39 int64 size_bytes,
38 const net::URLRequestStatus& status, 40 const net::URLRequestStatus& status,
39 const std::string& status_message); 41 const std::string& status_message);
40 42
41 // Used to retrieve the results of the initial run of a new version. 43 // Used to retrieve the results of the initial run of a new version.
42 void GetResources( 44 void GetResources(
43 std::vector<ServiceWorkerDatabase::ResourceRecord>* resources); 45 std::vector<ServiceWorkerDatabase::ResourceRecord>* resources);
44 46
45 // Used when loading an existing version. 47 // Used when loading an existing version.
46 void SetResources( 48 void SetResources(
47 const std::vector<ServiceWorkerDatabase::ResourceRecord>& resources); 49 const std::vector<ServiceWorkerDatabase::ResourceRecord>& resources);
48 50
51 // Writes the metadata of the existing script.
52 void WriteMetadata(const GURL& url,
53 const std::vector<char>& data,
54 const net::CompletionCallback& callback);
55 // Clears the metadata of the existing script.
56 void ClearMetadata(const GURL& url, const net::CompletionCallback& callback);
57
49 size_t size() const { return resource_map_.size(); } 58 size_t size() const { return resource_map_.size(); }
50 59
51 const net::URLRequestStatus& main_script_status() const { 60 const net::URLRequestStatus& main_script_status() const {
52 return main_script_status_; 61 return main_script_status_;
53 } 62 }
54 63
55 const std::string& main_script_status_message() const { 64 const std::string& main_script_status_message() const {
56 return main_script_status_message_; 65 return main_script_status_message_;
57 } 66 }
58 67
59 private: 68 private:
60 typedef std::map<GURL, ServiceWorkerDatabase::ResourceRecord> ResourceMap; 69 typedef std::map<GURL, ServiceWorkerDatabase::ResourceRecord> ResourceMap;
61 70
62 // The version objects owns its script cache and provides a rawptr to it. 71 // The version objects owns its script cache and provides a rawptr to it.
63 friend class ServiceWorkerVersion; 72 friend class ServiceWorkerVersion;
64 ServiceWorkerScriptCacheMap( 73 ServiceWorkerScriptCacheMap(
65 ServiceWorkerVersion* owner, 74 ServiceWorkerVersion* owner,
66 base::WeakPtr<ServiceWorkerContextCore> context); 75 base::WeakPtr<ServiceWorkerContextCore> context);
67 ~ServiceWorkerScriptCacheMap(); 76 ~ServiceWorkerScriptCacheMap();
68 77
78 void OnMetadataWritten(scoped_ptr<ServiceWorkerResponseMetadataWriter> writer,
79 const net::CompletionCallback& callback,
80 int);
michaeln 2015/02/18 03:37:34 name the last arg
horo 2015/02/18 04:17:06 Done.
81
69 ServiceWorkerVersion* owner_; 82 ServiceWorkerVersion* owner_;
70 base::WeakPtr<ServiceWorkerContextCore> context_; 83 base::WeakPtr<ServiceWorkerContextCore> context_;
71 ResourceMap resource_map_; 84 ResourceMap resource_map_;
72 net::URLRequestStatus main_script_status_; 85 net::URLRequestStatus main_script_status_;
73 std::string main_script_status_message_; 86 std::string main_script_status_message_;
74 87
88 base::WeakPtrFactory<ServiceWorkerScriptCacheMap> weak_factory_;
89
75 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerScriptCacheMap); 90 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerScriptCacheMap);
76 }; 91 };
77 92
78 } // namespace content 93 } // namespace content
79 94
80 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_SCRIPT_CACHE_MAP_H_ 95 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_SCRIPT_CACHE_MAP_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698