OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/appcache/appcache_backend_impl.h" | 5 #include "content/browser/appcache/appcache_backend_impl.h" |
6 | 6 |
7 #include "base/stl_util.h" | 7 #include "base/memory/ptr_util.h" |
8 #include "content/browser/appcache/appcache.h" | 8 #include "content/browser/appcache/appcache.h" |
9 #include "content/browser/appcache/appcache_group.h" | 9 #include "content/browser/appcache/appcache_group.h" |
10 #include "content/browser/appcache/appcache_service_impl.h" | 10 #include "content/browser/appcache/appcache_service_impl.h" |
11 | 11 |
12 namespace content { | 12 namespace content { |
13 | 13 |
14 AppCacheBackendImpl::AppCacheBackendImpl() | 14 AppCacheBackendImpl::AppCacheBackendImpl() |
15 : service_(NULL), | 15 : service_(NULL), |
16 frontend_(NULL), | 16 frontend_(NULL), |
17 process_id_(0) { | 17 process_id_(0) { |
18 } | 18 } |
19 | 19 |
20 AppCacheBackendImpl::~AppCacheBackendImpl() { | 20 AppCacheBackendImpl::~AppCacheBackendImpl() { |
21 base::STLDeleteValues(&hosts_); | 21 hosts_.clear(); |
22 if (service_) | 22 if (service_) |
23 service_->UnregisterBackend(this); | 23 service_->UnregisterBackend(this); |
24 } | 24 } |
25 | 25 |
26 void AppCacheBackendImpl::Initialize(AppCacheServiceImpl* service, | 26 void AppCacheBackendImpl::Initialize(AppCacheServiceImpl* service, |
27 AppCacheFrontend* frontend, | 27 AppCacheFrontend* frontend, |
28 int process_id) { | 28 int process_id) { |
29 DCHECK(!service_ && !frontend_ && frontend && service); | 29 DCHECK(!service_ && !frontend_ && frontend && service); |
30 service_ = service; | 30 service_ = service; |
31 frontend_ = frontend; | 31 frontend_ = frontend; |
32 process_id_ = process_id; | 32 process_id_ = process_id; |
33 service_->RegisterBackend(this); | 33 service_->RegisterBackend(this); |
34 } | 34 } |
35 | 35 |
36 bool AppCacheBackendImpl::RegisterHost(int id) { | 36 bool AppCacheBackendImpl::RegisterHost(int id) { |
37 if (GetHost(id)) | 37 if (GetHost(id)) |
38 return false; | 38 return false; |
39 | 39 |
40 hosts_.insert( | 40 hosts_[id] = base::MakeUnique<AppCacheHost>(id, frontend_, service_); |
41 HostMap::value_type(id, new AppCacheHost(id, frontend_, service_))); | |
42 return true; | 41 return true; |
43 } | 42 } |
44 | 43 |
45 bool AppCacheBackendImpl::UnregisterHost(int id) { | 44 bool AppCacheBackendImpl::UnregisterHost(int id) { |
46 HostMap::iterator found = hosts_.find(id); | 45 return hosts_.erase(id) > 0; |
47 if (found == hosts_.end()) | |
48 return false; | |
49 | |
50 delete found->second; | |
51 hosts_.erase(found); | |
52 return true; | |
53 } | 46 } |
54 | 47 |
55 bool AppCacheBackendImpl::SetSpawningHostId( | 48 bool AppCacheBackendImpl::SetSpawningHostId( |
56 int host_id, | 49 int host_id, |
57 int spawning_host_id) { | 50 int spawning_host_id) { |
58 AppCacheHost* host = GetHost(host_id); | 51 AppCacheHost* host = GetHost(host_id); |
59 if (!host) | 52 if (!host) |
60 return false; | 53 return false; |
61 host->SetSpawningHostId(process_id_, spawning_host_id); | 54 host->SetSpawningHostId(process_id_, spawning_host_id); |
62 return true; | 55 return true; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 int host_id, std::vector<AppCacheResourceInfo>* resource_infos) { | 131 int host_id, std::vector<AppCacheResourceInfo>* resource_infos) { |
139 AppCacheHost* host = GetHost(host_id); | 132 AppCacheHost* host = GetHost(host_id); |
140 if (!host) | 133 if (!host) |
141 return; | 134 return; |
142 | 135 |
143 host->GetResourceList(resource_infos); | 136 host->GetResourceList(resource_infos); |
144 } | 137 } |
145 | 138 |
146 std::unique_ptr<AppCacheHost> AppCacheBackendImpl::TransferHostOut( | 139 std::unique_ptr<AppCacheHost> AppCacheBackendImpl::TransferHostOut( |
147 int host_id) { | 140 int host_id) { |
148 HostMap::iterator found = hosts_.find(host_id); | 141 auto found = hosts_.find(host_id); |
149 if (found == hosts_.end()) { | 142 if (found == hosts_.end()) { |
150 NOTREACHED(); | 143 NOTREACHED(); |
151 return std::unique_ptr<AppCacheHost>(); | 144 return std::unique_ptr<AppCacheHost>(); |
152 } | 145 } |
153 | 146 |
154 AppCacheHost* transferree = found->second; | 147 std::unique_ptr<AppCacheHost> transferree = std::move(found->second); |
155 | 148 |
156 // Put a new empty host in its place. | 149 // Put a new empty host in its place. |
157 found->second = new AppCacheHost(host_id, frontend_, service_); | 150 found->second = base::MakeUnique<AppCacheHost>(host_id, frontend_, service_); |
158 | 151 |
159 // We give up ownership. | 152 // We give up ownership. |
160 transferree->PrepareForTransfer(); | 153 transferree->PrepareForTransfer(); |
161 return std::unique_ptr<AppCacheHost>(transferree); | 154 return transferree; |
162 } | 155 } |
163 | 156 |
164 void AppCacheBackendImpl::TransferHostIn(int new_host_id, | 157 void AppCacheBackendImpl::TransferHostIn(int new_host_id, |
165 std::unique_ptr<AppCacheHost> host) { | 158 std::unique_ptr<AppCacheHost> host) { |
166 HostMap::iterator found = hosts_.find(new_host_id); | 159 auto found = hosts_.find(new_host_id); |
167 if (found == hosts_.end()) { | 160 if (found == hosts_.end()) { |
168 NOTREACHED(); | 161 NOTREACHED(); |
169 return; | 162 return; |
170 } | 163 } |
171 | 164 |
172 delete found->second; | |
173 | |
174 // We take onwership. | |
175 host->CompleteTransfer(new_host_id, frontend_); | 165 host->CompleteTransfer(new_host_id, frontend_); |
176 found->second = host.release(); | 166 found->second = std::move(host); |
177 } | 167 } |
178 | 168 |
179 } // namespace content | 169 } // namespace content |
OLD | NEW |