Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / extensions / browser / guest_view / web_view / web_view_renderer_state.cc
blob3068ae3a9b864cf2793dc182b55545bacb97b427
1 // Copyright 2014 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/public/browser/browser_thread.h"
6 #include "extensions/browser/guest_view/web_view/web_view_renderer_state.h"
8 using content::BrowserThread;
10 namespace extensions {
12 WebViewRendererState::WebViewInfo::WebViewInfo() {
15 WebViewRendererState::WebViewInfo::~WebViewInfo() {
18 // static
19 WebViewRendererState* WebViewRendererState::GetInstance() {
20 return Singleton<WebViewRendererState>::get();
23 WebViewRendererState::WebViewRendererState() {
26 WebViewRendererState::~WebViewRendererState() {
29 bool WebViewRendererState::IsGuest(int render_process_id) {
30 DCHECK_CURRENTLY_ON(BrowserThread::IO);
31 return web_view_partition_id_map_.find(render_process_id) !=
32 web_view_partition_id_map_.end();
35 void WebViewRendererState::AddGuest(int guest_process_id,
36 int guest_routing_id,
37 const WebViewInfo& web_view_info) {
38 DCHECK_CURRENTLY_ON(BrowserThread::IO);
39 RenderId render_id(guest_process_id, guest_routing_id);
40 bool updating =
41 web_view_info_map_.find(render_id) != web_view_info_map_.end();
42 web_view_info_map_[render_id] = web_view_info;
43 if (updating)
44 return;
46 auto iter = web_view_partition_id_map_.find(guest_process_id);
47 if (iter != web_view_partition_id_map_.end()) {
48 ++iter->second.web_view_count;
49 return;
51 WebViewPartitionInfo partition_info(1, web_view_info.partition_id);
52 web_view_partition_id_map_[guest_process_id] = partition_info;
55 void WebViewRendererState::RemoveGuest(int guest_process_id,
56 int guest_routing_id) {
57 DCHECK_CURRENTLY_ON(BrowserThread::IO);
58 RenderId render_id(guest_process_id, guest_routing_id);
59 web_view_info_map_.erase(render_id);
60 auto iter = web_view_partition_id_map_.find(guest_process_id);
61 if (iter != web_view_partition_id_map_.end() &&
62 iter->second.web_view_count > 1) {
63 --iter->second.web_view_count;
64 return;
66 web_view_partition_id_map_.erase(guest_process_id);
69 bool WebViewRendererState::GetInfo(int guest_process_id,
70 int guest_routing_id,
71 WebViewInfo* web_view_info) {
72 DCHECK_CURRENTLY_ON(BrowserThread::IO);
73 RenderId render_id(guest_process_id, guest_routing_id);
74 auto iter = web_view_info_map_.find(render_id);
75 if (iter != web_view_info_map_.end()) {
76 *web_view_info = iter->second;
77 return true;
79 return false;
82 bool WebViewRendererState::GetOwnerInfo(int guest_process_id,
83 int* owner_process_id,
84 std::string* owner_host) const {
85 DCHECK_CURRENTLY_ON(BrowserThread::IO);
86 // TODO(fsamuel): Store per-process info in WebViewPartitionInfo instead of in
87 // WebViewInfo.
88 for (const auto& info : web_view_info_map_) {
89 if (info.first.first == guest_process_id) {
90 if (owner_process_id)
91 *owner_process_id = info.second.embedder_process_id;
92 if (owner_host)
93 *owner_host = info.second.owner_host;
94 return true;
97 return false;
100 bool WebViewRendererState::GetPartitionID(int guest_process_id,
101 std::string* partition_id) {
102 DCHECK_CURRENTLY_ON(BrowserThread::IO);
104 auto iter = web_view_partition_id_map_.find(guest_process_id);
105 if (iter != web_view_partition_id_map_.end()){
106 *partition_id = iter->second.partition_id;
107 return true;
109 return false;
112 void WebViewRendererState::AddContentScriptIDs(
113 int embedder_process_id,
114 int view_instance_id,
115 const std::set<int>& script_ids) {
116 DCHECK_CURRENTLY_ON(BrowserThread::IO);
118 for (auto& render_id_info : web_view_info_map_) {
119 WebViewInfo& info = render_id_info.second;
120 if (info.embedder_process_id == embedder_process_id &&
121 info.instance_id == view_instance_id) {
122 for (int id : script_ids)
123 info.content_script_ids.insert(id);
124 return;
129 void WebViewRendererState::RemoveContentScriptIDs(
130 int embedder_process_id,
131 int view_instance_id,
132 const std::set<int>& script_ids) {
133 DCHECK_CURRENTLY_ON(BrowserThread::IO);
135 for (auto& render_id_info : web_view_info_map_) {
136 WebViewInfo& info = render_id_info.second;
137 if (info.embedder_process_id == embedder_process_id &&
138 info.instance_id == view_instance_id) {
139 for (int id : script_ids)
140 info.content_script_ids.erase(id);
141 return;
146 } // namespace extensions