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/memory/ptr_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 #include "content/public/browser/browser_thread.h" | |
12 #include "content/public/common/browser_side_navigation_policy.h" | |
11 | 13 |
12 namespace content { | 14 namespace content { |
13 | 15 |
14 AppCacheBackendImpl::AppCacheBackendImpl() | 16 AppCacheBackendImpl::AppCacheBackendImpl() |
15 : service_(NULL), | 17 : service_(NULL), |
16 frontend_(NULL), | 18 frontend_(NULL), |
17 process_id_(0) { | 19 process_id_(0) { |
18 } | 20 } |
19 | 21 |
20 AppCacheBackendImpl::~AppCacheBackendImpl() { | 22 AppCacheBackendImpl::~AppCacheBackendImpl() { |
21 hosts_.clear(); | 23 hosts_.clear(); |
22 if (service_) | 24 if (service_) |
23 service_->UnregisterBackend(this); | 25 service_->UnregisterBackend(this); |
24 } | 26 } |
25 | 27 |
26 void AppCacheBackendImpl::Initialize(AppCacheServiceImpl* service, | 28 void AppCacheBackendImpl::Initialize(AppCacheServiceImpl* service, |
27 AppCacheFrontend* frontend, | 29 AppCacheFrontend* frontend, |
28 int process_id) { | 30 int process_id) { |
29 DCHECK(!service_ && !frontend_ && frontend && service); | 31 DCHECK(!service_ && !frontend_ && frontend && service); |
30 service_ = service; | 32 service_ = service; |
31 frontend_ = frontend; | 33 frontend_ = frontend; |
32 process_id_ = process_id; | 34 process_id_ = process_id; |
33 service_->RegisterBackend(this); | 35 service_->RegisterBackend(this); |
34 } | 36 } |
35 | 37 |
36 bool AppCacheBackendImpl::RegisterHost(int id) { | 38 bool AppCacheBackendImpl::RegisterHost(int id) { |
37 if (GetHost(id)) | 39 AppCacheHost* host = GetHost(id); |
40 | |
41 if (host) { | |
42 // PlzNavigate. The is precreated which means we want to avoid registering | |
43 // it again. | |
44 if (IsBrowserSideNavigationEnabled()) { | |
45 auto found = pending_hosts_.find(id); | |
46 DCHECK(found != pending_hosts_.end()); | |
michaeln
2016/12/05 21:52:54
Since this |id| is given to us by a potentially co
ananta
2016/12/06 01:24:38
The pending hosts are no longer needed with your s
| |
47 pending_hosts_.erase(found); | |
48 // Switch the frontend proxy so that the host can make IPC calls from | |
49 // here on. | |
50 host->set_frontend(frontend_); | |
51 return true; | |
52 } | |
38 return false; | 53 return false; |
54 } | |
39 | 55 |
40 hosts_[id] = base::MakeUnique<AppCacheHost>(id, frontend_, service_); | 56 hosts_[id] = base::MakeUnique<AppCacheHost>(id, frontend_, service_); |
41 return true; | 57 return true; |
42 } | 58 } |
43 | 59 |
44 bool AppCacheBackendImpl::UnregisterHost(int id) { | 60 bool AppCacheBackendImpl::UnregisterHost(int id) { |
45 return hosts_.erase(id) > 0; | 61 return hosts_.erase(id) > 0; |
46 } | 62 } |
47 | 63 |
48 bool AppCacheBackendImpl::SetSpawningHostId( | 64 bool AppCacheBackendImpl::SetSpawningHostId( |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
159 auto found = hosts_.find(new_host_id); | 175 auto found = hosts_.find(new_host_id); |
160 if (found == hosts_.end()) { | 176 if (found == hosts_.end()) { |
161 NOTREACHED(); | 177 NOTREACHED(); |
162 return; | 178 return; |
163 } | 179 } |
164 | 180 |
165 host->CompleteTransfer(new_host_id, frontend_); | 181 host->CompleteTransfer(new_host_id, frontend_); |
166 found->second = std::move(host); | 182 found->second = std::move(host); |
167 } | 183 } |
168 | 184 |
185 void AppCacheBackendImpl::RegisterPrecreatedHost( | |
186 std::unique_ptr<AppCacheHost> host) { | |
187 DCHECK(IsBrowserSideNavigationEnabled()); | |
188 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
189 | |
190 DCHECK(host.get()); | |
191 // Mark the host as pending so we can avoid registering it again in the | |
192 // RegisterHost() call. | |
193 DCHECK(pending_hosts_.find(host->host_id()) == pending_hosts_.end()); | |
194 pending_hosts_.insert(host->host_id()); | |
195 | |
196 DCHECK(hosts_.find(host->host_id()) == hosts_.end()); | |
197 hosts_[host->host_id()] = std::move(host); | |
198 } | |
199 | |
169 } // namespace content | 200 } // namespace content |
OLD | NEW |