Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / extensions / browser / guest_view / web_view / web_view_renderer_state.cc
blob16879127c7e6c8fc4da578d1dc19fe46f9036a58
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 // static
13 WebViewRendererState* WebViewRendererState::GetInstance() {
14 return Singleton<WebViewRendererState>::get();
17 WebViewRendererState::WebViewRendererState() {
20 WebViewRendererState::~WebViewRendererState() {
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();
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;
41 WebViewPartitionInfo partition_info(1, webview_info.partition_id);
42 webview_partition_id_map_[guest_process_id] = partition_info;
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;
57 webview_partition_id_map_.erase(guest_process_id);
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;
70 return false;
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;
82 return false;
85 } // namespace extensions