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
3 // found in the LICENSE file.
5 #include "webkit/appcache/appcache_working_set.h"
7 #include "base/logging.h"
8 #include "webkit/appcache/appcache.h"
9 #include "webkit/appcache/appcache_group.h"
10 #include "webkit/appcache/appcache_response.h"
14 AppCacheWorkingSet::AppCacheWorkingSet() : is_disabled_(false) {}
16 AppCacheWorkingSet::~AppCacheWorkingSet() {
17 DCHECK(caches_
.empty());
18 DCHECK(groups_
.empty());
19 DCHECK(groups_by_origin_
.empty());
22 void AppCacheWorkingSet::Disable() {
28 groups_by_origin_
.clear();
29 response_infos_
.clear();
32 void AppCacheWorkingSet::AddCache(AppCache
* cache
) {
35 DCHECK(cache
->cache_id() != kNoCacheId
);
36 int64 cache_id
= cache
->cache_id();
37 DCHECK(caches_
.find(cache_id
) == caches_
.end());
38 caches_
.insert(CacheMap::value_type(cache_id
, cache
));
41 void AppCacheWorkingSet::RemoveCache(AppCache
* cache
) {
42 caches_
.erase(cache
->cache_id());
45 void AppCacheWorkingSet::AddGroup(AppCacheGroup
* group
) {
48 const GURL
& url
= group
->manifest_url();
49 DCHECK(groups_
.find(url
) == groups_
.end());
50 groups_
.insert(GroupMap::value_type(url
, group
));
51 groups_by_origin_
[url
.GetOrigin()].insert(GroupMap::value_type(url
, group
));
54 void AppCacheWorkingSet::RemoveGroup(AppCacheGroup
* group
) {
55 const GURL
& url
= group
->manifest_url();
58 GURL origin_url
= url
.GetOrigin();
59 GroupMap
* groups_in_origin
= GetMutableGroupsInOrigin(origin_url
);
60 if (groups_in_origin
) {
61 groups_in_origin
->erase(url
);
62 if (groups_in_origin
->empty())
63 groups_by_origin_
.erase(origin_url
);
67 void AppCacheWorkingSet::AddResponseInfo(AppCacheResponseInfo
* info
) {
70 DCHECK(info
->response_id() != kNoResponseId
);
71 int64 response_id
= info
->response_id();
72 DCHECK(response_infos_
.find(response_id
) == response_infos_
.end());
73 response_infos_
.insert(ResponseInfoMap::value_type(response_id
, info
));
76 void AppCacheWorkingSet::RemoveResponseInfo(AppCacheResponseInfo
* info
) {
77 response_infos_
.erase(info
->response_id());