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

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: Fix a broken test 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/files/file_path.h" 13 #include "base/files/file_path.h"
14 #include "base/memory/linked_ptr.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 virtual void OnThrottleStateChanged(bool is_throttled) = 0;
dmichael (off chromium) 2015/02/18 18:58:09 Maybe add a note about what this function means an
tommycli 2015/02/18 19:19:09 Done. I assume it's okay that it's invoked on IO t
dmichael (off chromium) 2015/02/18 20:31:40 Right, I just want to make sure it's documented ri
tommycli 2015/02/18 21:31:17 Done.
39 };
40
34 // The creator is responsible for calling set_plugin_process as soon as it is 41 // 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 42 // known (we start the process asynchronously so it won't be known when this
36 // object is created). 43 // object is created).
37 // |external_plugin| signfies that this is a proxy created for an embedder's 44 // |external_plugin| signfies that this is a proxy created for an embedder's
38 // plugin, i.e. using BrowserPpapiHost::CreateExternalPluginProcess. 45 // plugin, i.e. using BrowserPpapiHost::CreateExternalPluginProcess.
39 BrowserPpapiHostImpl(IPC::Sender* sender, 46 BrowserPpapiHostImpl(IPC::Sender* sender,
40 const ppapi::PpapiPermissions& permissions, 47 const ppapi::PpapiPermissions& permissions,
41 const std::string& plugin_name, 48 const std::string& plugin_name,
42 const base::FilePath& plugin_path, 49 const base::FilePath& plugin_path,
43 const base::FilePath& profile_data_directory, 50 const base::FilePath& profile_data_directory,
(...skipping 22 matching lines...) Expand all
66 73
67 bool external_plugin() const { return external_plugin_; } 74 bool external_plugin() const { return external_plugin_; }
68 75
69 // These two functions are notifications that an instance has been created 76 // 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 77 // 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. 78 // associated with the instance including view IDs in the browser process.
72 void AddInstance(PP_Instance instance, 79 void AddInstance(PP_Instance instance,
73 const PepperRendererInstanceData& instance_data); 80 const PepperRendererInstanceData& instance_data);
74 void DeleteInstance(PP_Instance instance); 81 void DeleteInstance(PP_Instance instance);
75 82
83 void AddInstanceObserver(PP_Instance instance, InstanceObserver* observer);
84 void RemoveInstanceObserver(PP_Instance instance, InstanceObserver* observer);
85
86 void OnThrottleStateChanged(PP_Instance instance, bool is_throttled);
87 bool IsThrottled(PP_Instance instance) const;
88
76 scoped_refptr<IPC::MessageFilter> message_filter() { 89 scoped_refptr<IPC::MessageFilter> message_filter() {
77 return message_filter_; 90 return message_filter_;
78 } 91 }
79 92
80 const scoped_refptr<SSLContextHelper>& ssl_context_helper() const { 93 const scoped_refptr<SSLContextHelper>& ssl_context_helper() const {
81 return ssl_context_helper_; 94 return ssl_context_helper_;
82 } 95 }
83 96
84 private: 97 private:
85 friend class BrowserPpapiHostTest; 98 friend class BrowserPpapiHostTest;
(...skipping 15 matching lines...) Expand all
101 ~HostMessageFilter() override; 114 ~HostMessageFilter() override;
102 115
103 void OnKeepalive(); 116 void OnKeepalive();
104 void OnHostMsgLogInterfaceUsage(int hash) const; 117 void OnHostMsgLogInterfaceUsage(int hash) const;
105 118
106 // Non owning pointers cleared in OnHostDestroyed() 119 // Non owning pointers cleared in OnHostDestroyed()
107 ppapi::host::PpapiHost* ppapi_host_; 120 ppapi::host::PpapiHost* ppapi_host_;
108 BrowserPpapiHostImpl* browser_ppapi_host_impl_; 121 BrowserPpapiHostImpl* browser_ppapi_host_impl_;
109 }; 122 };
110 123
124 struct InstanceData {
125 InstanceData();
126 ~InstanceData();
127
128 PepperRendererInstanceData renderer_data;
129 bool is_throttled;
130
131 // linked_ptr wrapper required because InstanceData must be copyable to
132 // be stored in an STL container.
133 linked_ptr<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 typedef std::map<PP_Instance, InstanceData> InstanceMap;
131 typedef std::map<PP_Instance, PepperRendererInstanceData> InstanceMap;
132 InstanceMap instance_map_; 156 InstanceMap instance_map_;
133 157
134 scoped_refptr<HostMessageFilter> message_filter_; 158 scoped_refptr<HostMessageFilter> message_filter_;
135 159
136 BrowserPpapiHost::OnKeepaliveCallback on_keepalive_callback_; 160 BrowserPpapiHost::OnKeepaliveCallback on_keepalive_callback_;
137 161
138 DISALLOW_COPY_AND_ASSIGN(BrowserPpapiHostImpl); 162 DISALLOW_COPY_AND_ASSIGN(BrowserPpapiHostImpl);
139 }; 163 };
140 164
141 } // namespace content 165 } // namespace content
142 166
143 #endif // CONTENT_BROWSER_RENDERER_HOST_PEPPER_BROWSER_PPAPI_HOST_IMPL_H_ 167 #endif // CONTENT_BROWSER_RENDERER_HOST_PEPPER_BROWSER_PPAPI_HOST_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698