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 #include "webkit/browser/appcache/appcache_backend_impl.h"
7 #include "base/stl_util.h"
8 #include "webkit/browser/appcache/appcache.h"
9 #include "webkit/browser/appcache/appcache_group.h"
10 #include "webkit/browser/appcache/appcache_service.h"
14 AppCacheBackendImpl::AppCacheBackendImpl()
20 AppCacheBackendImpl::~AppCacheBackendImpl() {
21 STLDeleteValues(&hosts_);
23 service_->UnregisterBackend(this);
26 void AppCacheBackendImpl::Initialize(AppCacheService* service,
27 AppCacheFrontend* frontend,
29 DCHECK(!service_ && !frontend_ && frontend && service);
32 process_id_ = process_id;
33 service_->RegisterBackend(this);
36 bool AppCacheBackendImpl::RegisterHost(int id) {
41 HostMap::value_type(id, new AppCacheHost(id, frontend_, service_)));
45 bool AppCacheBackendImpl::UnregisterHost(int id) {
46 HostMap::iterator found = hosts_.find(id);
47 if (found == hosts_.end())
55 bool AppCacheBackendImpl::SetSpawningHostId(
57 int spawning_host_id) {
58 AppCacheHost* host = GetHost(host_id);
61 host->SetSpawningHostId(process_id_, spawning_host_id);
65 bool AppCacheBackendImpl::SelectCache(
67 const GURL& document_url,
68 const int64 cache_document_was_loaded_from,
69 const GURL& manifest_url) {
70 AppCacheHost* host = GetHost(host_id);
74 host->SelectCache(document_url, cache_document_was_loaded_from,
79 bool AppCacheBackendImpl::SelectCacheForWorker(
80 int host_id, int parent_process_id, int parent_host_id) {
81 AppCacheHost* host = GetHost(host_id);
85 host->SelectCacheForWorker(parent_process_id, parent_host_id);
89 bool AppCacheBackendImpl::SelectCacheForSharedWorker(
90 int host_id, int64 appcache_id) {
91 AppCacheHost* host = GetHost(host_id);
95 host->SelectCacheForSharedWorker(appcache_id);
99 bool AppCacheBackendImpl::MarkAsForeignEntry(
101 const GURL& document_url,
102 int64 cache_document_was_loaded_from) {
103 AppCacheHost* host = GetHost(host_id);
107 host->MarkAsForeignEntry(document_url, cache_document_was_loaded_from);
111 bool AppCacheBackendImpl::GetStatusWithCallback(
112 int host_id, const GetStatusCallback& callback, void* callback_param) {
113 AppCacheHost* host = GetHost(host_id);
117 host->GetStatusWithCallback(callback, callback_param);
121 bool AppCacheBackendImpl::StartUpdateWithCallback(
122 int host_id, const StartUpdateCallback& callback, void* callback_param) {
123 AppCacheHost* host = GetHost(host_id);
127 host->StartUpdateWithCallback(callback, callback_param);
131 bool AppCacheBackendImpl::SwapCacheWithCallback(
132 int host_id, const SwapCacheCallback& callback, void* callback_param) {
133 AppCacheHost* host = GetHost(host_id);
137 host->SwapCacheWithCallback(callback, callback_param);
141 void AppCacheBackendImpl::GetResourceList(
142 int host_id, std::vector<appcache::AppCacheResourceInfo>* resource_infos) {
143 AppCacheHost* host = GetHost(host_id);
147 host->GetResourceList(resource_infos);
150 } // namespace appcache