| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "content/browser/gpu/gpu_blacklist.h" | 5 #include "content/browser/gpu/gpu_blacklist.h" |
| 6 | 6 |
| 7 #include "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
| 10 #include "base/string_piece.h" | 10 #include "base/string_piece.h" |
| (...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 } | 420 } |
| 421 dictionary_entry_count++; | 421 dictionary_entry_count++; |
| 422 } | 422 } |
| 423 | 423 |
| 424 DictionaryValue* browser_version_value = NULL; | 424 DictionaryValue* browser_version_value = NULL; |
| 425 // browser_version is processed in LoadGpuBlacklist(). | 425 // browser_version is processed in LoadGpuBlacklist(). |
| 426 if (value->GetDictionary("browser_version", &browser_version_value)) | 426 if (value->GetDictionary("browser_version", &browser_version_value)) |
| 427 dictionary_entry_count++; | 427 dictionary_entry_count++; |
| 428 } | 428 } |
| 429 | 429 |
| 430 ListValue* channel_list_value = NULL; | |
| 431 if (value->GetList("browser_channels", &channel_list_value)) { | |
| 432 for (size_t i = 0; i < channel_list_value->GetSize(); ++i) { | |
| 433 std::string channel_value; | |
| 434 if (!channel_list_value->GetString(i, &channel_value)) { | |
| 435 LOG(WARNING) << "Malformed browser_channels entry " << entry->id(); | |
| 436 return NULL; | |
| 437 } | |
| 438 BrowserChannel channel = StringToBrowserChannel(channel_value); | |
| 439 if (channel == kUnknown) { | |
| 440 LOG(WARNING) << "Malformed browser_channels entry " << entry->id(); | |
| 441 return NULL; | |
| 442 } | |
| 443 entry->AddBrowserChannel(channel); | |
| 444 } | |
| 445 dictionary_entry_count++; | |
| 446 } | |
| 447 | |
| 448 if (value->size() != dictionary_entry_count) { | 430 if (value->size() != dictionary_entry_count) { |
| 449 LOG(WARNING) << "Entry with unknown fields " << entry->id(); | 431 LOG(WARNING) << "Entry with unknown fields " << entry->id(); |
| 450 entry->contains_unknown_fields_ = true; | 432 entry->contains_unknown_fields_ = true; |
| 451 } | 433 } |
| 452 return entry; | 434 return entry; |
| 453 } | 435 } |
| 454 | 436 |
| 455 GpuBlacklist::GpuBlacklistEntry::GpuBlacklistEntry() | 437 GpuBlacklist::GpuBlacklistEntry::GpuBlacklistEntry() |
| 456 : id_(0), | 438 : id_(0), |
| 457 disabled_(false), | 439 disabled_(false), |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 566 feature_flags_.reset(new GpuFeatureFlags()); | 548 feature_flags_.reset(new GpuFeatureFlags()); |
| 567 feature_flags_->set_flags(flags); | 549 feature_flags_->set_flags(flags); |
| 568 return true; | 550 return true; |
| 569 } | 551 } |
| 570 | 552 |
| 571 void GpuBlacklist::GpuBlacklistEntry::AddException( | 553 void GpuBlacklist::GpuBlacklistEntry::AddException( |
| 572 ScopedGpuBlacklistEntry exception) { | 554 ScopedGpuBlacklistEntry exception) { |
| 573 exceptions_.push_back(exception); | 555 exceptions_.push_back(exception); |
| 574 } | 556 } |
| 575 | 557 |
| 576 void GpuBlacklist::GpuBlacklistEntry::AddBrowserChannel( | |
| 577 BrowserChannel channel) { | |
| 578 DCHECK(channel != kUnknown); | |
| 579 browser_channels_.push_back(channel); | |
| 580 } | |
| 581 | |
| 582 bool GpuBlacklist::GpuBlacklistEntry::Contains( | 558 bool GpuBlacklist::GpuBlacklistEntry::Contains( |
| 583 OsType os_type, const Version& os_version, BrowserChannel channel, | 559 OsType os_type, const Version& os_version, |
| 584 const content::GPUInfo& gpu_info) const { | 560 const content::GPUInfo& gpu_info) const { |
| 585 DCHECK(os_type != kOsAny); | 561 DCHECK(os_type != kOsAny); |
| 586 if (os_info_.get() != NULL && !os_info_->Contains(os_type, os_version)) | 562 if (os_info_.get() != NULL && !os_info_->Contains(os_type, os_version)) |
| 587 return false; | 563 return false; |
| 588 if (vendor_id_ != 0 && vendor_id_ != gpu_info.vendor_id) | 564 if (vendor_id_ != 0 && vendor_id_ != gpu_info.vendor_id) |
| 589 return false; | 565 return false; |
| 590 if (device_id_list_.size() > 0) { | 566 if (device_id_list_.size() > 0) { |
| 591 bool found = false; | 567 bool found = false; |
| 592 for (size_t i = 0; i < device_id_list_.size(); ++i) { | 568 for (size_t i = 0; i < device_id_list_.size(); ++i) { |
| 593 if (device_id_list_[i] == gpu_info.device_id) { | 569 if (device_id_list_[i] == gpu_info.device_id) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 614 !driver_date_info_->Contains(*driver_date)) | 590 !driver_date_info_->Contains(*driver_date)) |
| 615 return false; | 591 return false; |
| 616 } | 592 } |
| 617 if (gl_vendor_info_.get() != NULL && | 593 if (gl_vendor_info_.get() != NULL && |
| 618 !gl_vendor_info_->Contains(gpu_info.gl_vendor)) | 594 !gl_vendor_info_->Contains(gpu_info.gl_vendor)) |
| 619 return false; | 595 return false; |
| 620 if (gl_renderer_info_.get() != NULL && | 596 if (gl_renderer_info_.get() != NULL && |
| 621 !gl_renderer_info_->Contains(gpu_info.gl_renderer)) | 597 !gl_renderer_info_->Contains(gpu_info.gl_renderer)) |
| 622 return false; | 598 return false; |
| 623 for (size_t i = 0; i < exceptions_.size(); ++i) { | 599 for (size_t i = 0; i < exceptions_.size(); ++i) { |
| 624 if (exceptions_[i]->Contains(os_type, os_version, channel, gpu_info)) | 600 if (exceptions_[i]->Contains(os_type, os_version, gpu_info)) |
| 625 return false; | 601 return false; |
| 626 } | 602 } |
| 627 bool rt = true; | 603 return true; |
| 628 if (browser_channels_.size() > 0) { | |
| 629 rt = false; | |
| 630 for (size_t i = 0; i < browser_channels_.size(); ++i) { | |
| 631 if (browser_channels_[i] == channel) { | |
| 632 rt = true; | |
| 633 break; | |
| 634 } | |
| 635 } | |
| 636 } | |
| 637 return rt; | |
| 638 } | 604 } |
| 639 | 605 |
| 640 GpuBlacklist::OsType GpuBlacklist::GpuBlacklistEntry::GetOsType() const { | 606 GpuBlacklist::OsType GpuBlacklist::GpuBlacklistEntry::GetOsType() const { |
| 641 if (os_info_.get() == NULL) | 607 if (os_info_.get() == NULL) |
| 642 return kOsAny; | 608 return kOsAny; |
| 643 return os_info_->type(); | 609 return os_info_->type(); |
| 644 } | 610 } |
| 645 | 611 |
| 646 uint32 GpuBlacklist::GpuBlacklistEntry::id() const { | 612 uint32 GpuBlacklist::GpuBlacklistEntry::id() const { |
| 647 return id_; | 613 return id_; |
| 648 } | 614 } |
| 649 | 615 |
| 650 bool GpuBlacklist::GpuBlacklistEntry::disabled() const { | 616 bool GpuBlacklist::GpuBlacklistEntry::disabled() const { |
| 651 return disabled_; | 617 return disabled_; |
| 652 } | 618 } |
| 653 | 619 |
| 654 GpuFeatureFlags GpuBlacklist::GpuBlacklistEntry::GetGpuFeatureFlags() const { | 620 GpuFeatureFlags GpuBlacklist::GpuBlacklistEntry::GetGpuFeatureFlags() const { |
| 655 return *feature_flags_; | 621 return *feature_flags_; |
| 656 } | 622 } |
| 657 | 623 |
| 658 GpuBlacklist::GpuBlacklist(const std::string& browser_info_string) | 624 GpuBlacklist::GpuBlacklist(const std::string& browser_version_string) |
| 659 : max_entry_id_(0), | 625 : max_entry_id_(0), |
| 660 contains_unknown_fields_(false) { | 626 contains_unknown_fields_(false) { |
| 661 SetBrowserInfo(browser_info_string); | 627 SetBrowserVersion(browser_version_string); |
| 662 } | 628 } |
| 663 | 629 |
| 664 GpuBlacklist::~GpuBlacklist() { | 630 GpuBlacklist::~GpuBlacklist() { |
| 665 Clear(); | 631 Clear(); |
| 666 } | 632 } |
| 667 | 633 |
| 668 bool GpuBlacklist::LoadGpuBlacklist( | 634 bool GpuBlacklist::LoadGpuBlacklist( |
| 669 const std::string& json_context, GpuBlacklist::OsFilter os_filter) { | 635 const std::string& json_context, GpuBlacklist::OsFilter os_filter) { |
| 670 scoped_ptr<Value> root; | 636 scoped_ptr<Value> root; |
| 671 root.reset(base::JSONReader::Read(json_context, false)); | 637 root.reset(base::JSONReader::Read(json_context, false)); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 751 std::string version_string = base::SysInfo::OperatingSystemVersion(); | 717 std::string version_string = base::SysInfo::OperatingSystemVersion(); |
| 752 size_t pos = version_string.find_first_not_of("0123456789."); | 718 size_t pos = version_string.find_first_not_of("0123456789."); |
| 753 if (pos != std::string::npos) | 719 if (pos != std::string::npos) |
| 754 version_string = version_string.substr(0, pos); | 720 version_string = version_string.substr(0, pos); |
| 755 my_os_version.reset(Version::GetVersionFromString(version_string)); | 721 my_os_version.reset(Version::GetVersionFromString(version_string)); |
| 756 os_version = my_os_version.get(); | 722 os_version = my_os_version.get(); |
| 757 } | 723 } |
| 758 DCHECK(os_version != NULL); | 724 DCHECK(os_version != NULL); |
| 759 | 725 |
| 760 for (size_t i = 0; i < blacklist_.size(); ++i) { | 726 for (size_t i = 0; i < blacklist_.size(); ++i) { |
| 761 if (blacklist_[i]->Contains(os, *os_version, browser_channel_, gpu_info)) { | 727 if (blacklist_[i]->Contains(os, *os_version, gpu_info)) { |
| 762 if (!blacklist_[i]->disabled()) | 728 if (!blacklist_[i]->disabled()) |
| 763 flags.Combine(blacklist_[i]->GetGpuFeatureFlags()); | 729 flags.Combine(blacklist_[i]->GetGpuFeatureFlags()); |
| 764 active_entries_.push_back(blacklist_[i]); | 730 active_entries_.push_back(blacklist_[i]); |
| 765 } | 731 } |
| 766 } | 732 } |
| 767 return flags; | 733 return flags; |
| 768 } | 734 } |
| 769 | 735 |
| 770 void GpuBlacklist::GetGpuFeatureFlagEntries( | 736 void GpuBlacklist::GetGpuFeatureFlagEntries( |
| 771 GpuFeatureFlags::GpuFeatureType feature, | 737 GpuFeatureFlags::GpuFeatureType feature, |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 884 new VersionInfo(version_op, version_string, version_string2)); | 850 new VersionInfo(version_op, version_string, version_string2)); |
| 885 if (!browser_version_info->IsValid()) | 851 if (!browser_version_info->IsValid()) |
| 886 return kMalformed; | 852 return kMalformed; |
| 887 if (browser_version_info->Contains(*browser_version_)) | 853 if (browser_version_info->Contains(*browser_version_)) |
| 888 return kSupported; | 854 return kSupported; |
| 889 return kUnsupported; | 855 return kUnsupported; |
| 890 } | 856 } |
| 891 return kSupported; | 857 return kSupported; |
| 892 } | 858 } |
| 893 | 859 |
| 894 void GpuBlacklist::SetBrowserInfo(const std::string& browser_info_string) { | 860 void GpuBlacklist::SetBrowserVersion(const std::string& version_string) { |
| 895 std::vector<std::string> pieces; | 861 browser_version_.reset(Version::GetVersionFromString(version_string)); |
| 896 base::SplitString(browser_info_string, ' ', &pieces); | |
| 897 if (pieces.size() != 2) { | |
| 898 pieces.resize(2); | |
| 899 pieces[0] = "0"; | |
| 900 pieces[1] = "unknown"; | |
| 901 } | |
| 902 | |
| 903 browser_version_.reset(Version::GetVersionFromString(pieces[0])); | |
| 904 DCHECK(browser_version_.get() != NULL); | 862 DCHECK(browser_version_.get() != NULL); |
| 905 | |
| 906 browser_channel_ = StringToBrowserChannel(pieces[1]); | |
| 907 } | 863 } |
| 908 | 864 |
| 909 // static | |
| 910 GpuBlacklist::BrowserChannel GpuBlacklist::StringToBrowserChannel( | |
| 911 const std::string& value) { | |
| 912 if (value == "stable") | |
| 913 return kStable; | |
| 914 if (value == "beta") | |
| 915 return kBeta; | |
| 916 if (value == "dev") | |
| 917 return kDev; | |
| 918 if (value == "canary") | |
| 919 return kCanary; | |
| 920 return kUnknown; | |
| 921 } | |
| 922 | |
| OLD | NEW |