Remove linux_chromium_gn_dbg from the chromium CQ.
[chromium-blink-merge.git] / extensions / browser / guest_view / web_view / web_view_renderer_state.cc
blob8e9e26d386c1ce2a396f1b7596dfa2f4b6cdc69e
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 base::Singleton<WebViewRendererState>::get();
23 WebViewRendererState::WebViewRendererState() {
26 WebViewRendererState::~WebViewRendererState() {
29 bool WebViewRendererState::IsGuest(int render_process_id) const {
30 base::AutoLock auto_lock(web_view_partition_id_map_lock_);
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 base::AutoLock auto_lock(web_view_info_map_lock_);
39 base::AutoLock auto_lock2(web_view_partition_id_map_lock_);
41 RenderId render_id(guest_process_id, guest_routing_id);
42 bool updating =
43 web_view_info_map_.find(render_id) != web_view_info_map_.end();
44 web_view_info_map_[render_id] = web_view_info;
45 if (updating)
46 return;
48 auto iter = web_view_partition_id_map_.find(guest_process_id);
49 if (iter != web_view_partition_id_map_.end()) {
50 ++iter->second.web_view_count;
51 return;
53 WebViewPartitionInfo partition_info(1, web_view_info.partition_id);
54 web_view_partition_id_map_[guest_process_id] = partition_info;
57 void WebViewRendererState::RemoveGuest(int guest_process_id,
58 int guest_routing_id) {
59 base::AutoLock auto_lock(web_view_info_map_lock_);
60 base::AutoLock auto_lock2(web_view_partition_id_map_lock_);
62 RenderId render_id(guest_process_id, guest_routing_id);
63 web_view_info_map_.erase(render_id);
64 auto iter = web_view_partition_id_map_.find(guest_process_id);
65 if (iter != web_view_partition_id_map_.end() &&
66 iter->second.web_view_count > 1) {
67 --iter->second.web_view_count;
68 return;
70 web_view_partition_id_map_.erase(guest_process_id);
73 bool WebViewRendererState::GetInfo(int guest_process_id,
74 int guest_routing_id,
75 WebViewInfo* web_view_info) const {
76 base::AutoLock auto_lock(web_view_info_map_lock_);
78 RenderId render_id(guest_process_id, guest_routing_id);
79 auto iter = web_view_info_map_.find(render_id);
80 if (iter != web_view_info_map_.end()) {
81 *web_view_info = iter->second;
82 return true;
84 return false;
87 bool WebViewRendererState::GetOwnerInfo(int guest_process_id,
88 int* owner_process_id,
89 std::string* owner_host) const {
90 base::AutoLock auto_lock(web_view_info_map_lock_);
92 // TODO(fsamuel): Store per-process info in WebViewPartitionInfo instead of in
93 // WebViewInfo.
94 for (const auto& info : web_view_info_map_) {
95 if (info.first.first == guest_process_id) {
96 if (owner_process_id)
97 *owner_process_id = info.second.embedder_process_id;
98 if (owner_host)
99 *owner_host = info.second.owner_host;
100 return true;
103 return false;
106 bool WebViewRendererState::GetPartitionID(int guest_process_id,
107 std::string* partition_id) const {
108 base::AutoLock auto_lock(web_view_partition_id_map_lock_);
110 auto iter = web_view_partition_id_map_.find(guest_process_id);
111 if (iter != web_view_partition_id_map_.end()){
112 *partition_id = iter->second.partition_id;
113 return true;
115 return false;
118 void WebViewRendererState::AddContentScriptIDs(
119 int embedder_process_id,
120 int view_instance_id,
121 const std::set<int>& script_ids) {
122 base::AutoLock auto_lock(web_view_info_map_lock_);
124 for (auto& render_id_info : web_view_info_map_) {
125 WebViewInfo& info = render_id_info.second;
126 if (info.embedder_process_id == embedder_process_id &&
127 info.instance_id == view_instance_id) {
128 for (int id : script_ids)
129 info.content_script_ids.insert(id);
130 return;
135 void WebViewRendererState::RemoveContentScriptIDs(
136 int embedder_process_id,
137 int view_instance_id,
138 const std::set<int>& script_ids) {
139 base::AutoLock auto_lock(web_view_info_map_lock_);
141 for (auto& render_id_info : web_view_info_map_) {
142 WebViewInfo& info = render_id_info.second;
143 if (info.embedder_process_id == embedder_process_id &&
144 info.instance_id == view_instance_id) {
145 for (int id : script_ids)
146 info.content_script_ids.erase(id);
147 return;
152 } // namespace extensions