Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / extensions / browser / guest_view / web_view / web_view_renderer_state.h
bloba6e5f438818fcb2c404be8798674807e5dbd9c87
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 #ifndef EXTENSIONS_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_RENDERER_STATE_H_
6 #define EXTENSIONS_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_RENDERER_STATE_H_
8 #include <map>
9 #include <string>
10 #include <utility>
12 #include "base/memory/singleton.h"
14 namespace extensions {
16 class WebViewGuest;
18 // This class keeps track of <webview> renderer state for use on the IO thread.
19 // All methods should be called on the IO thread.
20 class WebViewRendererState {
21 public:
22 struct WebViewInfo {
23 int embedder_process_id;
24 int instance_id;
25 std::string partition_id;
26 std::string embedder_extension_id;
29 static WebViewRendererState* GetInstance();
31 // Looks up the information for the embedder <webview> for a given render
32 // view, if one exists. Called on the IO thread.
33 bool GetInfo(int guest_process_id, int guest_routing_id,
34 WebViewInfo* webview_info);
36 // Looks up the partition info for the embedder <webview> for a given guest
37 // process. Called on the IO thread.
38 bool GetPartitionID(int guest_process_id, std::string* partition_id);
40 // Returns true if the given renderer is used by webviews.
41 bool IsGuest(int render_process_id);
43 private:
44 friend class WebViewGuest;
45 friend struct DefaultSingletonTraits<WebViewRendererState>;
47 typedef std::pair<int, int> RenderId;
48 typedef std::map<RenderId, WebViewInfo> WebViewInfoMap;
50 struct WebViewPartitionInfo {
51 int web_view_count;
52 std::string partition_id;
53 WebViewPartitionInfo() {}
54 WebViewPartitionInfo(int count, std::string partition):
55 web_view_count(count),
56 partition_id(partition) {}
59 typedef std::map<int, WebViewPartitionInfo> WebViewPartitionIDMap;
61 WebViewRendererState();
62 ~WebViewRendererState();
64 // Adds or removes a <webview> guest render process from the set.
65 void AddGuest(int render_process_host_id, int routing_id,
66 const WebViewInfo& webview_info);
67 void RemoveGuest(int render_process_host_id, int routing_id);
69 WebViewInfoMap webview_info_map_;
70 WebViewPartitionIDMap webview_partition_id_map_;
72 DISALLOW_COPY_AND_ASSIGN(WebViewRendererState);
75 } // namespace extensions
77 #endif // EXTENSIONS_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_RENDERER_STATE_H_