| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_APPCACHE_APPCACHE_H_ | 5 #ifndef CONTENT_BROWSER_APPCACHE_APPCACHE_H_ |
| 6 #define CONTENT_BROWSER_APPCACHE_APPCACHE_H_ | 6 #define CONTENT_BROWSER_APPCACHE_APPCACHE_H_ |
| 7 | 7 |
| 8 #include <stdint.h> |
| 9 |
| 8 #include <map> | 10 #include <map> |
| 9 #include <set> | 11 #include <set> |
| 10 #include <vector> | 12 #include <vector> |
| 11 | 13 |
| 12 #include "base/gtest_prod_util.h" | 14 #include "base/gtest_prod_util.h" |
| 15 #include "base/macros.h" |
| 13 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
| 14 #include "base/time/time.h" | 17 #include "base/time/time.h" |
| 15 #include "content/browser/appcache/appcache_database.h" | 18 #include "content/browser/appcache/appcache_database.h" |
| 16 #include "content/browser/appcache/appcache_entry.h" | 19 #include "content/browser/appcache/appcache_entry.h" |
| 17 #include "content/browser/appcache/appcache_manifest_parser.h" | 20 #include "content/browser/appcache/appcache_manifest_parser.h" |
| 18 #include "content/common/content_export.h" | 21 #include "content/common/content_export.h" |
| 19 #include "url/gurl.h" | 22 #include "url/gurl.h" |
| 20 | 23 |
| 21 namespace net { | 24 namespace net { |
| 22 class IOBuffer; | 25 class IOBuffer; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 35 | 38 |
| 36 // Set of cached resources for an application. A cache exists as long as a | 39 // Set of cached resources for an application. A cache exists as long as a |
| 37 // host is associated with it, the cache is in an appcache group or the | 40 // host is associated with it, the cache is in an appcache group or the |
| 38 // cache is being created during an appcache upate. | 41 // cache is being created during an appcache upate. |
| 39 class CONTENT_EXPORT AppCache | 42 class CONTENT_EXPORT AppCache |
| 40 : public base::RefCounted<AppCache> { | 43 : public base::RefCounted<AppCache> { |
| 41 public: | 44 public: |
| 42 typedef std::map<GURL, AppCacheEntry> EntryMap; | 45 typedef std::map<GURL, AppCacheEntry> EntryMap; |
| 43 typedef std::set<AppCacheHost*> AppCacheHosts; | 46 typedef std::set<AppCacheHost*> AppCacheHosts; |
| 44 | 47 |
| 45 AppCache(AppCacheStorage* storage, int64 cache_id); | 48 AppCache(AppCacheStorage* storage, int64_t cache_id); |
| 46 | 49 |
| 47 int64 cache_id() const { return cache_id_; } | 50 int64_t cache_id() const { return cache_id_; } |
| 48 | 51 |
| 49 AppCacheGroup* owning_group() const { return owning_group_.get(); } | 52 AppCacheGroup* owning_group() const { return owning_group_.get(); } |
| 50 | 53 |
| 51 bool is_complete() const { return is_complete_; } | 54 bool is_complete() const { return is_complete_; } |
| 52 void set_complete(bool value) { is_complete_ = value; } | 55 void set_complete(bool value) { is_complete_ = value; } |
| 53 | 56 |
| 54 // Adds a new entry. Entry must not already be in cache. | 57 // Adds a new entry. Entry must not already be in cache. |
| 55 void AddEntry(const GURL& url, const AppCacheEntry& entry); | 58 void AddEntry(const GURL& url, const AppCacheEntry& entry); |
| 56 | 59 |
| 57 // Adds a new entry or modifies an existing entry by merging the types | 60 // Adds a new entry or modifies an existing entry by merging the types |
| 58 // of the new entry with the existing entry. Returns true if a new entry | 61 // of the new entry with the existing entry. Returns true if a new entry |
| 59 // is added, false if the flags are merged into an existing entry. | 62 // is added, false if the flags are merged into an existing entry. |
| 60 bool AddOrModifyEntry(const GURL& url, const AppCacheEntry& entry); | 63 bool AddOrModifyEntry(const GURL& url, const AppCacheEntry& entry); |
| 61 | 64 |
| 62 // Removes an entry from the EntryMap, the URL must be in the set. | 65 // Removes an entry from the EntryMap, the URL must be in the set. |
| 63 void RemoveEntry(const GURL& url); | 66 void RemoveEntry(const GURL& url); |
| 64 | 67 |
| 65 // Do not store or delete the returned ptr, they're owned by 'this'. | 68 // Do not store or delete the returned ptr, they're owned by 'this'. |
| 66 AppCacheEntry* GetEntry(const GURL& url); | 69 AppCacheEntry* GetEntry(const GURL& url); |
| 67 const AppCacheEntry* GetEntryWithResponseId(int64 response_id) { | 70 const AppCacheEntry* GetEntryWithResponseId(int64_t response_id) { |
| 68 return GetEntryAndUrlWithResponseId(response_id, NULL); | 71 return GetEntryAndUrlWithResponseId(response_id, NULL); |
| 69 } | 72 } |
| 70 const AppCacheEntry* GetEntryAndUrlWithResponseId( | 73 const AppCacheEntry* GetEntryAndUrlWithResponseId(int64_t response_id, |
| 71 int64 response_id, GURL* optional_url); | 74 GURL* optional_url); |
| 72 const EntryMap& entries() const { return entries_; } | 75 const EntryMap& entries() const { return entries_; } |
| 73 | 76 |
| 74 // The AppCache owns the collection of executable handlers that have | 77 // The AppCache owns the collection of executable handlers that have |
| 75 // been started for this instance. The getter looks up an existing | 78 // been started for this instance. The getter looks up an existing |
| 76 // handler returning null if not found, the GetOrCreate method will | 79 // handler returning null if not found, the GetOrCreate method will |
| 77 // cons one up if not found. | 80 // cons one up if not found. |
| 78 // Do not store the returned ptrs, they're owned by 'this'. | 81 // Do not store the returned ptrs, they're owned by 'this'. |
| 79 AppCacheExecutableHandler* GetExecutableHandler(int64 response_id); | 82 AppCacheExecutableHandler* GetExecutableHandler(int64_t response_id); |
| 80 AppCacheExecutableHandler* GetOrCreateExecutableHandler( | 83 AppCacheExecutableHandler* GetOrCreateExecutableHandler( |
| 81 int64 response_id, net::IOBuffer* handler_source); | 84 int64_t response_id, |
| 85 net::IOBuffer* handler_source); |
| 82 | 86 |
| 83 // Returns the URL of the resource used as entry for 'namespace_url'. | 87 // Returns the URL of the resource used as entry for 'namespace_url'. |
| 84 GURL GetFallbackEntryUrl(const GURL& namespace_url) const { | 88 GURL GetFallbackEntryUrl(const GURL& namespace_url) const { |
| 85 return GetNamespaceEntryUrl(fallback_namespaces_, namespace_url); | 89 return GetNamespaceEntryUrl(fallback_namespaces_, namespace_url); |
| 86 } | 90 } |
| 87 GURL GetInterceptEntryUrl(const GURL& namespace_url) const { | 91 GURL GetInterceptEntryUrl(const GURL& namespace_url) const { |
| 88 return GetNamespaceEntryUrl(intercept_namespaces_, namespace_url); | 92 return GetNamespaceEntryUrl(intercept_namespaces_, namespace_url); |
| 89 } | 93 } |
| 90 | 94 |
| 91 AppCacheHosts& associated_hosts() { return associated_hosts_; } | 95 AppCacheHosts& associated_hosts() { return associated_hosts_; } |
| 92 | 96 |
| 93 bool IsNewerThan(AppCache* cache) const { | 97 bool IsNewerThan(AppCache* cache) const { |
| 94 // TODO(michaeln): revisit, the system clock can be set | 98 // TODO(michaeln): revisit, the system clock can be set |
| 95 // back in time which would confuse this logic. | 99 // back in time which would confuse this logic. |
| 96 if (update_time_ > cache->update_time_) | 100 if (update_time_ > cache->update_time_) |
| 97 return true; | 101 return true; |
| 98 | 102 |
| 99 // Tie breaker. Newer caches have a larger cache ID. | 103 // Tie breaker. Newer caches have a larger cache ID. |
| 100 if (update_time_ == cache->update_time_) | 104 if (update_time_ == cache->update_time_) |
| 101 return cache_id_ > cache->cache_id_; | 105 return cache_id_ > cache->cache_id_; |
| 102 | 106 |
| 103 return false; | 107 return false; |
| 104 } | 108 } |
| 105 | 109 |
| 106 base::Time update_time() const { return update_time_; } | 110 base::Time update_time() const { return update_time_; } |
| 107 | 111 |
| 108 int64 cache_size() const { return cache_size_; } | 112 int64_t cache_size() const { return cache_size_; } |
| 109 | 113 |
| 110 void set_update_time(base::Time ticks) { update_time_ = ticks; } | 114 void set_update_time(base::Time ticks) { update_time_ = ticks; } |
| 111 | 115 |
| 112 // Initializes the cache with information in the manifest. | 116 // Initializes the cache with information in the manifest. |
| 113 // Do not use the manifest after this call. | 117 // Do not use the manifest after this call. |
| 114 void InitializeWithManifest(AppCacheManifest* manifest); | 118 void InitializeWithManifest(AppCacheManifest* manifest); |
| 115 | 119 |
| 116 // Initializes the cache with the information in the database records. | 120 // Initializes the cache with the information in the database records. |
| 117 void InitializeWithDatabaseRecords( | 121 void InitializeWithDatabaseRecords( |
| 118 const AppCacheDatabase::CacheRecord& cache_record, | 122 const AppCacheDatabase::CacheRecord& cache_record, |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 | 173 |
| 170 GURL GetNamespaceEntryUrl(const AppCacheNamespaceVector& namespaces, | 174 GURL GetNamespaceEntryUrl(const AppCacheNamespaceVector& namespaces, |
| 171 const GURL& namespace_url) const; | 175 const GURL& namespace_url) const; |
| 172 | 176 |
| 173 // Use AppCacheHost::Associate*Cache() to manipulate host association. | 177 // Use AppCacheHost::Associate*Cache() to manipulate host association. |
| 174 void AssociateHost(AppCacheHost* host) { | 178 void AssociateHost(AppCacheHost* host) { |
| 175 associated_hosts_.insert(host); | 179 associated_hosts_.insert(host); |
| 176 } | 180 } |
| 177 void UnassociateHost(AppCacheHost* host); | 181 void UnassociateHost(AppCacheHost* host); |
| 178 | 182 |
| 179 const int64 cache_id_; | 183 const int64_t cache_id_; |
| 180 scoped_refptr<AppCacheGroup> owning_group_; | 184 scoped_refptr<AppCacheGroup> owning_group_; |
| 181 AppCacheHosts associated_hosts_; | 185 AppCacheHosts associated_hosts_; |
| 182 | 186 |
| 183 EntryMap entries_; // contains entries of all types | 187 EntryMap entries_; // contains entries of all types |
| 184 | 188 |
| 185 AppCacheNamespaceVector intercept_namespaces_; | 189 AppCacheNamespaceVector intercept_namespaces_; |
| 186 AppCacheNamespaceVector fallback_namespaces_; | 190 AppCacheNamespaceVector fallback_namespaces_; |
| 187 AppCacheNamespaceVector online_whitelist_namespaces_; | 191 AppCacheNamespaceVector online_whitelist_namespaces_; |
| 188 bool online_whitelist_all_; | 192 bool online_whitelist_all_; |
| 189 | 193 |
| 190 bool is_complete_; | 194 bool is_complete_; |
| 191 | 195 |
| 192 // when this cache was last updated | 196 // when this cache was last updated |
| 193 base::Time update_time_; | 197 base::Time update_time_; |
| 194 | 198 |
| 195 int64 cache_size_; | 199 int64_t cache_size_; |
| 196 | 200 |
| 197 typedef std::map<int64, AppCacheExecutableHandler*> HandlerMap; | 201 typedef std::map<int64_t, AppCacheExecutableHandler*> HandlerMap; |
| 198 HandlerMap executable_handlers_; | 202 HandlerMap executable_handlers_; |
| 199 | 203 |
| 200 // to notify storage when cache is deleted | 204 // to notify storage when cache is deleted |
| 201 AppCacheStorage* storage_; | 205 AppCacheStorage* storage_; |
| 202 | 206 |
| 203 FRIEND_TEST_ALL_PREFIXES(content::AppCacheTest, InitializeWithManifest); | 207 FRIEND_TEST_ALL_PREFIXES(content::AppCacheTest, InitializeWithManifest); |
| 204 FRIEND_TEST_ALL_PREFIXES(content::AppCacheTest, ToFromDatabaseRecords); | 208 FRIEND_TEST_ALL_PREFIXES(content::AppCacheTest, ToFromDatabaseRecords); |
| 205 DISALLOW_COPY_AND_ASSIGN(AppCache); | 209 DISALLOW_COPY_AND_ASSIGN(AppCache); |
| 206 }; | 210 }; |
| 207 | 211 |
| 208 } // namespace content | 212 } // namespace content |
| 209 | 213 |
| 210 #endif // CONTENT_BROWSER_APPCACHE_APPCACHE_H_ | 214 #endif // CONTENT_BROWSER_APPCACHE_APPCACHE_H_ |
| OLD | NEW |