1 // Copyright (c) 2011 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 WEBKIT_BROWSER_APPCACHE_APPCACHE_WORKING_SET_H_ 6 #define WEBKIT_BROWSER_APPCACHE_APPCACHE_WORKING_SET_H_ 7 8 #include <map> 9 10 #include "base/containers/hash_tables.h" 11 #include "url/gurl.h" 12 #include "webkit/browser/webkit_storage_browser_export.h" 13 14 namespace appcache { 15 16 class AppCache; 17 class AppCacheGroup; 18 class AppCacheResponseInfo; 19 20 // Represents the working set of appcache object instances 21 // currently in memory. 22 class WEBKIT_STORAGE_BROWSER_EXPORT AppCacheWorkingSet { 23 public: 24 typedef std::map<GURL, AppCacheGroup*> GroupMap; 25 26 AppCacheWorkingSet(); 27 ~AppCacheWorkingSet(); 28 29 void Disable(); 30 bool is_disabled() const { return is_disabled_; } 31 32 void AddCache(AppCache* cache); 33 void RemoveCache(AppCache* cache); 34 AppCache* GetCache(int64 id) { 35 CacheMap::iterator it = caches_.find(id); 36 return (it != caches_.end()) ? it->second : NULL; 37 } 38 39 void AddGroup(AppCacheGroup* group); 40 void RemoveGroup(AppCacheGroup* group); 41 AppCacheGroup* GetGroup(const GURL& manifest_url) { 42 GroupMap::iterator it = groups_.find(manifest_url); 43 return (it != groups_.end()) ? it->second : NULL; 44 } 45 46 const GroupMap* GetGroupsInOrigin(const GURL& origin_url) { 47 return GetMutableGroupsInOrigin(origin_url); 48 } 49 50 void AddResponseInfo(AppCacheResponseInfo* response_info); 51 void RemoveResponseInfo(AppCacheResponseInfo* response_info); 52 AppCacheResponseInfo* GetResponseInfo(int64 id) { 53 ResponseInfoMap::iterator it = response_infos_.find(id); 54 return (it != response_infos_.end()) ? it->second : NULL; 55 } 56 57 private: 58 typedef base::hash_map<int64, AppCache*> CacheMap; 59 typedef std::map<GURL, GroupMap> GroupsByOriginMap; 60 typedef base::hash_map<int64, AppCacheResponseInfo*> ResponseInfoMap; 61 62 GroupMap* GetMutableGroupsInOrigin(const GURL& origin_url) { 63 GroupsByOriginMap::iterator it = groups_by_origin_.find(origin_url); 64 return (it != groups_by_origin_.end()) ? &it->second : NULL; 65 } 66 67 CacheMap caches_; 68 GroupMap groups_; 69 GroupsByOriginMap groups_by_origin_; // origin -> (manifest -> group) 70 ResponseInfoMap response_infos_; 71 bool is_disabled_; 72 }; 73 74 } // namespace appcache 75 76 #endif // WEBKIT_BROWSER_APPCACHE_APPCACHE_WORKING_SET_H_ 77