OLD | NEW |
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 CHROME_BROWSER_GPU_BLACKLIST_H_ | 5 #ifndef CONTENT_BROWSER_GPU_GPU_BLACKLIST_H_ |
6 #define CHROME_BROWSER_GPU_BLACKLIST_H_ | 6 #define CONTENT_BROWSER_GPU_GPU_BLACKLIST_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/gtest_prod_util.h" | 12 #include "base/gtest_prod_util.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "base/memory/singleton.h" | |
16 #include "base/values.h" | 15 #include "base/values.h" |
17 #include "content/public/browser/gpu_data_manager_observer.h" | 16 #include "build/build_config.h" |
| 17 #include "content/common/content_export.h" |
18 #include "content/public/common/gpu_feature_type.h" | 18 #include "content/public/common/gpu_feature_type.h" |
19 | 19 |
20 class Version; | 20 class Version; |
21 | 21 |
22 namespace content { | 22 namespace content { |
23 struct GPUInfo; | 23 struct GPUInfo; |
24 } | 24 } |
25 | 25 |
26 class GpuBlacklist : public content::GpuDataManagerObserver { | 26 class CONTENT_EXPORT GpuBlacklist { |
27 public: | 27 public: |
28 enum OsType { | 28 enum OsType { |
29 kOsLinux, | 29 kOsLinux, |
30 kOsMacosx, | 30 kOsMacosx, |
31 kOsWin, | 31 kOsWin, |
32 kOsChromeOS, | 32 kOsChromeOS, |
33 kOsAny, | 33 kOsAny, |
34 kOsUnknown | 34 kOsUnknown |
35 }; | 35 }; |
36 | 36 |
37 enum OsFilter { | 37 enum OsFilter { |
38 // In loading, ignore all entries that belong to other OS. | 38 // In loading, ignore all entries that belong to other OS. |
39 kCurrentOsOnly, | 39 kCurrentOsOnly, |
40 // In loading, keep all entries. This is for testing only. | 40 // In loading, keep all entries. This is for testing only. |
41 kAllOs | 41 kAllOs |
42 }; | 42 }; |
43 | 43 |
44 // Getter for the singleton. This will return NULL on failure. | 44 GpuBlacklist(); |
45 static GpuBlacklist* GetInstance(); | |
46 | |
47 virtual ~GpuBlacklist(); | 45 virtual ~GpuBlacklist(); |
48 | 46 |
49 // Loads blacklist information from a json file. | 47 // Loads blacklist information from a json file. |
50 // If failed, the current GpuBlacklist is un-touched. | 48 // If failed, the current GpuBlacklist is un-touched. |
51 bool LoadGpuBlacklist(const std::string& json_context, | 49 bool LoadGpuBlacklist(const std::string& json_context, OsFilter os_filter); |
| 50 bool LoadGpuBlacklist(const std::string& browser_version_string, |
| 51 const std::string& json_context, |
52 OsFilter os_filter); | 52 OsFilter os_filter); |
53 | 53 |
54 // Collects system information and combines them with gpu_info and blacklist | 54 // Collects system information and combines them with gpu_info and blacklist |
55 // information to determine gpu feature flags. | 55 // information to determine gpu feature flags. |
56 // If os is kOsAny, use the current OS; if os_version is null, use the | 56 // If os is kOsAny, use the current OS; if os_version is null, use the |
57 // current OS version. | 57 // current OS version. |
58 content::GpuFeatureType DetermineGpuFeatureType( | 58 content::GpuFeatureType DetermineGpuFeatureType( |
59 OsType os, Version* os_version, const content::GPUInfo& gpu_info); | 59 OsType os, Version* os_version, const content::GPUInfo& gpu_info); |
60 | 60 |
61 // Helper function that calls DetermineGpuFeatureType and sets the updated | |
62 // features on GpuDataManager. | |
63 void UpdateGpuDataManager(); | |
64 | |
65 // Collects the active entries that set the "feature" flag from the last | 61 // Collects the active entries that set the "feature" flag from the last |
66 // DetermineGpuFeatureType() call. This tells which entries are responsible | 62 // DetermineGpuFeatureType() call. This tells which entries are responsible |
67 // for raising a certain flag, i.e, for blacklisting a certain feature. | 63 // for raising a certain flag, i.e, for blacklisting a certain feature. |
68 // Examples of "feature": | 64 // Examples of "feature": |
69 // GPU_FEATURE_TYPE_ALL - any of the supported features; | 65 // GPU_FEATURE_TYPE_ALL - any of the supported features; |
70 // GPU_FEATURE_TYPE_WEBGL - a single feature; | 66 // GPU_FEATURE_TYPE_WEBGL - a single feature; |
71 // GPU_FEATURE_TYPE_WEBGL | GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING | 67 // GPU_FEATURE_TYPE_WEBGL | GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING |
72 // - two features. | 68 // - two features. |
73 // If disabled set to true, return entries that are disabled; otherwise, | 69 // If disabled set to true, return entries that are disabled; otherwise, |
74 // return enabled entries. | 70 // return enabled entries. |
(...skipping 13 matching lines...) Expand all Loading... |
88 void GetBlacklistReasons(ListValue* problem_list) const; | 84 void GetBlacklistReasons(ListValue* problem_list) const; |
89 | 85 |
90 // Return the largest entry id. This is used for histogramming. | 86 // Return the largest entry id. This is used for histogramming. |
91 uint32 max_entry_id() const; | 87 uint32 max_entry_id() const; |
92 | 88 |
93 // Returns the version of the current blacklist. | 89 // Returns the version of the current blacklist. |
94 std::string GetVersion() const; | 90 std::string GetVersion() const; |
95 | 91 |
96 private: | 92 private: |
97 friend class GpuBlacklistTest; | 93 friend class GpuBlacklistTest; |
98 friend struct DefaultSingletonTraits<GpuBlacklist>; | |
99 FRIEND_TEST_ALL_PREFIXES(GpuBlacklistTest, ChromeVersionEntry); | 94 FRIEND_TEST_ALL_PREFIXES(GpuBlacklistTest, ChromeVersionEntry); |
100 FRIEND_TEST_ALL_PREFIXES(GpuBlacklistTest, CurrentBlacklistValidation); | 95 FRIEND_TEST_ALL_PREFIXES(GpuBlacklistTest, CurrentBlacklistValidation); |
101 FRIEND_TEST_ALL_PREFIXES(GpuBlacklistTest, UnknownField); | 96 FRIEND_TEST_ALL_PREFIXES(GpuBlacklistTest, UnknownField); |
102 FRIEND_TEST_ALL_PREFIXES(GpuBlacklistTest, UnknownExceptionField); | 97 FRIEND_TEST_ALL_PREFIXES(GpuBlacklistTest, UnknownExceptionField); |
103 FRIEND_TEST_ALL_PREFIXES(GpuBlacklistTest, UnknownFeature); | 98 FRIEND_TEST_ALL_PREFIXES(GpuBlacklistTest, UnknownFeature); |
104 | 99 |
105 enum BrowserVersionSupport { | 100 enum BrowserVersionSupport { |
106 kSupported, | 101 kSupported, |
107 kUnsupported, | 102 kUnsupported, |
108 kMalformed | 103 kMalformed |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 scoped_ptr<FloatInfo> perf_overall_info_; | 354 scoped_ptr<FloatInfo> perf_overall_info_; |
360 content::GpuFeatureType feature_type_; | 355 content::GpuFeatureType feature_type_; |
361 std::vector<ScopedGpuBlacklistEntry> exceptions_; | 356 std::vector<ScopedGpuBlacklistEntry> exceptions_; |
362 bool contains_unknown_fields_; | 357 bool contains_unknown_fields_; |
363 bool contains_unknown_features_; | 358 bool contains_unknown_features_; |
364 }; | 359 }; |
365 | 360 |
366 // Gets the current OS type. | 361 // Gets the current OS type. |
367 static OsType GetOsType(); | 362 static OsType GetOsType(); |
368 | 363 |
369 GpuBlacklist(); | |
370 | |
371 bool LoadGpuBlacklist(const std::string& browser_version_string, | |
372 const std::string& json_context, | |
373 OsFilter os_filter); | |
374 | |
375 bool LoadGpuBlacklist(const base::DictionaryValue& parsed_json, | 364 bool LoadGpuBlacklist(const base::DictionaryValue& parsed_json, |
376 OsFilter os_filter); | 365 OsFilter os_filter); |
377 | 366 |
378 void Clear(); | 367 void Clear(); |
379 | 368 |
380 // Check if the entry is supported by the current version of browser. | 369 // Check if the entry is supported by the current version of browser. |
381 // By default, if there is no browser version information in the entry, | 370 // By default, if there is no browser version information in the entry, |
382 // return kSupported; | 371 // return kSupported; |
383 BrowserVersionSupport IsEntrySupportedByCurrentBrowserVersion( | 372 BrowserVersionSupport IsEntrySupportedByCurrentBrowserVersion( |
384 const base::DictionaryValue* value); | 373 const base::DictionaryValue* value); |
385 | 374 |
386 // GpuDataManager::Observer implementation. | |
387 virtual void OnGpuInfoUpdate() OVERRIDE; | |
388 virtual void OnVideoMemoryUsageStatsUpdate( | |
389 const content::GPUVideoMemoryUsageStats& video_memory) OVERRIDE {} | |
390 | |
391 // Returns the number of entries. This is only for tests. | 375 // Returns the number of entries. This is only for tests. |
392 size_t num_entries() const; | 376 size_t num_entries() const; |
393 | 377 |
394 // Check if any entries contain unknown fields. This is only for tests. | 378 // Check if any entries contain unknown fields. This is only for tests. |
395 bool contains_unknown_fields() const { return contains_unknown_fields_; } | 379 bool contains_unknown_fields() const { return contains_unknown_fields_; } |
396 | 380 |
397 static NumericOp StringToNumericOp(const std::string& op); | 381 static NumericOp StringToNumericOp(const std::string& op); |
398 | 382 |
399 scoped_ptr<Version> version_; | 383 scoped_ptr<Version> version_; |
400 std::vector<ScopedGpuBlacklistEntry> blacklist_; | 384 std::vector<ScopedGpuBlacklistEntry> blacklist_; |
401 | 385 |
402 scoped_ptr<Version> browser_version_; | 386 scoped_ptr<Version> browser_version_; |
403 | 387 |
404 // This records all the blacklist entries that are appliable to the current | 388 // This records all the blacklist entries that are appliable to the current |
405 // user machine. It is updated everytime DetermineGpuFeatureType() is | 389 // user machine. It is updated everytime DetermineGpuFeatureType() is |
406 // called and is used later by GetGpuFeatureTypeEntries(). | 390 // called and is used later by GetGpuFeatureTypeEntries(). |
407 std::vector<ScopedGpuBlacklistEntry> active_entries_; | 391 std::vector<ScopedGpuBlacklistEntry> active_entries_; |
408 | 392 |
409 uint32 max_entry_id_; | 393 uint32 max_entry_id_; |
410 | 394 |
411 bool contains_unknown_fields_; | 395 bool contains_unknown_fields_; |
412 | 396 |
413 DISALLOW_COPY_AND_ASSIGN(GpuBlacklist); | 397 DISALLOW_COPY_AND_ASSIGN(GpuBlacklist); |
414 }; | 398 }; |
415 | 399 |
416 #endif // CHROME_BROWSER_GPU_BLACKLIST_H_ | 400 #endif // CONTENT_BROWSER_GPU_GPU_BLACKLIST_H_ |
| 401 |
OLD | NEW |