Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1235)

Side by Side Diff: content/browser/renderer_host/pepper/browser_ppapi_host_impl.h

Issue 929483004: Plugin Power Saver: Throttled Plugins should block TCPSocket reads. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CONTENT_BROWSER_RENDERER_HOST_PEPPER_BROWSER_PPAPI_HOST_IMPL_H_ 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_PEPPER_BROWSER_PPAPI_HOST_IMPL_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_PEPPER_BROWSER_PPAPI_HOST_IMPL_H_ 6 #define CONTENT_BROWSER_RENDERER_HOST_PEPPER_BROWSER_PPAPI_HOST_IMPL_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
13 #include "base/containers/scoped_ptr_hash_map.h"
13 #include "base/files/file_path.h" 14 #include "base/files/file_path.h"
14 #include "base/memory/ref_counted.h" 15 #include "base/memory/ref_counted.h"
15 #include "base/memory/weak_ptr.h" 16 #include "base/memory/weak_ptr.h"
17 #include "base/observer_list.h"
16 #include "base/process/process.h" 18 #include "base/process/process.h"
17 #include "content/browser/renderer_host/pepper/content_browser_pepper_host_facto ry.h" 19 #include "content/browser/renderer_host/pepper/content_browser_pepper_host_facto ry.h"
18 #include "content/browser/renderer_host/pepper/ssl_context_helper.h" 20 #include "content/browser/renderer_host/pepper/ssl_context_helper.h"
19 #include "content/common/content_export.h" 21 #include "content/common/content_export.h"
20 #include "content/common/pepper_renderer_instance_data.h" 22 #include "content/common/pepper_renderer_instance_data.h"
21 #include "content/public/browser/browser_ppapi_host.h" 23 #include "content/public/browser/browser_ppapi_host.h"
22 #include "content/public/common/process_type.h" 24 #include "content/public/common/process_type.h"
23 #include "ipc/message_filter.h" 25 #include "ipc/message_filter.h"
24 #include "ppapi/host/ppapi_host.h" 26 #include "ppapi/host/ppapi_host.h"
25 27
26 #if !defined(ENABLE_PLUGINS) 28 #if !defined(ENABLE_PLUGINS)
27 #error "Plugins should be enabled" 29 #error "Plugins should be enabled"
28 #endif 30 #endif
29 31
30 namespace content { 32 namespace content {
31 33
32 class CONTENT_EXPORT BrowserPpapiHostImpl : public BrowserPpapiHost { 34 class CONTENT_EXPORT BrowserPpapiHostImpl : public BrowserPpapiHost {
33 public: 35 public:
36 class InstanceObserver {
37 public:
38 // Called when the plugin instance is throttled or unthrottled because of
39 // the Plugin Power Saver feature. Invoked on the IO thread.
40 virtual void OnThrottleStateChanged(bool is_throttled) = 0;
41 };
42
34 // The creator is responsible for calling set_plugin_process as soon as it is 43 // The creator is responsible for calling set_plugin_process as soon as it is
35 // known (we start the process asynchronously so it won't be known when this 44 // known (we start the process asynchronously so it won't be known when this
36 // object is created). 45 // object is created).
37 // |external_plugin| signfies that this is a proxy created for an embedder's 46 // |external_plugin| signfies that this is a proxy created for an embedder's
38 // plugin, i.e. using BrowserPpapiHost::CreateExternalPluginProcess. 47 // plugin, i.e. using BrowserPpapiHost::CreateExternalPluginProcess.
39 BrowserPpapiHostImpl(IPC::Sender* sender, 48 BrowserPpapiHostImpl(IPC::Sender* sender,
40 const ppapi::PpapiPermissions& permissions, 49 const ppapi::PpapiPermissions& permissions,
41 const std::string& plugin_name, 50 const std::string& plugin_name,
42 const base::FilePath& plugin_path, 51 const base::FilePath& plugin_path,
43 const base::FilePath& profile_data_directory, 52 const base::FilePath& profile_data_directory,
(...skipping 19 matching lines...) Expand all
63 void set_plugin_process(base::Process process) { 72 void set_plugin_process(base::Process process) {
64 plugin_process_ = process.Pass(); 73 plugin_process_ = process.Pass();
65 } 74 }
66 75
67 bool external_plugin() const { return external_plugin_; } 76 bool external_plugin() const { return external_plugin_; }
68 77
69 // These two functions are notifications that an instance has been created 78 // These two functions are notifications that an instance has been created
70 // or destroyed. They allow us to maintain a mapping of PP_Instance to data 79 // or destroyed. They allow us to maintain a mapping of PP_Instance to data
71 // associated with the instance including view IDs in the browser process. 80 // associated with the instance including view IDs in the browser process.
72 void AddInstance(PP_Instance instance, 81 void AddInstance(PP_Instance instance,
73 const PepperRendererInstanceData& instance_data); 82 const PepperRendererInstanceData& renderer_instance_data);
74 void DeleteInstance(PP_Instance instance); 83 void DeleteInstance(PP_Instance instance);
75 84
85 void AddInstanceObserver(PP_Instance instance, InstanceObserver* observer);
86 void RemoveInstanceObserver(PP_Instance instance, InstanceObserver* observer);
87
88 void OnThrottleStateChanged(PP_Instance instance, bool is_throttled);
89 bool IsThrottled(PP_Instance instance) const;
90
76 scoped_refptr<IPC::MessageFilter> message_filter() { 91 scoped_refptr<IPC::MessageFilter> message_filter() {
77 return message_filter_; 92 return message_filter_;
78 } 93 }
79 94
80 const scoped_refptr<SSLContextHelper>& ssl_context_helper() const { 95 const scoped_refptr<SSLContextHelper>& ssl_context_helper() const {
81 return ssl_context_helper_; 96 return ssl_context_helper_;
82 } 97 }
83 98
84 private: 99 private:
85 friend class BrowserPpapiHostTest; 100 friend class BrowserPpapiHostTest;
(...skipping 15 matching lines...) Expand all
101 ~HostMessageFilter() override; 116 ~HostMessageFilter() override;
102 117
103 void OnKeepalive(); 118 void OnKeepalive();
104 void OnHostMsgLogInterfaceUsage(int hash) const; 119 void OnHostMsgLogInterfaceUsage(int hash) const;
105 120
106 // Non owning pointers cleared in OnHostDestroyed() 121 // Non owning pointers cleared in OnHostDestroyed()
107 ppapi::host::PpapiHost* ppapi_host_; 122 ppapi::host::PpapiHost* ppapi_host_;
108 BrowserPpapiHostImpl* browser_ppapi_host_impl_; 123 BrowserPpapiHostImpl* browser_ppapi_host_impl_;
109 }; 124 };
110 125
126 struct InstanceData {
127 InstanceData(const PepperRendererInstanceData& renderer_data);
128 ~InstanceData();
129
130 PepperRendererInstanceData renderer_data;
131 bool is_throttled;
132
133 ObserverList<InstanceObserver> observer_list;
134 };
135
111 // Reports plugin activity to the callback set with SetOnKeepaliveCallback. 136 // Reports plugin activity to the callback set with SetOnKeepaliveCallback.
112 void OnKeepalive(); 137 void OnKeepalive();
113 138
114 scoped_ptr<ppapi::host::PpapiHost> ppapi_host_; 139 scoped_ptr<ppapi::host::PpapiHost> ppapi_host_;
115 base::Process plugin_process_; 140 base::Process plugin_process_;
116 std::string plugin_name_; 141 std::string plugin_name_;
117 base::FilePath plugin_path_; 142 base::FilePath plugin_path_;
118 base::FilePath profile_data_directory_; 143 base::FilePath profile_data_directory_;
119 144
120 // If true, this refers to a plugin running in the renderer process. 145 // If true, this refers to a plugin running in the renderer process.
121 bool in_process_; 146 bool in_process_;
122 147
123 // If true, this is an external plugin, i.e. created by the embedder using 148 // If true, this is an external plugin, i.e. created by the embedder using
124 // BrowserPpapiHost::CreateExternalPluginProcess. 149 // BrowserPpapiHost::CreateExternalPluginProcess.
125 bool external_plugin_; 150 bool external_plugin_;
126 151
127 scoped_refptr<SSLContextHelper> ssl_context_helper_; 152 scoped_refptr<SSLContextHelper> ssl_context_helper_;
128 153
129 // Tracks all PP_Instances in this plugin and associated renderer-related 154 // Tracks all PP_Instances in this plugin and associated data.
130 // data. 155 base::ScopedPtrHashMap<PP_Instance, InstanceData> instance_map_;
131 typedef std::map<PP_Instance, PepperRendererInstanceData> InstanceMap;
132 InstanceMap instance_map_;
133 156
134 scoped_refptr<HostMessageFilter> message_filter_; 157 scoped_refptr<HostMessageFilter> message_filter_;
135 158
136 BrowserPpapiHost::OnKeepaliveCallback on_keepalive_callback_; 159 BrowserPpapiHost::OnKeepaliveCallback on_keepalive_callback_;
137 160
138 DISALLOW_COPY_AND_ASSIGN(BrowserPpapiHostImpl); 161 DISALLOW_COPY_AND_ASSIGN(BrowserPpapiHostImpl);
139 }; 162 };
140 163
141 } // namespace content 164 } // namespace content
142 165
143 #endif // CONTENT_BROWSER_RENDERER_HOST_PEPPER_BROWSER_PPAPI_HOST_IMPL_H_ 166 #endif // CONTENT_BROWSER_RENDERER_HOST_PEPPER_BROWSER_PPAPI_HOST_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698