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

Side by Side Diff: webkit/appcache/appcache.h

Issue 201070: Implementation of application cache update algorithm.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | webkit/appcache/appcache.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 WEBKIT_APPCACHE_APPCACHE_H_ 5 #ifndef WEBKIT_APPCACHE_APPCACHE_H_
6 #define WEBKIT_APPCACHE_APPCACHE_H_ 6 #define WEBKIT_APPCACHE_APPCACHE_H_
7 7
8 #include <map> 8 #include <map>
9 #include <set> 9 #include <set>
10 #include <string> 10 #include <string>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/ref_counted.h" 13 #include "base/ref_counted.h"
14 #include "base/time.h" 14 #include "base/time.h"
15 #include "googleurl/src/gurl.h" 15 #include "googleurl/src/gurl.h"
16 #include "testing/gtest/include/gtest/gtest_prod.h"
16 #include "webkit/appcache/appcache_entry.h" 17 #include "webkit/appcache/appcache_entry.h"
17 #include "webkit/appcache/manifest_parser.h" 18 #include "webkit/appcache/manifest_parser.h"
18 19
19 namespace appcache { 20 namespace appcache {
20 21
21 class AppCacheGroup; 22 class AppCacheGroup;
22 class AppCacheHost; 23 class AppCacheHost;
23 class AppCacheService; 24 class AppCacheService;
24 25
25 // Set of cached resources for an application. A cache exists as long as a 26 // Set of cached resources for an application. A cache exists as long as a
26 // host is associated with it, the cache is in an appcache group or the 27 // host is associated with it, the cache is in an appcache group or the
27 // cache is being created during an appcache upate. 28 // cache is being created during an appcache upate.
28 class AppCache : public base::RefCounted<AppCache> { 29 class AppCache : public base::RefCounted<AppCache> {
29 public: 30 public:
31 typedef std::map<GURL, AppCacheEntry> EntryMap;
32
30 AppCache(AppCacheService *service, int64 cache_id); 33 AppCache(AppCacheService *service, int64 cache_id);
31 ~AppCache(); 34 ~AppCache();
32 35
33 int64 cache_id() const { return cache_id_; } 36 int64 cache_id() const { return cache_id_; }
34 37
35 AppCacheGroup* owning_group() const { return owning_group_; } 38 AppCacheGroup* owning_group() const { return owning_group_; }
36 void set_owning_group(AppCacheGroup* group) { owning_group_ = group; } 39 void set_owning_group(AppCacheGroup* group) { owning_group_ = group; }
37 40
38 bool is_complete() const { return is_complete_; } 41 bool is_complete() const { return is_complete_; }
39 void set_complete(bool value) { is_complete_ = value; } 42 void set_complete(bool value) { is_complete_ = value; }
40 43
41 AppCacheService* service() const { return service_; } 44 AppCacheService* service() const { return service_; }
42 45
43 // Adds a new entry. Entry must not already be in cache. 46 // Adds a new entry. Entry must not already be in cache.
44 void AddEntry(const GURL& url, const AppCacheEntry& entry); 47 void AddEntry(const GURL& url, const AppCacheEntry& entry);
45 48
46 // Adds a new entry or modifies an existing entry by merging the types 49 // Adds a new entry or modifies an existing entry by merging the types
47 // of the new entry with the existing entry. 50 // of the new entry with the existing entry.
48 void AddOrModifyEntry(const GURL& url, const AppCacheEntry& entry); 51 void AddOrModifyEntry(const GURL& url, const AppCacheEntry& entry);
49 52
50 // Do not store the returned object as it could be deleted anytime. 53 // Do not store the returned object as it could be deleted anytime.
51 AppCacheEntry* GetEntry(const GURL& url); 54 AppCacheEntry* GetEntry(const GURL& url);
52 55
53 typedef std::map<GURL, AppCacheEntry> EntryMap;
54 const EntryMap& entries() const { return entries_; } 56 const EntryMap& entries() const { return entries_; }
55 57
58 const std::set<AppCacheHost*>& associated_hosts() const {
59 return associated_hosts_;
60 }
61
56 bool IsNewerThan(AppCache* cache) const { 62 bool IsNewerThan(AppCache* cache) const {
57 return update_time_ > cache->update_time_; 63 return update_time_ > cache->update_time_;
58 } 64 }
59 65
60 void set_update_time(base::TimeTicks ticks = base::TimeTicks::Now()) { 66 void set_update_time(base::TimeTicks ticks) {
61 update_time_ = ticks; 67 update_time_ = ticks;
62 } 68 }
63 69
70 // Initializes the cache with information in the manifest.
71 // Do not use the manifest after this call.
72 void InitializeWithManifest(Manifest* manifest);
73
64 private: 74 private:
65 friend class AppCacheHost; 75 friend class AppCacheHost;
76 friend class AppCacheUpdateJobTest;
66 77
67 // Use AppCacheHost::AssociateCache() to manipulate host association. 78 // Use AppCacheHost::AssociateCache() to manipulate host association.
68 void AssociateHost(AppCacheHost* host) { 79 void AssociateHost(AppCacheHost* host) {
69 associated_hosts_.insert(host); 80 associated_hosts_.insert(host);
70 } 81 }
71 void UnassociateHost(AppCacheHost* host); 82 void UnassociateHost(AppCacheHost* host);
72 83
73 const int64 cache_id_; 84 const int64 cache_id_;
74 AppCacheEntry* manifest_; // also in entry map
75 AppCacheGroup* owning_group_; 85 AppCacheGroup* owning_group_;
76 std::set<AppCacheHost*> associated_hosts_; 86 std::set<AppCacheHost*> associated_hosts_;
77 87
78 EntryMap entries_; // contains entries of all types 88 EntryMap entries_; // contains entries of all types
79 89
80 std::vector<FallbackNamespace> fallback_namespaces_; 90 std::vector<FallbackNamespace> fallback_namespaces_;
81 std::vector<GURL> online_whitelist_namespaces_; 91 std::vector<GURL> online_whitelist_namespaces_;
82 bool online_whitelist_all_; 92 bool online_whitelist_all_;
83 93
84 bool is_complete_; 94 bool is_complete_;
85 95
86 // when this cache was last updated 96 // when this cache was last updated
87 base::TimeTicks update_time_; 97 base::TimeTicks update_time_;
88 98
89 // to notify service when cache is deleted 99 // to notify service when cache is deleted
90 AppCacheService* service_; 100 AppCacheService* service_;
101
102 FRIEND_TEST(AppCacheTest, InitializeWithManifest);
103 DISALLOW_COPY_AND_ASSIGN(AppCache);
91 }; 104 };
92 105
93 } // namespace appcache 106 } // namespace appcache
94 107
95 #endif // WEBKIT_APPCACHE_APPCACHE_H_ 108 #endif // WEBKIT_APPCACHE_APPCACHE_H_
OLDNEW
« no previous file with comments | « no previous file | webkit/appcache/appcache.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698