Make sure webrtc::VideoSource is released when WebRtcVideoTrackAdapter is destroyed.
[chromium-blink-merge.git] / content / ppapi_plugin / ppapi_thread.h
blob9b4018905878e04ec38c042eb22a6cb6f4f46307
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
3 // found in the LICENSE file.
5 #ifndef CONTENT_PPAPI_PLUGIN_PPAPI_THREAD_H_
6 #define CONTENT_PPAPI_PLUGIN_PPAPI_THREAD_H_
8 #include <map>
9 #include <string>
11 #include "base/basictypes.h"
12 #include "base/compiler_specific.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/process/process.h"
15 #include "base/scoped_native_library.h"
16 #include "build/build_config.h"
17 #include "content/child/child_thread.h"
18 #include "content/public/common/pepper_plugin_info.h"
19 #include "ppapi/c/pp_module.h"
20 #include "ppapi/c/trusted/ppp_broker.h"
21 #include "ppapi/proxy/connection.h"
22 #include "ppapi/proxy/plugin_dispatcher.h"
23 #include "ppapi/proxy/plugin_globals.h"
24 #include "ppapi/proxy/plugin_proxy_delegate.h"
26 #if defined(OS_WIN)
27 #include "base/win/scoped_handle.h"
28 #endif
30 namespace base {
31 class CommandLine;
32 class FilePath;
35 namespace IPC {
36 struct ChannelHandle;
39 namespace content {
41 class PpapiWebKitPlatformSupportImpl;
43 class PpapiThread : public ChildThread,
44 public ppapi::proxy::PluginDispatcher::PluginDelegate,
45 public ppapi::proxy::PluginProxyDelegate {
46 public:
47 PpapiThread(const base::CommandLine& command_line, bool is_broker);
48 virtual ~PpapiThread();
49 virtual void Shutdown() OVERRIDE;
51 private:
52 // Make sure the enum list in tools/histogram/histograms.xml is updated with
53 // any change in this list.
54 enum LoadResult {
55 LOAD_SUCCESS,
56 LOAD_FAILED,
57 ENTRY_POINT_MISSING,
58 INIT_FAILED,
59 // NOTE: Add new values only immediately above this line.
60 LOAD_RESULT_MAX // Boundary value for UMA_HISTOGRAM_ENUMERATION.
63 // ChildThread overrides.
64 virtual bool Send(IPC::Message* msg) OVERRIDE;
65 virtual bool OnControlMessageReceived(const IPC::Message& msg) OVERRIDE;
66 virtual void OnChannelConnected(int32 peer_pid) OVERRIDE;
68 // PluginDispatcher::PluginDelegate implementation.
69 virtual std::set<PP_Instance>* GetGloballySeenInstanceIDSet() OVERRIDE;
70 virtual base::MessageLoopProxy* GetIPCMessageLoop() OVERRIDE;
71 virtual base::WaitableEvent* GetShutdownEvent() OVERRIDE;
72 virtual IPC::PlatformFileForTransit ShareHandleWithRemote(
73 base::PlatformFile handle,
74 base::ProcessId peer_pid,
75 bool should_close_source) OVERRIDE;
76 virtual uint32 Register(
77 ppapi::proxy::PluginDispatcher* plugin_dispatcher) OVERRIDE;
78 virtual void Unregister(uint32 plugin_dispatcher_id) OVERRIDE;
80 // PluginProxyDelegate.
81 // SendToBrowser() is intended to be safe to use on another thread so
82 // long as the main PpapiThread outlives it.
83 virtual IPC::Sender* GetBrowserSender() OVERRIDE;
84 virtual std::string GetUILanguage() OVERRIDE;
85 virtual void PreCacheFont(const void* logfontw) OVERRIDE;
86 virtual void SetActiveURL(const std::string& url) OVERRIDE;
87 virtual PP_Resource CreateBrowserFont(
88 ppapi::proxy::Connection connection,
89 PP_Instance instance,
90 const PP_BrowserFont_Trusted_Description& desc,
91 const ppapi::Preferences& prefs) OVERRIDE;
93 // Message handlers.
94 void OnLoadPlugin(const base::FilePath& path,
95 const ppapi::PpapiPermissions& permissions);
96 void OnCreateChannel(base::ProcessId renderer_pid,
97 int renderer_child_id,
98 bool incognito);
99 void OnSetNetworkState(bool online);
100 void OnCrash();
101 void OnHang();
103 // Sets up the channel to the given renderer. On success, returns true and
104 // fills the given ChannelHandle with the information from the new channel.
105 bool SetupRendererChannel(base::ProcessId renderer_pid,
106 int renderer_child_id,
107 bool incognito,
108 IPC::ChannelHandle* handle);
110 // Sets up the name of the plugin for logging using the given path.
111 void SavePluginName(const base::FilePath& path);
113 void ReportLoadResult(const base::FilePath& path, LoadResult result);
115 // Reports |error| to UMA when plugin load fails.
116 void ReportLoadErrorCode(const base::FilePath& path,
117 const base::NativeLibraryLoadError& error);
119 // True if running in a broker process rather than a normal plugin process.
120 bool is_broker_;
122 base::ScopedNativeLibrary library_;
124 ppapi::PpapiPermissions permissions_;
126 // Global state tracking for the proxy.
127 ppapi::proxy::PluginGlobals plugin_globals_;
129 // Storage for plugin entry points.
130 PepperPluginInfo::EntryPoints plugin_entry_points_;
132 // Callback to call when a new instance connects to the broker.
133 // Used only when is_broker_.
134 PP_ConnectInstance_Func connect_instance_func_;
136 // Local concept of the module ID. Some functions take this. It's necessary
137 // for the in-process PPAPI to handle this properly, but for proxied it's
138 // unnecessary. The proxy talking to multiple renderers means that each
139 // renderer has a different idea of what the module ID is for this plugin.
140 // To force people to "do the right thing" we generate a random module ID
141 // and pass it around as necessary.
142 PP_Module local_pp_module_;
144 // See Dispatcher::Delegate::GetGloballySeenInstanceIDSet.
145 std::set<PP_Instance> globally_seen_instance_ids_;
147 // The PluginDispatcher instances contained in the map are not owned by it.
148 std::map<uint32, ppapi::proxy::PluginDispatcher*> plugin_dispatchers_;
149 uint32 next_plugin_dispatcher_id_;
151 // The WebKitPlatformSupport implementation.
152 scoped_ptr<PpapiWebKitPlatformSupportImpl> webkit_platform_support_;
154 #if defined(OS_WIN)
155 // Caches the handle to the peer process if this is a broker.
156 base::win::ScopedHandle peer_handle_;
157 #endif
159 DISALLOW_IMPLICIT_CONSTRUCTORS(PpapiThread);
162 } // namespace content
164 #endif // CONTENT_PPAPI_PLUGIN_PPAPI_THREAD_H_