forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathappcache_navigation_handle.cc
62 lines (50 loc) · 2.14 KB
/
appcache_navigation_handle.cc
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
58
59
60
61
62
// Copyright 2016 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 "content/browser/appcache/appcache_navigation_handle.h"
#include "base/bind.h"
#include "base/lazy_instance.h"
#include "content/browser/appcache/chrome_appcache_service.h"
#include "content/browser/child_process_security_policy_impl.h"
#include "content/public/browser/browser_thread.h"
namespace content {
namespace {
// Map of AppCache host id to the AppCacheNavigationHandle instance.
// Accessed on the UI thread only.
// TODO(nhiroki): base::LazyInstance is deprecated. Use base::NoDestructor
// instead.
using AppCacheHandleMap =
std::map<base::UnguessableToken, content::AppCacheNavigationHandle*>;
base::LazyInstance<AppCacheHandleMap>::DestructorAtExit g_appcache_handle_map =
LAZY_INSTANCE_INITIALIZER;
} // namespace
AppCacheNavigationHandle::AppCacheNavigationHandle(
ChromeAppCacheService* appcache_service,
int process_id)
: appcache_host_id_(base::UnguessableToken::Create()) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
precreated_host_ = std::make_unique<AppCacheHost>(
appcache_host_id_, process_id, MSG_ROUTING_NONE,
ChildProcessSecurityPolicyImpl::GetInstance()->CreateHandle(process_id),
mojo::NullRemote(), static_cast<AppCacheServiceImpl*>(appcache_service));
DCHECK(g_appcache_handle_map.Get().find(appcache_host_id_) ==
g_appcache_handle_map.Get().end());
g_appcache_handle_map.Get()[appcache_host_id_] = this;
}
AppCacheNavigationHandle::~AppCacheNavigationHandle() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
g_appcache_handle_map.Get().erase(appcache_host_id_);
}
// static
std::unique_ptr<AppCacheHost> AppCacheNavigationHandle::TakePrecreatedHost(
const base::UnguessableToken& host_id) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
auto index = g_appcache_handle_map.Get().find(host_id);
if (index != g_appcache_handle_map.Get().end()) {
AppCacheNavigationHandle* instance = index->second;
DCHECK(instance);
return std::move(instance->precreated_host_);
}
return nullptr;
}
} // namespace content