Supervised user import: Listen for profile creation/deletion
[chromium-blink-merge.git] / content / browser / appcache / appcache_backend_impl.cc
blob099c54e55adae043a613cfdca79faaa2d1cfeadc
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 "content/browser/appcache/appcache_backend_impl.h"
7 #include "base/stl_util.h"
8 #include "content/browser/appcache/appcache.h"
9 #include "content/browser/appcache/appcache_group.h"
10 #include "content/browser/appcache/appcache_service_impl.h"
12 namespace content {
14 AppCacheBackendImpl::AppCacheBackendImpl()
15 : service_(NULL),
16 frontend_(NULL),
17 process_id_(0) {
20 AppCacheBackendImpl::~AppCacheBackendImpl() {
21 STLDeleteValues(&hosts_);
22 if (service_)
23 service_->UnregisterBackend(this);
26 void AppCacheBackendImpl::Initialize(AppCacheServiceImpl* service,
27 AppCacheFrontend* frontend,
28 int process_id) {
29 DCHECK(!service_ && !frontend_ && frontend && service);
30 service_ = service;
31 frontend_ = frontend;
32 process_id_ = process_id;
33 service_->RegisterBackend(this);
36 bool AppCacheBackendImpl::RegisterHost(int id) {
37 if (GetHost(id))
38 return false;
40 hosts_.insert(
41 HostMap::value_type(id, new AppCacheHost(id, frontend_, service_)));
42 return true;
45 bool AppCacheBackendImpl::UnregisterHost(int id) {
46 HostMap::iterator found = hosts_.find(id);
47 if (found == hosts_.end())
48 return false;
50 delete found->second;
51 hosts_.erase(found);
52 return true;
55 bool AppCacheBackendImpl::SetSpawningHostId(
56 int host_id,
57 int spawning_host_id) {
58 AppCacheHost* host = GetHost(host_id);
59 if (!host)
60 return false;
61 host->SetSpawningHostId(process_id_, spawning_host_id);
62 return true;
65 bool AppCacheBackendImpl::SelectCache(
66 int host_id,
67 const GURL& document_url,
68 const int64 cache_document_was_loaded_from,
69 const GURL& manifest_url) {
70 AppCacheHost* host = GetHost(host_id);
71 if (!host)
72 return false;
74 host->SelectCache(document_url, cache_document_was_loaded_from,
75 manifest_url);
76 return true;
79 bool AppCacheBackendImpl::SelectCacheForWorker(
80 int host_id, int parent_process_id, int parent_host_id) {
81 AppCacheHost* host = GetHost(host_id);
82 if (!host)
83 return false;
85 host->SelectCacheForWorker(parent_process_id, parent_host_id);
86 return true;
89 bool AppCacheBackendImpl::SelectCacheForSharedWorker(
90 int host_id, int64 appcache_id) {
91 AppCacheHost* host = GetHost(host_id);
92 if (!host)
93 return false;
95 host->SelectCacheForSharedWorker(appcache_id);
96 return true;
99 bool AppCacheBackendImpl::MarkAsForeignEntry(
100 int host_id,
101 const GURL& document_url,
102 int64 cache_document_was_loaded_from) {
103 AppCacheHost* host = GetHost(host_id);
104 if (!host)
105 return false;
107 host->MarkAsForeignEntry(document_url, cache_document_was_loaded_from);
108 return true;
111 bool AppCacheBackendImpl::GetStatusWithCallback(
112 int host_id, const GetStatusCallback& callback, void* callback_param) {
113 AppCacheHost* host = GetHost(host_id);
114 if (!host)
115 return false;
117 host->GetStatusWithCallback(callback, callback_param);
118 return true;
121 bool AppCacheBackendImpl::StartUpdateWithCallback(
122 int host_id, const StartUpdateCallback& callback, void* callback_param) {
123 AppCacheHost* host = GetHost(host_id);
124 if (!host)
125 return false;
127 host->StartUpdateWithCallback(callback, callback_param);
128 return true;
131 bool AppCacheBackendImpl::SwapCacheWithCallback(
132 int host_id, const SwapCacheCallback& callback, void* callback_param) {
133 AppCacheHost* host = GetHost(host_id);
134 if (!host)
135 return false;
137 host->SwapCacheWithCallback(callback, callback_param);
138 return true;
141 void AppCacheBackendImpl::GetResourceList(
142 int host_id, std::vector<AppCacheResourceInfo>* resource_infos) {
143 AppCacheHost* host = GetHost(host_id);
144 if (!host)
145 return;
147 host->GetResourceList(resource_infos);
150 scoped_ptr<AppCacheHost> AppCacheBackendImpl::TransferHostOut(int host_id) {
151 HostMap::iterator found = hosts_.find(host_id);
152 if (found == hosts_.end()) {
153 NOTREACHED();
154 return scoped_ptr<AppCacheHost>();
157 AppCacheHost* transferree = found->second;
159 // Put a new empty host in its place.
160 found->second = new AppCacheHost(host_id, frontend_, service_);
162 // We give up ownership.
163 transferree->PrepareForTransfer();
164 return scoped_ptr<AppCacheHost>(transferree);
167 void AppCacheBackendImpl::TransferHostIn(
168 int new_host_id, scoped_ptr<AppCacheHost> host) {
169 HostMap::iterator found = hosts_.find(new_host_id);
170 if (found == hosts_.end()) {
171 NOTREACHED();
172 return;
175 delete found->second;
177 // We take onwership.
178 host->CompleteTransfer(new_host_id, frontend_);
179 found->second = host.release();
182 } // namespace content