• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_SCRIPT_CACHE_MAP_H_
6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_SCRIPT_CACHE_MAP_H_
7 
8 #include <map>
9 #include <vector>
10 
11 #include "base/basictypes.h"
12 #include "base/memory/weak_ptr.h"
13 #include "content/browser/service_worker/service_worker_database.h"
14 
15 class GURL;
16 
17 namespace content {
18 
19 class ServiceWorkerContextCore;
20 class ServiceWorkerVersion;
21 
22 // Class that maintains the mapping between urls and a resource id
23 // for a particular versions implicit script resources.
24 class ServiceWorkerScriptCacheMap {
25  public:
26   int64 Lookup(const GURL& url);
27 
28   // Used during the initial run of a new version to build the map
29   // of resources ids.
30   void NotifyStartedCaching(const GURL& url, int64 resource_id);
31   void NotifyFinishedCaching(const GURL& url, bool success);
32 
33   // Used to retrieve the results of the initial run of a new version.
HasError()34   bool HasError() const { return has_error_; }
35   void GetResources(
36       std::vector<ServiceWorkerDatabase::ResourceRecord>* resources);
37 
38   // Used when loading an existing version.
39   void SetResources(
40      const std::vector<ServiceWorkerDatabase::ResourceRecord>& resources);
41 
42  private:
43   typedef std::map<GURL, int64> ResourceIDMap;
44 
45   // The version objects owns its script cache and provides a rawptr to it.
46   friend class ServiceWorkerVersion;
47   ServiceWorkerScriptCacheMap(
48       ServiceWorkerVersion* owner,
49       base::WeakPtr<ServiceWorkerContextCore> context);
50   ~ServiceWorkerScriptCacheMap();
51 
52   ServiceWorkerVersion* owner_;
53   base::WeakPtr<ServiceWorkerContextCore> context_;
54   ResourceIDMap resource_ids_;
55   bool has_error_;
56 
57   DISALLOW_COPY_AND_ASSIGN(ServiceWorkerScriptCacheMap);
58 };
59 
60 }  // namespace content
61 
62 #endif  // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_SCRIPT_CACHE_MAP_H_
63