Blink roll 25b6bd3a7a131ffe68d809546ad1a20707915cdc:3a503f41ae42e5b79cfcd2ff10e65afde...
[chromium-blink-merge.git] / content / browser / service_worker / service_worker_script_cache_map.h
blobde814c210b17d6d579ecd79b4f92b04a02d363ec
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
3 // found in the LICENSE file.
5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_SCRIPT_CACHE_MAP_H_
6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_SCRIPT_CACHE_MAP_H_
8 #include <map>
9 #include <vector>
11 #include "base/basictypes.h"
12 #include "base/memory/weak_ptr.h"
13 #include "content/browser/service_worker/service_worker_database.h"
14 #include "content/common/content_export.h"
15 #include "net/url_request/url_request_status.h"
17 class GURL;
19 namespace content {
21 class ServiceWorkerContextCore;
22 class ServiceWorkerVersion;
24 // Class that maintains the mapping between urls and a resource id
25 // for a particular version's implicit script resources.
26 class CONTENT_EXPORT ServiceWorkerScriptCacheMap {
27 public:
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);
33 // Used during the initial run of a new version to build the map
34 // of resources ids.
35 void NotifyStartedCaching(const GURL& url, int64 resource_id);
36 void NotifyFinishedCaching(const GURL& url,
37 int64 size_bytes,
38 const net::URLRequestStatus& status);
40 // Used to retrieve the results of the initial run of a new version.
41 void GetResources(
42 std::vector<ServiceWorkerDatabase::ResourceRecord>* resources);
44 // Used when loading an existing version.
45 void SetResources(
46 const std::vector<ServiceWorkerDatabase::ResourceRecord>& resources);
48 size_t size() const { return resource_map_.size(); }
50 const net::URLRequestStatus& main_script_status() const {
51 return main_script_status_;
54 private:
55 typedef std::map<GURL, ServiceWorkerDatabase::ResourceRecord> ResourceMap;
57 // The version objects owns its script cache and provides a rawptr to it.
58 friend class ServiceWorkerVersion;
59 ServiceWorkerScriptCacheMap(
60 ServiceWorkerVersion* owner,
61 base::WeakPtr<ServiceWorkerContextCore> context);
62 ~ServiceWorkerScriptCacheMap();
64 ServiceWorkerVersion* owner_;
65 base::WeakPtr<ServiceWorkerContextCore> context_;
66 ResourceMap resource_map_;
67 net::URLRequestStatus main_script_status_;
69 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerScriptCacheMap);
72 } // namespace content
74 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_SCRIPT_CACHE_MAP_H_