Make USB permissions work in the new permission message system
[chromium-blink-merge.git] / content / browser / gpu / gpu_data_manager_impl_private.h
blobae7a879f147967c5a5f98123c0893dae120be0a8
1 // Copyright (c) 2013 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_BROWSER_GPU_GPU_DATA_MANAGER_IMPL_PRIVATE_H_
6 #define CONTENT_BROWSER_GPU_GPU_DATA_MANAGER_IMPL_PRIVATE_H_
8 #include <list>
9 #include <map>
10 #include <set>
11 #include <string>
12 #include <vector>
14 #include "base/memory/ref_counted.h"
15 #include "base/memory/singleton.h"
16 #include "base/observer_list_threadsafe.h"
17 #include "content/browser/gpu/gpu_data_manager_impl.h"
18 #include "gpu/config/gpu_blacklist.h"
19 #include "gpu/config/gpu_driver_bug_list.h"
21 namespace base {
22 class CommandLine;
25 namespace content {
27 class CONTENT_EXPORT GpuDataManagerImplPrivate {
28 public:
29 static GpuDataManagerImplPrivate* Create(GpuDataManagerImpl* owner);
31 void InitializeForTesting(
32 const std::string& gpu_blacklist_json,
33 const gpu::GPUInfo& gpu_info);
34 bool IsFeatureBlacklisted(int feature) const;
35 bool IsDriverBugWorkaroundActive(int feature) const;
36 gpu::GPUInfo GetGPUInfo() const;
37 void GetGpuProcessHandles(
38 const GpuDataManager::GetGpuProcessHandlesCallback& callback) const;
39 bool GpuAccessAllowed(std::string* reason) const;
40 void RequestCompleteGpuInfoIfNeeded();
41 bool IsEssentialGpuInfoAvailable() const;
42 bool IsCompleteGpuInfoAvailable() const;
43 void RequestVideoMemoryUsageStatsUpdate() const;
44 bool ShouldUseSwiftShader() const;
45 void RegisterSwiftShaderPath(const base::FilePath& path);
46 bool ShouldUseWarp() const;
47 void AddObserver(GpuDataManagerObserver* observer);
48 void RemoveObserver(GpuDataManagerObserver* observer);
49 void UnblockDomainFrom3DAPIs(const GURL& url);
50 void DisableGpuWatchdog();
51 void SetGLStrings(const std::string& gl_vendor,
52 const std::string& gl_renderer,
53 const std::string& gl_version);
54 void GetGLStrings(std::string* gl_vendor,
55 std::string* gl_renderer,
56 std::string* gl_version);
57 void DisableHardwareAcceleration();
59 void Initialize();
61 void UpdateGpuInfo(const gpu::GPUInfo& gpu_info);
63 void UpdateVideoMemoryUsageStats(
64 const GPUVideoMemoryUsageStats& video_memory_usage_stats);
66 void AppendRendererCommandLine(base::CommandLine* command_line) const;
68 void AppendGpuCommandLine(base::CommandLine* command_line) const;
70 void AppendPluginCommandLine(base::CommandLine* command_line) const;
72 void UpdateRendererWebPrefs(WebPreferences* prefs) const;
74 std::string GetBlacklistVersion() const;
75 std::string GetDriverBugListVersion() const;
77 void GetBlacklistReasons(base::ListValue* reasons) const;
79 std::vector<std::string> GetDriverBugWorkarounds() const;
81 void AddLogMessage(int level,
82 const std::string& header,
83 const std::string& message);
85 void ProcessCrashed(base::TerminationStatus exit_code);
87 base::ListValue* GetLogMessages() const;
89 void HandleGpuSwitch();
91 bool CanUseGpuBrowserCompositor() const;
92 bool ShouldDisableAcceleratedVideoDecode(
93 const base::CommandLine* command_line) const;
95 void GetDisabledExtensions(std::string* disabled_extensions) const;
97 void BlockDomainFrom3DAPIs(
98 const GURL& url, GpuDataManagerImpl::DomainGuilt guilt);
99 bool Are3DAPIsBlocked(const GURL& url,
100 int render_process_id,
101 int render_view_id,
102 ThreeDAPIType requester);
104 void DisableDomainBlockingFor3DAPIsForTesting();
106 void Notify3DAPIBlocked(const GURL& url,
107 int render_process_id,
108 int render_view_id,
109 ThreeDAPIType requester);
111 size_t GetBlacklistedFeatureCount() const;
113 void SetDisplayCount(unsigned int display_count);
114 unsigned int GetDisplayCount() const;
116 bool UpdateActiveGpu(uint32 vendor_id, uint32 device_id);
118 void OnGpuProcessInitFailure();
120 virtual ~GpuDataManagerImplPrivate();
122 private:
123 friend class GpuDataManagerImplPrivateTest;
125 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
126 GpuSideBlacklisting);
127 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
128 GpuSideExceptions);
129 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
130 DisableHardwareAcceleration);
131 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
132 SwiftShaderRendering);
133 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
134 SwiftShaderRendering2);
135 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
136 WarpEnabledOverridesSwiftShader);
137 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
138 GpuInfoUpdate);
139 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
140 NoGpuInfoUpdateWithSwiftShader);
141 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
142 GPUVideoMemoryUsageStatsUpdate);
143 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
144 BlockAllDomainsFrom3DAPIs);
145 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
146 UnblockGuiltyDomainFrom3DAPIs);
147 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
148 UnblockDomainOfUnknownGuiltFrom3DAPIs);
149 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
150 UnblockOtherDomainFrom3DAPIs);
151 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
152 UnblockThisDomainFrom3DAPIs);
153 #if defined(OS_LINUX)
154 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
155 SetGLStrings);
156 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
157 SetGLStringsNoEffects);
158 #endif
159 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
160 GpuDriverBugListSingle);
161 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
162 GpuDriverBugListMultiple);
163 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
164 BlacklistAllFeatures);
166 struct DomainBlockEntry {
167 GpuDataManagerImpl::DomainGuilt last_guilt;
170 typedef std::map<std::string, DomainBlockEntry> DomainBlockMap;
172 typedef base::ObserverListThreadSafe<GpuDataManagerObserver>
173 GpuDataManagerObserverList;
175 struct LogMessage {
176 int level;
177 std::string header;
178 std::string message;
180 LogMessage(int _level,
181 const std::string& _header,
182 const std::string& _message)
183 : level(_level),
184 header(_header),
185 message(_message) { }
188 explicit GpuDataManagerImplPrivate(GpuDataManagerImpl* owner);
190 void InitializeImpl(const std::string& gpu_blacklist_json,
191 const std::string& gpu_driver_bug_list_json,
192 const gpu::GPUInfo& gpu_info);
194 void UpdateGpuInfoHelper();
196 void UpdateBlacklistedFeatures(const std::set<int>& features);
198 // This should only be called once at initialization time, when preliminary
199 // gpu info is collected.
200 void UpdatePreliminaryBlacklistedFeatures();
202 // Update the GPU switching status.
203 // This should only be called once at initialization time.
204 void UpdateGpuSwitchingManager(const gpu::GPUInfo& gpu_info);
206 // Notify all observers whenever there is a GPU info update.
207 void NotifyGpuInfoUpdate();
209 // Try to switch to SwiftShader rendering, if possible and necessary.
210 void EnableSwiftShaderIfNecessary();
212 // Try to switch to WARP rendering if the GPU hardware is not supported or
213 // absent, and if we are trying to run in Windows Metro mode.
214 void EnableWarpIfNecessary();
216 // Use only for testing, forces |use_warp_| to true.
217 void ForceWarpModeForTesting();
219 // Helper to extract the domain from a given URL.
220 std::string GetDomainFromURL(const GURL& url) const;
222 // Implementation functions for blocking of 3D graphics APIs, used
223 // for unit testing.
224 void BlockDomainFrom3DAPIsAtTime(const GURL& url,
225 GpuDataManagerImpl::DomainGuilt guilt,
226 base::Time at_time);
227 GpuDataManagerImpl::DomainBlockStatus Are3DAPIsBlockedAtTime(
228 const GURL& url, base::Time at_time) const;
229 int64 GetBlockAllDomainsDurationInMs() const;
231 bool complete_gpu_info_already_requested_;
233 std::set<int> blacklisted_features_;
234 std::set<int> preliminary_blacklisted_features_;
236 std::set<int> gpu_driver_bugs_;
238 gpu::GPUInfo gpu_info_;
240 scoped_ptr<gpu::GpuBlacklist> gpu_blacklist_;
241 scoped_ptr<gpu::GpuDriverBugList> gpu_driver_bug_list_;
243 const scoped_refptr<GpuDataManagerObserverList> observer_list_;
245 std::vector<LogMessage> log_messages_;
247 bool use_swiftshader_;
249 bool use_warp_;
251 base::FilePath swiftshader_path_;
253 // Current card force-blacklisted due to GPU crashes, or disabled through
254 // the --disable-gpu commandline switch.
255 bool card_blacklisted_;
257 // We disable histogram stuff in testing, especially in unit tests because
258 // they cause random failures.
259 bool update_histograms_;
261 // Number of currently open windows, to be used in gpu memory allocation.
262 int window_count_;
264 DomainBlockMap blocked_domains_;
265 mutable std::list<base::Time> timestamps_of_gpu_resets_;
266 bool domain_blocking_enabled_;
268 GpuDataManagerImpl* owner_;
270 unsigned int display_count_;
272 bool gpu_process_accessible_;
274 // True if all future Initialize calls should be ignored.
275 bool finalized_;
277 std::string disabled_extensions_;
279 DISALLOW_COPY_AND_ASSIGN(GpuDataManagerImplPrivate);
282 } // namespace content
284 #endif // CONTENT_BROWSER_GPU_GPU_DATA_MANAGER_IMPL_PRIVATE_H_