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

Side by Side Diff: chrome/browser/gpu_blacklist.cc

Issue 10683005: Remove two deprecated methods from base::Version (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ... Created 8 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/first_run/upgrade_util_win.cc ('k') | chrome/browser/gpu_blacklist_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "chrome/browser/gpu_blacklist.h" 5 #include "chrome/browser/gpu_blacklist.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/json/json_reader.h" 8 #include "base/json/json_reader.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/string_number_conversions.h" 10 #include "base/string_number_conversions.h"
11 #include "base/string_split.h" 11 #include "base/string_split.h"
12 #include "base/string_util.h" 12 #include "base/string_util.h"
13 #include "base/sys_info.h" 13 #include "base/sys_info.h"
14 #include "base/version.h" 14 #include "base/version.h"
15 #include "chrome/browser/gpu_util.h" 15 #include "chrome/browser/gpu_util.h"
16 #include "chrome/common/chrome_version_info.h" 16 #include "chrome/common/chrome_version_info.h"
17 #include "content/public/browser/gpu_data_manager.h" 17 #include "content/public/browser/gpu_data_manager.h"
18 #include "content/public/common/content_switches.h" 18 #include "content/public/common/content_switches.h"
19 #include "content/public/common/gpu_info.h" 19 #include "content/public/common/gpu_info.h"
20 20
21 using content::GpuDataManager; 21 using content::GpuDataManager;
22 using content::GpuFeatureType; 22 using content::GpuFeatureType;
23 23
24 namespace { 24 namespace {
25 25
26 // Encode a date as Version, where [0] is year, [1] is month, and [2] is day. 26 // Encode a date as Version, where [0] is year, [1] is month, and [2] is day.
27 Version* GetDateFromString(const std::string& date_string) { 27 void GetDateFromString(const std::string& date_string, Version* version) {
28 // TODO(zmo): verify if in Windows registry, driver dates are always in the 28 // TODO(zmo): verify if in Windows registry, driver dates are always in the
29 // format of "mm-dd-yyyy". 29 // format of "mm-dd-yyyy".
30 std::vector<std::string> pieces; 30 std::vector<std::string> pieces;
31 base::SplitString(date_string, '-', &pieces); 31 base::SplitString(date_string, '-', &pieces);
32 if (pieces.size() != 3) 32 if (pieces.size() != 3) {
33 return NULL; 33 *version = Version();
34 return;
35 }
34 std::string date_as_version_string = pieces[2]; 36 std::string date_as_version_string = pieces[2];
35 for (size_t i = 0; i < 2; ++i) { 37 for (size_t i = 0; i < 2; ++i) {
36 date_as_version_string += "."; 38 date_as_version_string += ".";
37 date_as_version_string += pieces[i]; 39 date_as_version_string += pieces[i];
38 } 40 }
39 return Version::GetVersionFromString(date_as_version_string); 41 *version = Version(date_as_version_string);
40 } 42 }
41 43
42 // We assume the input format is major.minor, and we treat major version 44 // We assume the input format is major.minor, and we treat major version
43 // as numerical and minor as lexical. 45 // as numerical and minor as lexical.
44 // Otherwise we simply return the original string. 46 // Otherwise we simply return the original string.
45 // For example, if input numerical is 8.103, returned lexical is 8.1.0.3. 47 // For example, if input numerical is 8.103, returned lexical is 8.1.0.3.
46 std::string NumericalToLexical(const std::string& numerical) { 48 std::string NumericalToLexical(const std::string& numerical) {
47 std::string lexical; 49 std::string lexical;
48 bool valid = true; 50 bool valid = true;
49 size_t pos = numerical.find_first_of('.'); 51 size_t pos = numerical.find_first_of('.');
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 return; 86 return;
85 version_style_ = StringToVersionStyle(version_style); 87 version_style_ = StringToVersionStyle(version_style);
86 std::string processed_version_string, processed_version_string2; 88 std::string processed_version_string, processed_version_string2;
87 if (version_style_ == kVersionStyleLexical) { 89 if (version_style_ == kVersionStyleLexical) {
88 processed_version_string = NumericalToLexical(version_string); 90 processed_version_string = NumericalToLexical(version_string);
89 processed_version_string2 = NumericalToLexical(version_string2); 91 processed_version_string2 = NumericalToLexical(version_string2);
90 } else { 92 } else {
91 processed_version_string = version_string; 93 processed_version_string = version_string;
92 processed_version_string2 = version_string2; 94 processed_version_string2 = version_string2;
93 } 95 }
94 version_.reset(Version::GetVersionFromString(processed_version_string)); 96 version_.reset(new Version(processed_version_string));
95 if (version_.get() == NULL) { 97 if (!version_->IsValid()) {
96 op_ = kUnknown; 98 op_ = kUnknown;
97 return; 99 return;
98 } 100 }
99 if (op_ == kBetween) { 101 if (op_ == kBetween) {
100 version2_.reset(Version::GetVersionFromString(processed_version_string2)); 102 version2_.reset(new Version(processed_version_string2));
101 if (version2_.get() == NULL) 103 if (!version2_->IsValid())
102 op_ = kUnknown; 104 op_ = kUnknown;
103 } 105 }
104 } 106 }
105 107
106 GpuBlacklist::VersionInfo::~VersionInfo() { 108 GpuBlacklist::VersionInfo::~VersionInfo() {
107 } 109 }
108 110
109 bool GpuBlacklist::VersionInfo::Contains(const Version& version) const { 111 bool GpuBlacklist::VersionInfo::Contains(const Version& version) const {
110 if (op_ == kUnknown) 112 if (op_ == kUnknown)
111 return false; 113 return false;
(...skipping 676 matching lines...) Expand 10 before | Expand all | Expand 10 after
788 } 790 }
789 if (driver_vendor_info_.get() != NULL && 791 if (driver_vendor_info_.get() != NULL &&
790 !driver_vendor_info_->Contains(gpu_info.driver_vendor)) 792 !driver_vendor_info_->Contains(gpu_info.driver_vendor))
791 return false; 793 return false;
792 if (driver_version_info_.get() != NULL) { 794 if (driver_version_info_.get() != NULL) {
793 std::string processed_driver_version; 795 std::string processed_driver_version;
794 if (driver_version_info_->IsLexical()) 796 if (driver_version_info_->IsLexical())
795 processed_driver_version = NumericalToLexical(gpu_info.driver_version); 797 processed_driver_version = NumericalToLexical(gpu_info.driver_version);
796 else 798 else
797 processed_driver_version = gpu_info.driver_version; 799 processed_driver_version = gpu_info.driver_version;
798 scoped_ptr<Version> driver_version( 800 Version driver_version(processed_driver_version);
799 Version::GetVersionFromString(processed_driver_version)); 801 if (!driver_version.IsValid() ||
800 if (driver_version.get() == NULL || 802 !driver_version_info_->Contains(driver_version))
801 !driver_version_info_->Contains(*driver_version))
802 return false; 803 return false;
803 } 804 }
804 if (driver_date_info_.get() != NULL) { 805 if (driver_date_info_.get() != NULL) {
805 scoped_ptr<Version> driver_date(GetDateFromString(gpu_info.driver_date)); 806 Version driver_date;
806 if (driver_date.get() == NULL || 807 GetDateFromString(gpu_info.driver_date, &driver_date);
807 !driver_date_info_->Contains(*driver_date)) 808 if (!driver_date.IsValid() || !driver_date_info_->Contains(driver_date))
808 return false; 809 return false;
809 } 810 }
810 if (gl_vendor_info_.get() != NULL && 811 if (gl_vendor_info_.get() != NULL &&
811 !gl_vendor_info_->Contains(gpu_info.gl_vendor)) 812 !gl_vendor_info_->Contains(gpu_info.gl_vendor))
812 return false; 813 return false;
813 if (gl_renderer_info_.get() != NULL && 814 if (gl_renderer_info_.get() != NULL &&
814 !gl_renderer_info_->Contains(gpu_info.gl_renderer)) 815 !gl_renderer_info_->Contains(gpu_info.gl_renderer))
815 return false; 816 return false;
816 if (perf_graphics_info_.get() != NULL && 817 if (perf_graphics_info_.get() != NULL &&
817 (gpu_info.performance_stats.graphics == 0.0 || 818 (gpu_info.performance_stats.graphics == 0.0 ||
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
871 chrome::VersionInfo chrome_version_info; 872 chrome::VersionInfo chrome_version_info;
872 std::string chrome_version_string = 873 std::string chrome_version_string =
873 chrome_version_info.is_valid() ? chrome_version_info.Version() : "0"; 874 chrome_version_info.is_valid() ? chrome_version_info.Version() : "0";
874 return LoadGpuBlacklist(chrome_version_string, json_context, os_filter); 875 return LoadGpuBlacklist(chrome_version_string, json_context, os_filter);
875 } 876 }
876 877
877 bool GpuBlacklist::LoadGpuBlacklist( 878 bool GpuBlacklist::LoadGpuBlacklist(
878 const std::string& browser_version_string, 879 const std::string& browser_version_string,
879 const std::string& json_context, 880 const std::string& json_context,
880 GpuBlacklist::OsFilter os_filter) { 881 GpuBlacklist::OsFilter os_filter) {
881 browser_version_.reset(Version::GetVersionFromString(browser_version_string)); 882 browser_version_.reset(new Version(browser_version_string));
882 DCHECK(browser_version_.get() != NULL); 883 DCHECK(browser_version_->IsValid());
883 884
884 scoped_ptr<Value> root; 885 scoped_ptr<Value> root;
885 root.reset(base::JSONReader::Read(json_context)); 886 root.reset(base::JSONReader::Read(json_context));
886 if (root.get() == NULL || !root->IsType(Value::TYPE_DICTIONARY)) 887 if (root.get() == NULL || !root->IsType(Value::TYPE_DICTIONARY))
887 return false; 888 return false;
888 889
889 DictionaryValue* root_dictionary = static_cast<DictionaryValue*>(root.get()); 890 DictionaryValue* root_dictionary = static_cast<DictionaryValue*>(root.get());
890 DCHECK(root_dictionary); 891 DCHECK(root_dictionary);
891 return LoadGpuBlacklist(*root_dictionary, os_filter); 892 return LoadGpuBlacklist(*root_dictionary, os_filter);
892 } 893 }
893 894
894 bool GpuBlacklist::LoadGpuBlacklist( 895 bool GpuBlacklist::LoadGpuBlacklist(
895 const DictionaryValue& parsed_json, GpuBlacklist::OsFilter os_filter) { 896 const DictionaryValue& parsed_json, GpuBlacklist::OsFilter os_filter) {
896 std::vector<ScopedGpuBlacklistEntry> entries; 897 std::vector<ScopedGpuBlacklistEntry> entries;
897 898
898 std::string version_string; 899 std::string version_string;
899 parsed_json.GetString("version", &version_string); 900 parsed_json.GetString("version", &version_string);
900 version_.reset(Version::GetVersionFromString(version_string)); 901 version_.reset(new Version(version_string));
901 if (version_.get() == NULL) 902 if (!version_->IsValid())
902 return false; 903 return false;
903 904
904 ListValue* list = NULL; 905 ListValue* list = NULL;
905 if (!parsed_json.GetList("entries", &list)) 906 if (!parsed_json.GetList("entries", &list))
906 return false; 907 return false;
907 908
908 uint32 max_entry_id = 0; 909 uint32 max_entry_id = 0;
909 bool contains_unknown_fields = false; 910 bool contains_unknown_fields = false;
910 for (size_t i = 0; i < list->GetSize(); ++i) { 911 for (size_t i = 0; i < list->GetSize(); ++i) {
911 DictionaryValue* list_item = NULL; 912 DictionaryValue* list_item = NULL;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
959 int type = 0; 960 int type = 0;
960 961
961 if (os == kOsAny) 962 if (os == kOsAny)
962 os = GetOsType(); 963 os = GetOsType();
963 scoped_ptr<Version> my_os_version; 964 scoped_ptr<Version> my_os_version;
964 if (os_version == NULL) { 965 if (os_version == NULL) {
965 std::string version_string = base::SysInfo::OperatingSystemVersion(); 966 std::string version_string = base::SysInfo::OperatingSystemVersion();
966 size_t pos = version_string.find_first_not_of("0123456789."); 967 size_t pos = version_string.find_first_not_of("0123456789.");
967 if (pos != std::string::npos) 968 if (pos != std::string::npos)
968 version_string = version_string.substr(0, pos); 969 version_string = version_string.substr(0, pos);
969 my_os_version.reset(Version::GetVersionFromString(version_string)); 970 my_os_version.reset(new Version(version_string));
970 os_version = my_os_version.get(); 971 os_version = my_os_version.get();
971 } 972 }
972 DCHECK(os_version != NULL); 973 DCHECK(os_version != NULL);
973 974
974 for (size_t i = 0; i < blacklist_.size(); ++i) { 975 for (size_t i = 0; i < blacklist_.size(); ++i) {
975 if (blacklist_[i]->Contains(os, *os_version, gpu_info)) { 976 if (blacklist_[i]->Contains(os, *os_version, gpu_info)) {
976 if (!blacklist_[i]->disabled()) 977 if (!blacklist_[i]->disabled())
977 type |= blacklist_[i]->GetGpuFeatureType(); 978 type |= blacklist_[i]->GetGpuFeatureType();
978 active_entries_.push_back(blacklist_[i]); 979 active_entries_.push_back(blacklist_[i]);
979 } 980 }
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
1110 return kGT; 1111 return kGT;
1111 if (op == ">=") 1112 if (op == ">=")
1112 return kGE; 1113 return kGE;
1113 if (op == "any") 1114 if (op == "any")
1114 return kAny; 1115 return kAny;
1115 if (op == "between") 1116 if (op == "between")
1116 return kBetween; 1117 return kBetween;
1117 return kUnknown; 1118 return kUnknown;
1118 } 1119 }
1119 1120
OLDNEW
« no previous file with comments | « chrome/browser/first_run/upgrade_util_win.cc ('k') | chrome/browser/gpu_blacklist_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698