summaryrefslogtreecommitdiffstats
path: root/webkit/appcache/appcache.cc
blob: 5e7bca631d3b53b9dbe164f3cffca0dcfeef9515 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "webkit/appcache/appcache.h"

#include "base/logging.h"
#include "webkit/appcache/appcache_group.h"
#include "webkit/appcache/appcache_host.h"
#include "webkit/appcache/appcache_service.h"

namespace appcache {

AppCache::AppCache(AppCacheService *service, int64 cache_id)
  : cache_id_(cache_id),
    manifest_(NULL),
    owning_group_(NULL),
    online_whitelist_all_(false),
    is_complete_(false),
    service_(service) {
  service_->AddCache(this);
}

AppCache::~AppCache() {
  DCHECK(associated_hosts_.empty());
  DCHECK(!owning_group_);
  service_->RemoveCache(this);
}

void AppCache::UnassociateHost(AppCacheHost* host) {
  associated_hosts_.erase(host);

  // Inform group if this cache is no longer in use.
  if (associated_hosts_.empty() && owning_group_)
    owning_group_->RemoveCache(this);
}

void AppCache::AddEntry(const GURL& url, const AppCacheEntry& entry) {
  DCHECK(entries_.find(url) == entries_.end());
  entries_.insert(EntryMap::value_type(url, entry));
}

void AppCache::AddOrModifyEntry(const GURL& url, const AppCacheEntry& entry) {
  std::pair<EntryMap::iterator, bool> ret =
    entries_.insert(EntryMap::value_type(url, entry));

  // Entry already exists.  Merge the types of the new and existing entries.
  if (!ret.second)
    ret.first->second.add_types(entry.types());
}

AppCacheEntry* AppCache::GetEntry(const GURL& url) {
  EntryMap::iterator it = entries_.find(url);
  return (it != entries_.end()) ? &(it->second) : NULL;
}

}  // namespace appcache