blob: 1c5f61f05f6a2ac109f721a57fcd7cd6841777ed [file] [log] [blame]
[email protected]81732082011-02-14 10:36:591// Copyright (c) 2011 The Chromium Authors. All rights reserved.
[email protected]2efc31182010-12-11 21:07:182// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]d9f37932011-05-09 20:09:245#include "content/browser/gpu/gpu_blacklist.h"
[email protected]2efc31182010-12-11 21:07:186
7#include "base/json/json_reader.h"
8#include "base/logging.h"
9#include "base/string_number_conversions.h"
[email protected]f0221ea2011-03-01 22:09:4910#include "base/string_piece.h"
11#include "base/string_split.h"
[email protected]36ee0322010-12-23 21:27:1212#include "base/string_util.h"
[email protected]2efc31182010-12-11 21:07:1813#include "base/stringprintf.h"
14#include "base/sys_info.h"
15#include "base/values.h"
16#include "base/version.h"
[email protected]f24a1e2b2011-04-08 01:48:4817#include "content/common/gpu/gpu_info.h"
[email protected]2efc31182010-12-11 21:07:1818
[email protected]f0221ea2011-03-01 22:09:4919namespace {
20
21// Encode a date as Version, where [0] is year, [1] is month, and [2] is day.
22Version* GetDateFromString(const std::string& date_string) {
23 // TODO(zmo): verify if in Windows registry, driver dates are always in the
24 // format of "mm-dd-yyyy".
25 std::vector<std::string> pieces;
26 base::SplitString(date_string, '-', &pieces);
[email protected]cf746942011-03-02 00:50:5527 if (pieces.size() != 3)
[email protected]f0221ea2011-03-01 22:09:4928 return NULL;
[email protected]cf746942011-03-02 00:50:5529 std::string date_as_version_string = pieces[2];
30 for (size_t i = 0; i < 2; ++i) {
[email protected]f0221ea2011-03-01 22:09:4931 date_as_version_string += ".";
32 date_as_version_string += pieces[i];
33 }
34 return Version::GetVersionFromString(date_as_version_string);
35}
36
[email protected]198b50072011-04-18 17:00:4537Value* NewStatusValue(const char* name, const char* status)
38{
39 DictionaryValue* value = new DictionaryValue();
40 value->SetString("name", name);
41 value->SetString("status", status);
42 return value;
43}
44
[email protected]f0221ea2011-03-01 22:09:4945} // namespace anonymous
46
[email protected]2efc31182010-12-11 21:07:1847GpuBlacklist::VersionInfo::VersionInfo(const std::string& version_op,
48 const std::string& version_string,
49 const std::string& version_string2) {
50 op_ = StringToOp(version_op);
51 if (op_ == kUnknown || op_ == kAny)
52 return;
53 version_.reset(Version::GetVersionFromString(version_string));
54 if (version_.get() == NULL) {
55 op_ = kUnknown;
56 return;
57 }
58 if (op_ == kBetween) {
59 version2_.reset(Version::GetVersionFromString(version_string2));
60 if (version2_.get() == NULL)
61 op_ = kUnknown;
62 }
63}
64
65GpuBlacklist::VersionInfo::~VersionInfo() {
66}
67
68bool GpuBlacklist::VersionInfo::Contains(const Version& version) const {
69 if (op_ == kUnknown)
70 return false;
71 if (op_ == kAny)
72 return true;
73 if (op_ == kEQ) {
74 // Handles cases where 10.6 is considered as containing 10.6.*.
75 const std::vector<uint16>& components_reference = version_->components();
76 const std::vector<uint16>& components = version.components();
77 for (size_t i = 0; i < components_reference.size(); ++i) {
78 if (i >= components.size() && components_reference[i] != 0)
79 return false;
80 if (components[i] != components_reference[i])
81 return false;
82 }
83 return true;
84 }
85 int relation = version.CompareTo(*version_);
86 if (op_ == kEQ)
87 return (relation == 0);
88 else if (op_ == kLT)
89 return (relation < 0);
90 else if (op_ == kLE)
91 return (relation <= 0);
92 else if (op_ == kGT)
93 return (relation > 0);
94 else if (op_ == kGE)
95 return (relation >= 0);
96 // op_ == kBetween
97 if (relation < 0)
98 return false;
99 return version.CompareTo(*version2_) <= 0;
100}
101
102bool GpuBlacklist::VersionInfo::IsValid() const {
103 return op_ != kUnknown;
104}
105
106GpuBlacklist::VersionInfo::Op GpuBlacklist::VersionInfo::StringToOp(
107 const std::string& version_op) {
108 if (version_op == "=")
109 return kEQ;
110 else if (version_op == "<")
111 return kLT;
112 else if (version_op == "<=")
113 return kLE;
114 else if (version_op == ">")
115 return kGT;
116 else if (version_op == ">=")
117 return kGE;
118 else if (version_op == "any")
119 return kAny;
120 else if (version_op == "between")
121 return kBetween;
122 return kUnknown;
123}
124
125GpuBlacklist::OsInfo::OsInfo(const std::string& os,
126 const std::string& version_op,
127 const std::string& version_string,
128 const std::string& version_string2) {
129 type_ = StringToOsType(os);
130 if (type_ != kOsUnknown) {
131 version_info_.reset(
132 new VersionInfo(version_op, version_string, version_string2));
133 }
134}
135
[email protected]1e605472010-12-16 21:41:40136GpuBlacklist::OsInfo::~OsInfo() {}
137
[email protected]2efc31182010-12-11 21:07:18138bool GpuBlacklist::OsInfo::Contains(OsType type,
139 const Version& version) const {
140 if (!IsValid())
141 return false;
142 if (type_ != type && type_ != kOsAny)
143 return false;
144 return version_info_->Contains(version);
145}
146
147bool GpuBlacklist::OsInfo::IsValid() const {
148 return type_ != kOsUnknown && version_info_->IsValid();
149}
150
151GpuBlacklist::OsType GpuBlacklist::OsInfo::type() const {
152 return type_;
153}
154
155GpuBlacklist::OsType GpuBlacklist::OsInfo::StringToOsType(
156 const std::string& os) {
157 if (os == "win")
158 return kOsWin;
159 else if (os == "macosx")
160 return kOsMacosx;
161 else if (os == "linux")
162 return kOsLinux;
[email protected]f0db0ee2011-03-22 21:42:42163 else if (os == "chromeos")
164 return kOsChromeOS;
[email protected]2efc31182010-12-11 21:07:18165 else if (os == "any")
166 return kOsAny;
167 return kOsUnknown;
168}
169
[email protected]61ce18f2011-01-25 17:16:10170GpuBlacklist::StringInfo::StringInfo(const std::string& string_op,
171 const std::string& string_value) {
172 op_ = StringToOp(string_op);
173 value_ = StringToLowerASCII(string_value);
174}
175
176bool GpuBlacklist::StringInfo::Contains(const std::string& value) const {
177 std::string my_value = StringToLowerASCII(value);
178 switch (op_) {
179 case kContains:
180 return strstr(my_value.c_str(), value_.c_str()) != NULL;
181 case kBeginWith:
182 return StartsWithASCII(my_value, value_, false);
183 case kEndWith:
184 return EndsWith(my_value, value_, false);
185 case kEQ:
186 return value_ == my_value;
187 default:
188 return false;
189 }
190}
191
192bool GpuBlacklist::StringInfo::IsValid() const {
193 return op_ != kUnknown;
194}
195
196GpuBlacklist::StringInfo::Op GpuBlacklist::StringInfo::StringToOp(
197 const std::string& string_op) {
198 if (string_op == "=")
199 return kEQ;
200 else if (string_op == "contains")
201 return kContains;
202 else if (string_op == "beginwith")
203 return kBeginWith;
204 else if (string_op == "endwith")
205 return kEndWith;
206 return kUnknown;
207}
208
[email protected]7f2f3512011-08-25 01:27:54209// static
[email protected]863d5662011-08-25 23:15:10210GpuBlacklist::ScopedGpuBlacklistEntry
[email protected]2efc31182010-12-11 21:07:18211GpuBlacklist::GpuBlacklistEntry::GetGpuBlacklistEntryFromValue(
[email protected]88a9e7842011-03-01 16:48:39212 DictionaryValue* value, bool top_level) {
[email protected]c6540e22011-04-06 16:23:49213 DCHECK(value);
[email protected]7f2f3512011-08-25 01:27:54214 ScopedGpuBlacklistEntry entry(new GpuBlacklistEntry());
[email protected]2efc31182010-12-11 21:07:18215
[email protected]005d0cf2011-05-31 18:13:53216 size_t dictionary_entry_count = 0;
217
[email protected]88a9e7842011-03-01 16:48:39218 if (top_level) {
[email protected]4bf0a52d2011-03-04 01:09:05219 uint32 id;
220 if (!value->GetInteger("id", reinterpret_cast<int*>(&id)) ||
221 !entry->SetId(id)) {
222 LOG(WARNING) << "Malformed id entry " << entry->id();
[email protected]88a9e7842011-03-01 16:48:39223 return NULL;
224 }
[email protected]005d0cf2011-05-31 18:13:53225 dictionary_entry_count++;
[email protected]61ce18f2011-01-25 17:16:10226 }
227
[email protected]47847e9c2011-03-03 01:17:41228 std::string description;
229 if (value->GetString("description", &description)) {
230 entry->description_ = description;
[email protected]005d0cf2011-05-31 18:13:53231 dictionary_entry_count++;
[email protected]47847e9c2011-03-03 01:17:41232 } else {
233 entry->description_ = "The GPU is unavailable for an unexplained reason.";
234 }
235
236 ListValue* cr_bugs;
237 if (value->GetList("cr_bugs", &cr_bugs)) {
[email protected]4bf0a52d2011-03-04 01:09:05238 for (size_t i = 0; i < cr_bugs->GetSize(); ++i) {
[email protected]47847e9c2011-03-03 01:17:41239 int bug_id;
[email protected]4bf0a52d2011-03-04 01:09:05240 if (cr_bugs->GetInteger(i, &bug_id)) {
[email protected]47847e9c2011-03-03 01:17:41241 entry->cr_bugs_.push_back(bug_id);
[email protected]4bf0a52d2011-03-04 01:09:05242 } else {
[email protected]47847e9c2011-03-03 01:17:41243 LOG(WARNING) << "Malformed cr_bugs entry " << entry->id();
[email protected]4bf0a52d2011-03-04 01:09:05244 return NULL;
245 }
[email protected]47847e9c2011-03-03 01:17:41246 }
[email protected]005d0cf2011-05-31 18:13:53247 dictionary_entry_count++;
[email protected]47847e9c2011-03-03 01:17:41248 }
249
250 ListValue* webkit_bugs;
251 if (value->GetList("webkit_bugs", &webkit_bugs)) {
[email protected]4bf0a52d2011-03-04 01:09:05252 for (size_t i = 0; i < webkit_bugs->GetSize(); ++i) {
[email protected]47847e9c2011-03-03 01:17:41253 int bug_id;
[email protected]4bf0a52d2011-03-04 01:09:05254 if (webkit_bugs->GetInteger(i, &bug_id)) {
[email protected]47847e9c2011-03-03 01:17:41255 entry->webkit_bugs_.push_back(bug_id);
[email protected]4bf0a52d2011-03-04 01:09:05256 } else {
[email protected]47847e9c2011-03-03 01:17:41257 LOG(WARNING) << "Malformed webkit_bugs entry " << entry->id();
[email protected]4bf0a52d2011-03-04 01:09:05258 return NULL;
259 }
[email protected]47847e9c2011-03-03 01:17:41260 }
[email protected]005d0cf2011-05-31 18:13:53261 dictionary_entry_count++;
[email protected]47847e9c2011-03-03 01:17:41262 }
263
[email protected]2efc31182010-12-11 21:07:18264 DictionaryValue* os_value = NULL;
265 if (value->GetDictionary("os", &os_value)) {
266 std::string os_type;
267 std::string os_version_op = "any";
268 std::string os_version_string;
269 std::string os_version_string2;
270 os_value->GetString("type", &os_type);
271 DictionaryValue* os_version_value = NULL;
272 if (os_value->GetDictionary("version", &os_version_value)) {
273 os_version_value->GetString("op", &os_version_op);
274 os_version_value->GetString("number", &os_version_string);
275 os_version_value->GetString("number2", &os_version_string2);
276 }
277 if (!entry->SetOsInfo(os_type, os_version_op, os_version_string,
278 os_version_string2)) {
[email protected]4bf0a52d2011-03-04 01:09:05279 LOG(WARNING) << "Malformed os entry " << entry->id();
[email protected]2efc31182010-12-11 21:07:18280 return NULL;
281 }
[email protected]005d0cf2011-05-31 18:13:53282 dictionary_entry_count++;
[email protected]2efc31182010-12-11 21:07:18283 }
284
285 std::string vendor_id;
286 if (value->GetString("vendor_id", &vendor_id)) {
287 if (!entry->SetVendorId(vendor_id)) {
[email protected]4bf0a52d2011-03-04 01:09:05288 LOG(WARNING) << "Malformed vendor_id entry " << entry->id();
[email protected]2efc31182010-12-11 21:07:18289 return NULL;
290 }
[email protected]005d0cf2011-05-31 18:13:53291 dictionary_entry_count++;
[email protected]2efc31182010-12-11 21:07:18292 }
293
[email protected]4bf0a52d2011-03-04 01:09:05294 ListValue* device_id_list;
295 if (value->GetList("device_id", &device_id_list)) {
296 for (size_t i = 0; i < device_id_list->GetSize(); ++i) {
297 std::string device_id;
298 if (!device_id_list->GetString(i, &device_id) ||
299 !entry->AddDeviceId(device_id)) {
300 LOG(WARNING) << "Malformed device_id entry " << entry->id();
301 return NULL;
302 }
[email protected]2efc31182010-12-11 21:07:18303 }
[email protected]005d0cf2011-05-31 18:13:53304 dictionary_entry_count++;
[email protected]2efc31182010-12-11 21:07:18305 }
306
[email protected]61ce18f2011-01-25 17:16:10307 DictionaryValue* driver_vendor_value = NULL;
308 if (value->GetDictionary("driver_vendor", &driver_vendor_value)) {
309 std::string vendor_op;
310 std::string vendor_value;
311 driver_vendor_value->GetString("op", &vendor_op);
312 driver_vendor_value->GetString("value", &vendor_value);
313 if (!entry->SetDriverVendorInfo(vendor_op, vendor_value)) {
[email protected]f055be712011-03-23 21:18:27314 LOG(WARNING) << "Malformed driver_vendor entry " << entry->id();
[email protected]61ce18f2011-01-25 17:16:10315 return NULL;
316 }
[email protected]005d0cf2011-05-31 18:13:53317 dictionary_entry_count++;
[email protected]61ce18f2011-01-25 17:16:10318 }
319
[email protected]2efc31182010-12-11 21:07:18320 DictionaryValue* driver_version_value = NULL;
321 if (value->GetDictionary("driver_version", &driver_version_value)) {
322 std::string driver_version_op = "any";
323 std::string driver_version_string;
324 std::string driver_version_string2;
325 driver_version_value->GetString("op", &driver_version_op);
326 driver_version_value->GetString("number", &driver_version_string);
327 driver_version_value->GetString("number2", &driver_version_string2);
328 if (!entry->SetDriverVersionInfo(driver_version_op, driver_version_string,
329 driver_version_string2)) {
[email protected]f055be712011-03-23 21:18:27330 LOG(WARNING) << "Malformed driver_version entry " << entry->id();
[email protected]2efc31182010-12-11 21:07:18331 return NULL;
332 }
[email protected]005d0cf2011-05-31 18:13:53333 dictionary_entry_count++;
[email protected]2efc31182010-12-11 21:07:18334 }
335
[email protected]f0221ea2011-03-01 22:09:49336 DictionaryValue* driver_date_value = NULL;
337 if (value->GetDictionary("driver_date", &driver_date_value)) {
338 std::string driver_date_op = "any";
339 std::string driver_date_string;
340 std::string driver_date_string2;
341 driver_date_value->GetString("op", &driver_date_op);
342 driver_date_value->GetString("number", &driver_date_string);
343 driver_date_value->GetString("number2", &driver_date_string2);
344 if (!entry->SetDriverDateInfo(driver_date_op, driver_date_string,
345 driver_date_string2)) {
[email protected]f055be712011-03-23 21:18:27346 LOG(WARNING) << "Malformed driver_date entry " << entry->id();
[email protected]f0221ea2011-03-01 22:09:49347 return NULL;
348 }
[email protected]005d0cf2011-05-31 18:13:53349 dictionary_entry_count++;
[email protected]f0221ea2011-03-01 22:09:49350 }
351
[email protected]916b977f2011-09-04 02:50:38352 DictionaryValue* gl_vendor_value = NULL;
353 if (value->GetDictionary("gl_vendor", &gl_vendor_value)) {
354 std::string vendor_op;
355 std::string vendor_value;
356 gl_vendor_value->GetString("op", &vendor_op);
357 gl_vendor_value->GetString("value", &vendor_value);
358 if (!entry->SetGLVendorInfo(vendor_op, vendor_value)) {
359 LOG(WARNING) << "Malformed gl_vendor entry " << entry->id();
360 return NULL;
361 }
362 dictionary_entry_count++;
363 }
364
[email protected]61ce18f2011-01-25 17:16:10365 DictionaryValue* gl_renderer_value = NULL;
366 if (value->GetDictionary("gl_renderer", &gl_renderer_value)) {
367 std::string renderer_op;
368 std::string renderer_value;
369 gl_renderer_value->GetString("op", &renderer_op);
370 gl_renderer_value->GetString("value", &renderer_value);
371 if (!entry->SetGLRendererInfo(renderer_op, renderer_value)) {
[email protected]4bf0a52d2011-03-04 01:09:05372 LOG(WARNING) << "Malformed gl_renderer entry " << entry->id();
[email protected]61ce18f2011-01-25 17:16:10373 return NULL;
374 }
[email protected]005d0cf2011-05-31 18:13:53375 dictionary_entry_count++;
[email protected]61ce18f2011-01-25 17:16:10376 }
377
[email protected]88a9e7842011-03-01 16:48:39378 if (top_level) {
379 ListValue* blacklist_value = NULL;
380 if (!value->GetList("blacklist", &blacklist_value)) {
[email protected]4bf0a52d2011-03-04 01:09:05381 LOG(WARNING) << "Malformed blacklist entry " << entry->id();
[email protected]88a9e7842011-03-01 16:48:39382 return NULL;
383 }
384 std::vector<std::string> blacklist;
385 for (size_t i = 0; i < blacklist_value->GetSize(); ++i) {
386 std::string feature;
387 if (blacklist_value->GetString(i, &feature)) {
388 blacklist.push_back(feature);
389 } else {
[email protected]4bf0a52d2011-03-04 01:09:05390 LOG(WARNING) << "Malformed blacklist entry " << entry->id();
[email protected]88a9e7842011-03-01 16:48:39391 return NULL;
392 }
393 }
394 if (!entry->SetBlacklistedFeatures(blacklist)) {
[email protected]4bf0a52d2011-03-04 01:09:05395 LOG(WARNING) << "Malformed blacklist entry " << entry->id();
[email protected]2efc31182010-12-11 21:07:18396 return NULL;
397 }
[email protected]005d0cf2011-05-31 18:13:53398 dictionary_entry_count++;
[email protected]2efc31182010-12-11 21:07:18399 }
[email protected]88a9e7842011-03-01 16:48:39400
401 if (top_level) {
402 ListValue* exception_list_value = NULL;
403 if (value->GetList("exceptions", &exception_list_value)) {
404 for (size_t i = 0; i < exception_list_value->GetSize(); ++i) {
405 DictionaryValue* exception_value = NULL;
[email protected]4bf0a52d2011-03-04 01:09:05406 if (!exception_list_value->GetDictionary(i, &exception_value)) {
407 LOG(WARNING) << "Malformed exceptions entry " << entry->id();
408 return NULL;
409 }
[email protected]7f2f3512011-08-25 01:27:54410 ScopedGpuBlacklistEntry exception(
411 GetGpuBlacklistEntryFromValue(exception_value, false));
[email protected]4bf0a52d2011-03-04 01:09:05412 if (exception == NULL) {
413 LOG(WARNING) << "Malformed exceptions entry " << entry->id();
414 return NULL;
415 }
[email protected]7f2f3512011-08-25 01:27:54416 if (exception->contains_unknown_fields_) {
417 LOG(WARNING) << "Exception with unknown fields " << entry->id();
418 entry->contains_unknown_fields_ = true;
419 } else {
420 entry->AddException(exception);
421 }
[email protected]88a9e7842011-03-01 16:48:39422 }
[email protected]005d0cf2011-05-31 18:13:53423 dictionary_entry_count++;
[email protected]88a9e7842011-03-01 16:48:39424 }
[email protected]005d0cf2011-05-31 18:13:53425
426 DictionaryValue* browser_version_value = NULL;
427 // browser_version is processed in LoadGpuBlacklist().
428 if (value->GetDictionary("browser_version", &browser_version_value))
429 dictionary_entry_count++;
[email protected]2efc31182010-12-11 21:07:18430 }
431
[email protected]916b977f2011-09-04 02:50:38432 ListValue* channel_list_value = NULL;
433 if (value->GetList("browser_channels", &channel_list_value)) {
434 for (size_t i = 0; i < channel_list_value->GetSize(); ++i) {
435 std::string channel_value;
436 if (!channel_list_value->GetString(i, &channel_value)) {
437 LOG(WARNING) << "Malformed browser_channels entry " << entry->id();
438 return NULL;
439 }
440 BrowserChannel channel = StringToBrowserChannel(channel_value);
441 if (channel == kUnknown) {
442 LOG(WARNING) << "Malformed browser_channels entry " << entry->id();
443 return NULL;
444 }
445 entry->AddBrowserChannel(channel);
446 }
447 dictionary_entry_count++;
448 }
449
[email protected]005d0cf2011-05-31 18:13:53450 if (value->size() != dictionary_entry_count) {
[email protected]7f2f3512011-08-25 01:27:54451 LOG(WARNING) << "Entry with unknown fields " << entry->id();
452 entry->contains_unknown_fields_ = true;
[email protected]005d0cf2011-05-31 18:13:53453 }
[email protected]863d5662011-08-25 23:15:10454 return entry;
[email protected]2efc31182010-12-11 21:07:18455}
456
457GpuBlacklist::GpuBlacklistEntry::GpuBlacklistEntry()
[email protected]65708af2011-01-29 02:30:27458 : id_(0),
[email protected]7f2f3512011-08-25 01:27:54459 vendor_id_(0),
460 contains_unknown_fields_(false),
461 contains_unknown_features_(false) {
[email protected]2efc31182010-12-11 21:07:18462}
463
[email protected]4bf0a52d2011-03-04 01:09:05464bool GpuBlacklist::GpuBlacklistEntry::SetId(uint32 id) {
465 if (id != 0) {
466 id_ = id;
[email protected]61ce18f2011-01-25 17:16:10467 return true;
468 }
469 return false;
470}
471
[email protected]2efc31182010-12-11 21:07:18472bool GpuBlacklist::GpuBlacklistEntry::SetOsInfo(
473 const std::string& os,
474 const std::string& version_op,
475 const std::string& version_string,
476 const std::string& version_string2) {
477 os_info_.reset(new OsInfo(os, version_op, version_string, version_string2));
478 return os_info_->IsValid();
479}
480
481bool GpuBlacklist::GpuBlacklistEntry::SetVendorId(
482 const std::string& vendor_id_string) {
483 vendor_id_ = 0;
484 return base::HexStringToInt(vendor_id_string,
485 reinterpret_cast<int*>(&vendor_id_));
486}
487
[email protected]4bf0a52d2011-03-04 01:09:05488bool GpuBlacklist::GpuBlacklistEntry::AddDeviceId(
[email protected]2efc31182010-12-11 21:07:18489 const std::string& device_id_string) {
[email protected]4bf0a52d2011-03-04 01:09:05490 uint32 device_id = 0;
491 if (base::HexStringToInt(device_id_string,
492 reinterpret_cast<int*>(&device_id))) {
493 device_id_list_.push_back(device_id);
494 return true;
495 }
496 return false;
[email protected]2efc31182010-12-11 21:07:18497}
498
[email protected]61ce18f2011-01-25 17:16:10499bool GpuBlacklist::GpuBlacklistEntry::SetDriverVendorInfo(
500 const std::string& vendor_op,
501 const std::string& vendor_value) {
502 driver_vendor_info_.reset(
503 new StringInfo(vendor_op, vendor_value));
504 return driver_vendor_info_->IsValid();
505}
506
[email protected]2efc31182010-12-11 21:07:18507bool GpuBlacklist::GpuBlacklistEntry::SetDriverVersionInfo(
508 const std::string& version_op,
509 const std::string& version_string,
510 const std::string& version_string2) {
511 driver_version_info_.reset(
512 new VersionInfo(version_op, version_string, version_string2));
513 return driver_version_info_->IsValid();
514}
515
[email protected]f0221ea2011-03-01 22:09:49516bool GpuBlacklist::GpuBlacklistEntry::SetDriverDateInfo(
517 const std::string& date_op,
518 const std::string& date_string,
519 const std::string& date_string2) {
520 driver_date_info_.reset(
521 new VersionInfo(date_op, date_string, date_string2));
522 return driver_date_info_->IsValid();
523}
524
[email protected]916b977f2011-09-04 02:50:38525bool GpuBlacklist::GpuBlacklistEntry::SetGLVendorInfo(
526 const std::string& vendor_op,
527 const std::string& vendor_value) {
528 gl_vendor_info_.reset(
529 new StringInfo(vendor_op, vendor_value));
530 return gl_vendor_info_->IsValid();
531}
532
[email protected]61ce18f2011-01-25 17:16:10533bool GpuBlacklist::GpuBlacklistEntry::SetGLRendererInfo(
534 const std::string& renderer_op,
535 const std::string& renderer_value) {
536 gl_renderer_info_.reset(
537 new StringInfo(renderer_op, renderer_value));
538 return gl_renderer_info_->IsValid();
539}
540
[email protected]2efc31182010-12-11 21:07:18541bool GpuBlacklist::GpuBlacklistEntry::SetBlacklistedFeatures(
542 const std::vector<std::string>& blacklisted_features) {
543 size_t size = blacklisted_features.size();
544 if (size == 0)
545 return false;
546 uint32 flags = 0;
547 for (size_t i = 0; i < size; ++i) {
548 GpuFeatureFlags::GpuFeatureType type =
549 GpuFeatureFlags::StringToGpuFeatureType(blacklisted_features[i]);
550 switch (type) {
551 case GpuFeatureFlags::kGpuFeatureAccelerated2dCanvas:
552 case GpuFeatureFlags::kGpuFeatureAcceleratedCompositing:
553 case GpuFeatureFlags::kGpuFeatureWebgl:
[email protected]4bf0a52d2011-03-04 01:09:05554 case GpuFeatureFlags::kGpuFeatureMultisampling:
[email protected]2efc31182010-12-11 21:07:18555 case GpuFeatureFlags::kGpuFeatureAll:
556 flags |= type;
557 break;
558 case GpuFeatureFlags::kGpuFeatureUnknown:
[email protected]7f2f3512011-08-25 01:27:54559 contains_unknown_features_ = true;
560 break;
[email protected]2efc31182010-12-11 21:07:18561 }
562 }
563 feature_flags_.reset(new GpuFeatureFlags());
564 feature_flags_->set_flags(flags);
565 return true;
566}
567
[email protected]88a9e7842011-03-01 16:48:39568void GpuBlacklist::GpuBlacklistEntry::AddException(
[email protected]863d5662011-08-25 23:15:10569 ScopedGpuBlacklistEntry exception) {
[email protected]88a9e7842011-03-01 16:48:39570 exceptions_.push_back(exception);
571}
572
[email protected]916b977f2011-09-04 02:50:38573void GpuBlacklist::GpuBlacklistEntry::AddBrowserChannel(
574 BrowserChannel channel) {
575 DCHECK(channel != kUnknown);
576 browser_channels_.push_back(channel);
577}
578
[email protected]2efc31182010-12-11 21:07:18579bool GpuBlacklist::GpuBlacklistEntry::Contains(
[email protected]916b977f2011-09-04 02:50:38580 OsType os_type, const Version& os_version, BrowserChannel channel,
581 const GPUInfo& gpu_info) const {
[email protected]2efc31182010-12-11 21:07:18582 DCHECK(os_type != kOsAny);
583 if (os_info_.get() != NULL && !os_info_->Contains(os_type, os_version))
584 return false;
[email protected]a61508e52011-03-08 17:59:42585 if (vendor_id_ != 0 && vendor_id_ != gpu_info.vendor_id)
[email protected]2efc31182010-12-11 21:07:18586 return false;
[email protected]4bf0a52d2011-03-04 01:09:05587 if (device_id_list_.size() > 0) {
588 bool found = false;
589 for (size_t i = 0; i < device_id_list_.size(); ++i) {
[email protected]a61508e52011-03-08 17:59:42590 if (device_id_list_[i] == gpu_info.device_id) {
[email protected]4bf0a52d2011-03-04 01:09:05591 found = true;
592 break;
593 }
594 }
595 if (!found)
596 return false;
597 }
[email protected]61ce18f2011-01-25 17:16:10598 if (driver_vendor_info_.get() != NULL &&
[email protected]a61508e52011-03-08 17:59:42599 !driver_vendor_info_->Contains(gpu_info.driver_vendor))
[email protected]61ce18f2011-01-25 17:16:10600 return false;
[email protected]079c4ad2011-02-19 00:05:57601 if (driver_version_info_.get() != NULL) {
602 scoped_ptr<Version> driver_version(
[email protected]a61508e52011-03-08 17:59:42603 Version::GetVersionFromString(gpu_info.driver_version));
[email protected]079c4ad2011-02-19 00:05:57604 if (driver_version.get() == NULL ||
605 !driver_version_info_->Contains(*driver_version))
606 return false;
607 }
[email protected]f0221ea2011-03-01 22:09:49608 if (driver_date_info_.get() != NULL) {
[email protected]a61508e52011-03-08 17:59:42609 scoped_ptr<Version> driver_date(GetDateFromString(gpu_info.driver_date));
[email protected]f0221ea2011-03-01 22:09:49610 if (driver_date.get() == NULL ||
611 !driver_date_info_->Contains(*driver_date))
612 return false;
613 }
[email protected]916b977f2011-09-04 02:50:38614 if (gl_vendor_info_.get() != NULL &&
615 !gl_vendor_info_->Contains(gpu_info.gl_vendor))
616 return false;
[email protected]61ce18f2011-01-25 17:16:10617 if (gl_renderer_info_.get() != NULL &&
[email protected]a61508e52011-03-08 17:59:42618 !gl_renderer_info_->Contains(gpu_info.gl_renderer))
[email protected]61ce18f2011-01-25 17:16:10619 return false;
[email protected]88a9e7842011-03-01 16:48:39620 for (size_t i = 0; i < exceptions_.size(); ++i) {
[email protected]916b977f2011-09-04 02:50:38621 if (exceptions_[i]->Contains(os_type, os_version, channel, gpu_info))
622 return false;
[email protected]88a9e7842011-03-01 16:48:39623 }
[email protected]916b977f2011-09-04 02:50:38624 bool rt = true;
625 if (browser_channels_.size() > 0) {
626 rt = false;
627 for (size_t i = 0; i < browser_channels_.size(); ++i) {
628 if (browser_channels_[i] == channel) {
629 rt = true;
630 break;
631 }
632 }
633 }
634 return rt;
[email protected]2efc31182010-12-11 21:07:18635}
636
637GpuBlacklist::OsType GpuBlacklist::GpuBlacklistEntry::GetOsType() const {
638 if (os_info_.get() == NULL)
[email protected]fa269952011-02-12 20:23:11639 return kOsAny;
[email protected]2efc31182010-12-11 21:07:18640 return os_info_->type();
641}
642
[email protected]61ce18f2011-01-25 17:16:10643uint32 GpuBlacklist::GpuBlacklistEntry::id() const {
644 return id_;
645}
646
[email protected]2efc31182010-12-11 21:07:18647GpuFeatureFlags GpuBlacklist::GpuBlacklistEntry::GetGpuFeatureFlags() const {
648 return *feature_flags_;
649}
650
[email protected]916b977f2011-09-04 02:50:38651GpuBlacklist::GpuBlacklist(const std::string& browser_info_string)
[email protected]7f2f3512011-08-25 01:27:54652 : max_entry_id_(0),
653 contains_unknown_fields_(false) {
[email protected]916b977f2011-09-04 02:50:38654 SetBrowserInfo(browser_info_string);
[email protected]2efc31182010-12-11 21:07:18655}
656
657GpuBlacklist::~GpuBlacklist() {
658 Clear();
659}
660
[email protected]7f2f3512011-08-25 01:27:54661bool GpuBlacklist::LoadGpuBlacklist(
662 const std::string& json_context, GpuBlacklist::OsFilter os_filter) {
[email protected]2efc31182010-12-11 21:07:18663 scoped_ptr<Value> root;
664 root.reset(base::JSONReader::Read(json_context, false));
665 if (root.get() == NULL || !root->IsType(Value::TYPE_DICTIONARY))
666 return false;
667
[email protected]61ce18f2011-01-25 17:16:10668 DictionaryValue* root_dictionary = static_cast<DictionaryValue*>(root.get());
669 DCHECK(root_dictionary);
[email protected]7f2f3512011-08-25 01:27:54670 return LoadGpuBlacklist(*root_dictionary, os_filter);
[email protected]bb4bf9d72011-02-26 02:37:38671}
672
[email protected]7f2f3512011-08-25 01:27:54673bool GpuBlacklist::LoadGpuBlacklist(
674 const DictionaryValue& parsed_json, GpuBlacklist::OsFilter os_filter) {
675 std::vector<ScopedGpuBlacklistEntry> entries;
[email protected]bb4bf9d72011-02-26 02:37:38676
[email protected]61ce18f2011-01-25 17:16:10677 std::string version_string;
[email protected]bb4bf9d72011-02-26 02:37:38678 parsed_json.GetString("version", &version_string);
[email protected]61ce18f2011-01-25 17:16:10679 version_.reset(Version::GetVersionFromString(version_string));
680 if (version_.get() == NULL)
681 return false;
682
[email protected]2efc31182010-12-11 21:07:18683 ListValue* list = NULL;
[email protected]49090b62011-03-11 03:38:06684 if (!parsed_json.GetList("entries", &list))
[email protected]2efc31182010-12-11 21:07:18685 return false;
686
[email protected]61ce18f2011-01-25 17:16:10687 uint32 max_entry_id = 0;
[email protected]7f2f3512011-08-25 01:27:54688 bool contains_unknown_fields = false;
[email protected]2efc31182010-12-11 21:07:18689 for (size_t i = 0; i < list->GetSize(); ++i) {
690 DictionaryValue* list_item = NULL;
691 bool valid = list->GetDictionary(i, &list_item);
[email protected]7f2f3512011-08-25 01:27:54692 if (!valid || list_item == NULL)
693 return false;
[email protected]c6540e22011-04-06 16:23:49694 // Check browser version compatibility: if the entry is not for the
695 // current browser version, don't process it.
696 BrowserVersionSupport browser_version_support =
697 IsEntrySupportedByCurrentBrowserVersion(list_item);
698 if (browser_version_support == kMalformed)
[email protected]7f2f3512011-08-25 01:27:54699 return false;
700 if (browser_version_support == kUnsupported)
[email protected]c6540e22011-04-06 16:23:49701 continue;
[email protected]c6540e22011-04-06 16:23:49702 DCHECK(browser_version_support == kSupported);
[email protected]7f2f3512011-08-25 01:27:54703 ScopedGpuBlacklistEntry entry(
704 GpuBlacklistEntry::GetGpuBlacklistEntryFromValue(list_item, true));
[email protected]2efc31182010-12-11 21:07:18705 if (entry == NULL)
[email protected]7f2f3512011-08-25 01:27:54706 return false;
[email protected]61ce18f2011-01-25 17:16:10707 if (entry->id() > max_entry_id)
708 max_entry_id = entry->id();
[email protected]7f2f3512011-08-25 01:27:54709 // If an unknown field is encountered, skip the entry; if an unknown
710 // feature is encountered, ignore the feature, but keep the entry.
711 if (entry->contains_unknown_fields()) {
712 contains_unknown_fields = true;
713 continue;
714 }
715 if (entry->contains_unknown_features())
716 contains_unknown_fields = true;
[email protected]2efc31182010-12-11 21:07:18717 entries.push_back(entry);
718 }
719
[email protected]2efc31182010-12-11 21:07:18720 Clear();
[email protected]7f2f3512011-08-25 01:27:54721 OsType my_os = GetOsType();
722 for (size_t i = 0; i < entries.size(); ++i) {
723 OsType entry_os = entries[i]->GetOsType();
724 if (os_filter == GpuBlacklist::kAllOs ||
725 entry_os == kOsAny || entry_os == my_os)
726 blacklist_.push_back(entries[i]);
[email protected]2efc31182010-12-11 21:07:18727 }
[email protected]61ce18f2011-01-25 17:16:10728 max_entry_id_ = max_entry_id;
[email protected]7f2f3512011-08-25 01:27:54729 contains_unknown_fields_ = contains_unknown_fields;
[email protected]2efc31182010-12-11 21:07:18730 return true;
731}
732
733GpuFeatureFlags GpuBlacklist::DetermineGpuFeatureFlags(
734 GpuBlacklist::OsType os,
735 Version* os_version,
[email protected]61ce18f2011-01-25 17:16:10736 const GPUInfo& gpu_info) {
737 active_entries_.clear();
[email protected]2efc31182010-12-11 21:07:18738 GpuFeatureFlags flags;
[email protected]2efc31182010-12-11 21:07:18739
740 if (os == kOsAny)
741 os = GetOsType();
742 scoped_ptr<Version> my_os_version;
743 if (os_version == NULL) {
[email protected]6e001bb2011-05-25 20:53:18744 std::string version_string = base::SysInfo::OperatingSystemVersion();
[email protected]7004d7eb2011-01-21 00:27:53745 size_t pos = version_string.find_first_not_of("0123456789.");
746 if (pos != std::string::npos)
747 version_string = version_string.substr(0, pos);
[email protected]2efc31182010-12-11 21:07:18748 my_os_version.reset(Version::GetVersionFromString(version_string));
749 os_version = my_os_version.get();
750 }
751 DCHECK(os_version != NULL);
752
753 for (size_t i = 0; i < blacklist_.size(); ++i) {
[email protected]916b977f2011-09-04 02:50:38754 if (blacklist_[i]->Contains(os, *os_version, browser_channel_, gpu_info)) {
[email protected]2efc31182010-12-11 21:07:18755 flags.Combine(blacklist_[i]->GetGpuFeatureFlags());
[email protected]61ce18f2011-01-25 17:16:10756 active_entries_.push_back(blacklist_[i]);
[email protected]2efc31182010-12-11 21:07:18757 }
758 }
759 return flags;
760}
761
[email protected]61ce18f2011-01-25 17:16:10762void GpuBlacklist::GetGpuFeatureFlagEntries(
763 GpuFeatureFlags::GpuFeatureType feature,
764 std::vector<uint32>& entry_ids) const {
765 entry_ids.clear();
766 for (size_t i = 0; i < active_entries_.size(); ++i) {
767 if ((feature & active_entries_[i]->GetGpuFeatureFlags().flags()) != 0)
768 entry_ids.push_back(active_entries_[i]->id());
769 }
770}
771
[email protected]198b50072011-04-18 17:00:45772bool GpuBlacklist::IsFeatureBlacklisted(
773 GpuFeatureFlags::GpuFeatureType feature) const
774{
775 for (size_t i = 0; i < active_entries_.size(); ++i) {
776 if (active_entries_[i]->GetGpuFeatureFlags().flags() & feature)
777 return true;
778 }
779 return false;
780}
781
[email protected]7a133252011-04-12 18:17:40782Value* GpuBlacklist::GetFeatureStatus(bool gpu_access_allowed,
783 bool disable_accelerated_compositing,
[email protected]206f3f02011-06-13 14:59:25784 bool disable_accelerated_2D_canvas,
[email protected]7a133252011-04-12 18:17:40785 bool disable_experimental_webgl,
786 bool disable_multisampling) const {
787 DictionaryValue* status = new DictionaryValue();
[email protected]47847e9c2011-03-03 01:17:41788
[email protected]198b50072011-04-18 17:00:45789 // Build the feature_status field.
[email protected]7a133252011-04-12 18:17:40790 {
791 ListValue* feature_status_list = new ListValue();
[email protected]47847e9c2011-03-03 01:17:41792
[email protected]198b50072011-04-18 17:00:45793 // 2d_canvas.
794 if (!gpu_access_allowed) {
[email protected]206f3f02011-06-13 14:59:25795 if (disable_accelerated_2D_canvas)
[email protected]95ef1cf2011-06-10 00:39:53796 feature_status_list->Append(NewStatusValue("2d_canvas",
797 "software"));
[email protected]206f3f02011-06-13 14:59:25798 else
799 feature_status_list->Append(NewStatusValue("2d_canvas",
800 "unavailable_software"));
801 } else if (!disable_accelerated_2D_canvas) {
[email protected]198b50072011-04-18 17:00:45802 if (IsFeatureBlacklisted(
803 GpuFeatureFlags::kGpuFeatureAccelerated2dCanvas))
804 feature_status_list->Append(NewStatusValue("2d_canvas",
805 "unavailable_software"));
[email protected]ac8c1c32011-08-02 04:10:43806 else if (disable_accelerated_compositing)
807 feature_status_list->Append(NewStatusValue("2d_canvas",
808 "disabled_software"));
[email protected]198b50072011-04-18 17:00:45809 else
810 feature_status_list->Append(NewStatusValue("2d_canvas",
811 "enabled"));
812 } else {
813 feature_status_list->Append(NewStatusValue("2d_canvas",
814 "software"));
[email protected]7a133252011-04-12 18:17:40815 }
[email protected]198b50072011-04-18 17:00:45816
817 // 3d css and compositing.
818 if (!gpu_access_allowed) {
819 feature_status_list->Append(NewStatusValue("3d_css",
820 "unavailable_off"));
821 feature_status_list->Append(NewStatusValue("compositing",
822 "unavailable_software"));
823 } else if (disable_accelerated_compositing) {
824 feature_status_list->Append(NewStatusValue("3d_css",
825 "unavailable_off"));
826 feature_status_list->Append(NewStatusValue("compositing",
827 "disabled_software"));
828 } else if (IsFeatureBlacklisted(
829 GpuFeatureFlags::kGpuFeatureAcceleratedCompositing)) {
830 feature_status_list->Append(NewStatusValue("3d_css",
831 "unavailable_off"));
832 feature_status_list->Append(NewStatusValue("compositing",
833 "disabled_software"));
834 } else {
835 feature_status_list->Append(NewStatusValue("3d_css",
836 "enabled"));
837 feature_status_list->Append(NewStatusValue("compositing",
838 "enabled"));
839 }
840
841 // webgl
842 if (!gpu_access_allowed)
843 feature_status_list->Append(NewStatusValue("webgl",
844 "unavailable_off"));
845 else if (disable_experimental_webgl)
846 feature_status_list->Append(NewStatusValue("webgl",
847 "disabled_off"));
848 else if (IsFeatureBlacklisted(
849 GpuFeatureFlags::kGpuFeatureWebgl))
850 feature_status_list->Append(NewStatusValue("webgl",
851 "unavailable_off"));
[email protected]ac8c1c32011-08-02 04:10:43852 else if (disable_accelerated_compositing)
853 feature_status_list->Append(NewStatusValue("webgl",
854 "enabled_readback"));
[email protected]198b50072011-04-18 17:00:45855 else
856 feature_status_list->Append(NewStatusValue("webgl",
857 "enabled"));
858
859 // multisampling
860 if (!gpu_access_allowed)
861 feature_status_list->Append(NewStatusValue("multisampling",
862 "unavailable_off"));
[email protected]206f3f02011-06-13 14:59:25863 else if (disable_multisampling)
[email protected]198b50072011-04-18 17:00:45864 feature_status_list->Append(NewStatusValue("multisampling",
865 "disabled_off"));
866 else if (IsFeatureBlacklisted(
867 GpuFeatureFlags::kGpuFeatureMultisampling))
868 feature_status_list->Append(NewStatusValue("multisampling",
869 "disabled_off"));
870 else
871 feature_status_list->Append(NewStatusValue("multisampling",
872 "enabled"));
873
[email protected]7a133252011-04-12 18:17:40874 status->Set("featureStatus", feature_status_list);
[email protected]47847e9c2011-03-03 01:17:41875 }
[email protected]7a133252011-04-12 18:17:40876
[email protected]198b50072011-04-18 17:00:45877 // Build the problems list.
[email protected]7a133252011-04-12 18:17:40878 {
879 ListValue* problem_list = new ListValue();
[email protected]206f3f02011-06-13 14:59:25880 if (!gpu_access_allowed) {
[email protected]7a133252011-04-12 18:17:40881 DictionaryValue* problem = new DictionaryValue();
882 problem->SetString("description",
883 "GPU process was unable to boot. Access to GPU disallowed.");
884 problem->Set("crBugs", new ListValue());
885 problem->Set("webkitBugs", new ListValue());
886 problem_list->Append(problem);
887 }
[email protected]206f3f02011-06-13 14:59:25888 if (disable_accelerated_2D_canvas) {
[email protected]7a133252011-04-12 18:17:40889 DictionaryValue* problem = new DictionaryValue();
890 problem->SetString("description",
[email protected]206f3f02011-06-13 14:59:25891 "Accelerated 2D canvas has been disabled at the command line");
[email protected]7a133252011-04-12 18:17:40892 problem->Set("crBugs", new ListValue());
893 problem->Set("webkitBugs", new ListValue());
894 problem_list->Append(problem);
895 }
[email protected]206f3f02011-06-13 14:59:25896 if (disable_accelerated_compositing) {
[email protected]7a133252011-04-12 18:17:40897 DictionaryValue* problem = new DictionaryValue();
898 problem->SetString("description",
899 "Accelerated compositing has been disabled, either via about:flags "
[email protected]ac8c1c32011-08-02 04:10:43900 "or command line. This adversely affects performance of all hardware "
901 " accelerated features.");
[email protected]7a133252011-04-12 18:17:40902 problem->Set("crBugs", new ListValue());
903 problem->Set("webkitBugs", new ListValue());
904 problem_list->Append(problem);
905 }
[email protected]206f3f02011-06-13 14:59:25906 if (disable_experimental_webgl) {
[email protected]7a133252011-04-12 18:17:40907 DictionaryValue* problem = new DictionaryValue();
908 problem->SetString("description",
909 "WebGL has been disabled, either via about:flags "
910 "or command line");
911 problem->Set("crBugs", new ListValue());
912 problem->Set("webkitBugs", new ListValue());
913 problem_list->Append(problem);
914 }
[email protected]206f3f02011-06-13 14:59:25915 if (disable_multisampling) {
[email protected]7a133252011-04-12 18:17:40916 DictionaryValue* problem = new DictionaryValue();
917 problem->SetString("description",
918 "Multisampling has been disabled, either via about:flags "
919 "or command line");
920 problem->Set("crBugs", new ListValue());
921 problem->Set("webkitBugs", new ListValue());
922 problem_list->Append(problem);
923 }
924 for (size_t i = 0; i < active_entries_.size(); ++i) {
[email protected]7f2f3512011-08-25 01:27:54925 ScopedGpuBlacklistEntry entry = active_entries_[i];
[email protected]7a133252011-04-12 18:17:40926 DictionaryValue* problem = new DictionaryValue();
927
928 problem->SetString("description", entry->description());
929
930 ListValue* cr_bugs = new ListValue();
931 for (size_t j = 0; j < entry->cr_bugs().size(); ++j)
932 cr_bugs->Append(Value::CreateIntegerValue(
933 entry->cr_bugs()[j]));
934 problem->Set("crBugs", cr_bugs);
935
936 ListValue* webkit_bugs = new ListValue();
937 for (size_t j = 0; j < entry->webkit_bugs().size(); ++j)
938 webkit_bugs->Append(Value::CreateIntegerValue(
939 entry->webkit_bugs()[j]));
940 problem->Set("webkitBugs", webkit_bugs);
941
942 problem_list->Append(problem);
943 }
944 status->Set("problems", problem_list);
945 }
946 return status;
[email protected]47847e9c2011-03-03 01:17:41947}
948
[email protected]7f2f3512011-08-25 01:27:54949size_t GpuBlacklist::num_entries() const {
950 return blacklist_.size();
951}
952
[email protected]61ce18f2011-01-25 17:16:10953uint32 GpuBlacklist::max_entry_id() const {
954 return max_entry_id_;
955}
956
957bool GpuBlacklist::GetVersion(uint16* major, uint16* minor) const {
958 DCHECK(major && minor);
959 *major = 0;
960 *minor = 0;
961 if (version_.get() == NULL)
962 return false;
963 const std::vector<uint16>& components_reference = version_->components();
964 if (components_reference.size() != 2)
965 return false;
966 *major = components_reference[0];
967 *minor = components_reference[1];
968 return true;
969}
970
[email protected]bb4bf9d72011-02-26 02:37:38971bool GpuBlacklist::GetVersion(
972 const DictionaryValue& parsed_json, uint16* major, uint16* minor) {
973 DCHECK(major && minor);
974 *major = 0;
975 *minor = 0;
976 std::string version_string;
977 if (!parsed_json.GetString("version", &version_string))
978 return false;
979 scoped_ptr<Version> version(Version::GetVersionFromString(version_string));
980 if (version.get() == NULL)
981 return false;
982 const std::vector<uint16>& components_reference = version->components();
983 if (components_reference.size() != 2)
984 return false;
985 *major = components_reference[0];
986 *minor = components_reference[1];
987 return true;
988}
989
[email protected]2efc31182010-12-11 21:07:18990GpuBlacklist::OsType GpuBlacklist::GetOsType() {
[email protected]f0db0ee2011-03-22 21:42:42991#if defined(OS_CHROMEOS)
[email protected]f0db0ee2011-03-22 21:42:42992 return kOsChromeOS;
993#elif defined(OS_WIN)
[email protected]2efc31182010-12-11 21:07:18994 return kOsWin;
995#elif defined(OS_LINUX)
996 return kOsLinux;
997#elif defined(OS_MACOSX)
998 return kOsMacosx;
999#else
1000 return kOsUnknown;
1001#endif
1002}
1003
1004void GpuBlacklist::Clear() {
[email protected]2efc31182010-12-11 21:07:181005 blacklist_.clear();
[email protected]61ce18f2011-01-25 17:16:101006 active_entries_.clear();
[email protected]7f2f3512011-08-25 01:27:541007 max_entry_id_ = 0;
1008 contains_unknown_fields_ = false;
[email protected]2efc31182010-12-11 21:07:181009}
[email protected]c6540e22011-04-06 16:23:491010
1011GpuBlacklist::BrowserVersionSupport
1012GpuBlacklist::IsEntrySupportedByCurrentBrowserVersion(
1013 DictionaryValue* value) {
1014 DCHECK(value);
1015 DictionaryValue* browser_version_value = NULL;
1016 if (value->GetDictionary("browser_version", &browser_version_value)) {
1017 std::string version_op = "any";
1018 std::string version_string;
1019 std::string version_string2;
1020 browser_version_value->GetString("op", &version_op);
1021 browser_version_value->GetString("number", &version_string);
1022 browser_version_value->GetString("number2", &version_string2);
1023 scoped_ptr<VersionInfo> browser_version_info;
1024 browser_version_info.reset(
1025 new VersionInfo(version_op, version_string, version_string2));
1026 if (!browser_version_info->IsValid())
1027 return kMalformed;
1028 if (browser_version_info->Contains(*browser_version_))
1029 return kSupported;
1030 return kUnsupported;
1031 }
1032 return kSupported;
1033}
[email protected]916b977f2011-09-04 02:50:381034
1035void GpuBlacklist::SetBrowserInfo(const std::string& browser_info_string) {
1036 std::vector<std::string> pieces;
1037 base::SplitString(browser_info_string, ' ', &pieces);
1038 if (pieces.size() != 2) {
1039 pieces.resize(2);
1040 pieces[0] = "0";
1041 pieces[1] = "unknown";
1042 }
1043
1044 browser_version_.reset(Version::GetVersionFromString(pieces[0]));
1045 DCHECK(browser_version_.get() != NULL);
1046
1047 browser_channel_ = StringToBrowserChannel(pieces[1]);
1048}
1049
1050// static
1051GpuBlacklist::BrowserChannel GpuBlacklist::StringToBrowserChannel(
1052 const std::string& value) {
1053 if (value == "stable")
1054 return kStable;
1055 if (value == "beta")
1056 return kBeta;
1057 if (value == "dev")
1058 return kDev;
1059 if (value == "canary")
1060 return kCanary;
1061 return kUnknown;
1062}
1063