OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #include "content/public/browser/browser_thread.h" | |
6 #include "extensions/browser/guest_view/web_view/web_view_renderer_state.h" | |
7 | |
8 using content::BrowserThread; | |
9 | |
10 namespace extensions { | |
11 | |
12 // static | |
13 WebViewRendererState* WebViewRendererState::GetInstance() { | |
14 return Singleton<WebViewRendererState>::get(); | |
15 } | |
16 | |
17 WebViewRendererState::WebViewRendererState() { | |
18 } | |
19 | |
20 WebViewRendererState::~WebViewRendererState() { | |
21 } | |
22 | |
23 bool WebViewRendererState::IsGuest(int render_process_id) { | |
24 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
25 return webview_partition_id_map_.find(render_process_id) != | |
26 webview_partition_id_map_.end(); | |
27 } | |
28 | |
29 void WebViewRendererState::AddGuest(int guest_process_id, | |
30 int guest_routing_id, | |
31 const WebViewInfo& webview_info) { | |
32 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
33 RenderId render_id(guest_process_id, guest_routing_id); | |
34 webview_info_map_[render_id] = webview_info; | |
35 WebViewPartitionIDMap::iterator iter = | |
36 webview_partition_id_map_.find(guest_process_id); | |
37 if (iter != webview_partition_id_map_.end()) { | |
38 ++iter->second.web_view_count; | |
39 return; | |
40 } | |
41 WebViewPartitionInfo partition_info(1, webview_info.partition_id); | |
42 webview_partition_id_map_[guest_process_id] = partition_info; | |
43 } | |
44 | |
45 void WebViewRendererState::RemoveGuest(int guest_process_id, | |
46 int guest_routing_id) { | |
47 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
48 RenderId render_id(guest_process_id, guest_routing_id); | |
49 webview_info_map_.erase(render_id); | |
50 WebViewPartitionIDMap::iterator iter = | |
51 webview_partition_id_map_.find(guest_process_id); | |
52 if (iter != webview_partition_id_map_.end() && | |
53 iter->second.web_view_count > 1) { | |
54 --iter->second.web_view_count; | |
55 return; | |
56 } | |
57 webview_partition_id_map_.erase(guest_process_id); | |
58 } | |
59 | |
60 bool WebViewRendererState::GetInfo(int guest_process_id, | |
61 int guest_routing_id, | |
62 WebViewInfo* webview_info) { | |
63 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
64 RenderId render_id(guest_process_id, guest_routing_id); | |
65 WebViewInfoMap::iterator iter = webview_info_map_.find(render_id); | |
66 if (iter != webview_info_map_.end()) { | |
67 *webview_info = iter->second; | |
68 return true; | |
69 } | |
70 return false; | |
71 } | |
72 | |
73 bool WebViewRendererState::GetPartitionID(int guest_process_id, | |
74 std::string* partition_id) { | |
75 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
76 WebViewPartitionIDMap::iterator iter = | |
77 webview_partition_id_map_.find(guest_process_id); | |
78 if (iter != webview_partition_id_map_.end()) { | |
79 *partition_id = iter->second.partition_id; | |
80 return true; | |
81 } | |
82 return false; | |
83 } | |
84 | |
85 } // namespace extensions | |
OLD | NEW |