Fix the last lint warnings in chrome/
[chromium-blink-merge.git] / content / ppapi_plugin / ppapi_thread.h
blob8b4f522d7c4d6ecbe9fb7bb90681d1cee0928a2d
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_impl.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 PpapiBlinkPlatformImpl;
43 #if defined(COMPILER_MSVC)
44 // See explanation for other RenderViewHostImpl which is the same issue.
45 #pragma warning(push)
46 #pragma warning(disable: 4250)
47 #endif
49 class PpapiThread : public ChildThreadImpl,
50 public ppapi::proxy::PluginDispatcher::PluginDelegate,
51 public ppapi::proxy::PluginProxyDelegate {
52 public:
53 PpapiThread(const base::CommandLine& command_line, bool is_broker);
54 ~PpapiThread() override;
55 void Shutdown() override;
57 private:
58 // Make sure the enum list in tools/histogram/histograms.xml is updated with
59 // any change in this list.
60 enum LoadResult {
61 LOAD_SUCCESS,
62 LOAD_FAILED,
63 ENTRY_POINT_MISSING,
64 INIT_FAILED,
65 FILE_MISSING,
66 // NOTE: Add new values only immediately above this line.
67 LOAD_RESULT_MAX // Boundary value for UMA_HISTOGRAM_ENUMERATION.
70 // ChildThread overrides.
71 bool Send(IPC::Message* msg) override;
72 bool OnControlMessageReceived(const IPC::Message& msg) override;
73 void OnChannelConnected(int32 peer_pid) override;
75 // PluginDispatcher::PluginDelegate implementation.
76 std::set<PP_Instance>* GetGloballySeenInstanceIDSet() override;
77 base::MessageLoopProxy* GetIPCMessageLoop() override;
78 base::WaitableEvent* GetShutdownEvent() override;
79 IPC::PlatformFileForTransit ShareHandleWithRemote(
80 base::PlatformFile handle,
81 base::ProcessId peer_pid,
82 bool should_close_source) override;
83 uint32 Register(ppapi::proxy::PluginDispatcher* plugin_dispatcher) override;
84 void Unregister(uint32 plugin_dispatcher_id) override;
86 // PluginProxyDelegate.
87 // SendToBrowser() is intended to be safe to use on another thread so
88 // long as the main PpapiThread outlives it.
89 IPC::Sender* GetBrowserSender() override;
90 std::string GetUILanguage() override;
91 void PreCacheFont(const void* logfontw) override;
92 void SetActiveURL(const std::string& url) override;
93 PP_Resource CreateBrowserFont(ppapi::proxy::Connection connection,
94 PP_Instance instance,
95 const PP_BrowserFont_Trusted_Description& desc,
96 const ppapi::Preferences& prefs) override;
98 // Message handlers.
99 void OnLoadPlugin(const base::FilePath& path,
100 const ppapi::PpapiPermissions& permissions);
101 void OnCreateChannel(base::ProcessId renderer_pid,
102 int renderer_child_id,
103 bool incognito);
104 void OnSetNetworkState(bool online);
105 void OnCrash();
106 void OnHang();
108 // Sets up the channel to the given renderer. On success, returns true and
109 // fills the given ChannelHandle with the information from the new channel.
110 bool SetupRendererChannel(base::ProcessId renderer_pid,
111 int renderer_child_id,
112 bool incognito,
113 IPC::ChannelHandle* handle);
115 // Sets up the name of the plugin for logging using the given path.
116 void SavePluginName(const base::FilePath& path);
118 void ReportLoadResult(const base::FilePath& path, LoadResult result);
120 // Reports |error| to UMA when plugin load fails.
121 void ReportLoadErrorCode(const base::FilePath& path,
122 const base::NativeLibraryLoadError& error);
124 // True if running in a broker process rather than a normal plugin process.
125 bool is_broker_;
127 base::ScopedNativeLibrary library_;
129 ppapi::PpapiPermissions permissions_;
131 // Global state tracking for the proxy.
132 ppapi::proxy::PluginGlobals plugin_globals_;
134 // Storage for plugin entry points.
135 PepperPluginInfo::EntryPoints plugin_entry_points_;
137 // Callback to call when a new instance connects to the broker.
138 // Used only when is_broker_.
139 PP_ConnectInstance_Func connect_instance_func_;
141 // Local concept of the module ID. Some functions take this. It's necessary
142 // for the in-process PPAPI to handle this properly, but for proxied it's
143 // unnecessary. The proxy talking to multiple renderers means that each
144 // renderer has a different idea of what the module ID is for this plugin.
145 // To force people to "do the right thing" we generate a random module ID
146 // and pass it around as necessary.
147 PP_Module local_pp_module_;
149 // See Dispatcher::Delegate::GetGloballySeenInstanceIDSet.
150 std::set<PP_Instance> globally_seen_instance_ids_;
152 // The PluginDispatcher instances contained in the map are not owned by it.
153 std::map<uint32, ppapi::proxy::PluginDispatcher*> plugin_dispatchers_;
154 uint32 next_plugin_dispatcher_id_;
156 // The BlinkPlatformImpl implementation.
157 scoped_ptr<PpapiBlinkPlatformImpl> blink_platform_impl_;
159 #if defined(OS_WIN)
160 // Caches the handle to the peer process if this is a broker.
161 base::win::ScopedHandle peer_handle_;
162 #endif
164 DISALLOW_IMPLICIT_CONSTRUCTORS(PpapiThread);
167 #if defined(COMPILER_MSVC)
168 #pragma warning(pop)
169 #endif
171 } // namespace content
173 #endif // CONTENT_PPAPI_PLUGIN_PPAPI_THREAD_H_