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.
5 #ifndef WEBKIT_APPCACHE_APPCACHE_WORKING_SET_H_
6 #define WEBKIT_APPCACHE_APPCACHE_WORKING_SET_H_
10 #include "base/hash_tables.h"
11 #include "googleurl/src/gurl.h"
12 #include "webkit/storage/webkit_storage_export.h"
18 class AppCacheResponseInfo
;
20 // Represents the working set of appcache object instances
21 // currently in memory.
22 class WEBKIT_STORAGE_EXPORT AppCacheWorkingSet
{
24 typedef std::map
<GURL
, AppCacheGroup
*> GroupMap
;
27 ~AppCacheWorkingSet();
30 bool is_disabled() const { return is_disabled_
; }
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
;
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
;
46 const GroupMap
* GetGroupsInOrigin(const GURL
& origin_url
) {
47 return GetMutableGroupsInOrigin(origin_url
);
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
;
58 typedef base::hash_map
<int64
, AppCache
*> CacheMap
;
59 typedef std::map
<GURL
, GroupMap
> GroupsByOriginMap
;
60 typedef base::hash_map
<int64
, AppCacheResponseInfo
*> ResponseInfoMap
;
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
;
69 GroupsByOriginMap groups_by_origin_
; // origin -> (manifest -> group)
70 ResponseInfoMap response_infos_
;
74 } // namespace appcache
76 #endif // WEBKIT_APPCACHE_APPCACHE_WORKING_SET_H_