| 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 "chrome/browser/web_resource/gpu_blacklist_updater.h" | 5 #include "chrome/browser/web_resource/gpu_blacklist_updater.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 | 29 |
| 30 namespace { | 30 namespace { |
| 31 | 31 |
| 32 // Delay on first fetch so we don't interfere with startup. | 32 // Delay on first fetch so we don't interfere with startup. |
| 33 static const int kStartGpuBlacklistFetchDelay = 6000; | 33 static const int kStartGpuBlacklistFetchDelay = 6000; |
| 34 | 34 |
| 35 // Delay between calls to update the gpu blacklist (48 hours). | 35 // Delay between calls to update the gpu blacklist (48 hours). |
| 36 static const int kCacheUpdateDelay = 48 * 60 * 60 * 1000; | 36 static const int kCacheUpdateDelay = 48 * 60 * 60 * 1000; |
| 37 | 37 |
| 38 std::string GetChromeVersionString() { | 38 std::string GetChromeVersionString() { |
| 39 CR_DEFINE_STATIC_LOCAL(std::string, cr_version, ()); | |
| 40 if (!cr_version.empty()) | |
| 41 return cr_version; | |
| 42 chrome::VersionInfo version_info; | 39 chrome::VersionInfo version_info; |
| 43 cr_version = version_info.is_valid() ? version_info.Version() : "0"; | 40 return version_info.is_valid() ? version_info.Version() : "0"; |
| 44 switch (version_info.GetChannel()) { | |
| 45 case chrome::VersionInfo::CHANNEL_STABLE: | |
| 46 cr_version += " stable"; | |
| 47 break; | |
| 48 case chrome::VersionInfo::CHANNEL_BETA: | |
| 49 cr_version += " beta"; | |
| 50 break; | |
| 51 case chrome::VersionInfo::CHANNEL_DEV: | |
| 52 cr_version += " dev"; | |
| 53 break; | |
| 54 case chrome::VersionInfo::CHANNEL_CANARY: | |
| 55 cr_version += " canary"; | |
| 56 break; | |
| 57 default: | |
| 58 cr_version += " unknown"; | |
| 59 break; | |
| 60 } | |
| 61 return cr_version; | |
| 62 } | 41 } |
| 63 | 42 |
| 64 } // namespace anonymous | 43 } // namespace anonymous |
| 65 | 44 |
| 66 const char* GpuBlacklistUpdater::kDefaultGpuBlacklistURL = | 45 const char* GpuBlacklistUpdater::kDefaultGpuBlacklistURL = |
| 67 "https://ssl.gstatic.com/chrome/config/software_rendering_list.json"; | 46 "https://ssl.gstatic.com/chrome/config/software_rendering_list.json"; |
| 68 | 47 |
| 69 GpuBlacklistUpdater::GpuBlacklistUpdater() | 48 GpuBlacklistUpdater::GpuBlacklistUpdater() |
| 70 : WebResourceService(g_browser_process->local_state(), | 49 : WebResourceService(g_browser_process->local_state(), |
| 71 GpuBlacklistUpdater::kDefaultGpuBlacklistURL, | 50 GpuBlacklistUpdater::kDefaultGpuBlacklistURL, |
| 72 false, // don't append locale to URL | 51 false, // don't append locale to URL |
| 73 chrome::NOTIFICATION_CHROME_END, | 52 chrome::NOTIFICATION_CHROME_END, |
| 74 prefs::kGpuBlacklistUpdate, | 53 prefs::kGpuBlacklistUpdate, |
| 75 kStartGpuBlacklistFetchDelay, | 54 kStartGpuBlacklistFetchDelay, |
| 76 kCacheUpdateDelay) { | 55 kCacheUpdateDelay) { |
| 77 prefs_->RegisterDictionaryPref(prefs::kGpuBlacklist); | 56 prefs_->RegisterDictionaryPref(prefs::kGpuBlacklist); |
| 78 InitializeGpuBlacklist(); | 57 InitializeGpuBlacklist(); |
| 79 } | 58 } |
| 80 | 59 |
| 81 GpuBlacklistUpdater::~GpuBlacklistUpdater() { } | 60 GpuBlacklistUpdater::~GpuBlacklistUpdater() { } |
| 82 | 61 |
| 83 // static | 62 // static |
| 84 void GpuBlacklistUpdater::SetupOnFileThread() { | 63 void GpuBlacklistUpdater::Setup() { |
| 85 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 64 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 86 | 65 |
| 87 // Initialize GpuDataManager instance, which collects preliminary | 66 // Initialize GpuDataManager instance, which collects preliminary |
| 88 // graphics information. This has to happen on FILE thread. | 67 // graphics information. |
| 89 GpuDataManager::GetInstance(); | 68 GpuDataManager::GetInstance(); |
| 90 | 69 |
| 91 // Cache the chrome version string. This has to happen on FILE thread | |
| 92 // because of chrome::VersionInfo::GetChannel(). | |
| 93 GetChromeVersionString(); | |
| 94 | |
| 95 // Skip auto updates in tests. | 70 // Skip auto updates in tests. |
| 96 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 71 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 97 if (command_line.HasSwitch(switches::kSkipGpuDataLoading)) | 72 if (command_line.HasSwitch(switches::kSkipGpuDataLoading)) |
| 98 return; | 73 return; |
| 99 | 74 |
| 100 // Post GpuBlacklistUpdate task on UI thread. This has to happen | |
| 101 // after GpuDataManager is initialized, otherwise it might be | |
| 102 // initialzed on UI thread. | |
| 103 BrowserThread::PostTask( | |
| 104 BrowserThread::UI, FROM_HERE, | |
| 105 base::Bind(&GpuBlacklistUpdater::SetupOnUIThread)); | |
| 106 } | |
| 107 | |
| 108 // static | |
| 109 void GpuBlacklistUpdater::SetupOnUIThread() { | |
| 110 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 111 | |
| 112 // Initialize GpuBlacklistUpdater, which loads the current blacklist; | 75 // Initialize GpuBlacklistUpdater, which loads the current blacklist; |
| 113 // then Schedule a GPU blacklist auto update. | 76 // then Schedule a GPU blacklist auto update. |
| 114 GpuBlacklistUpdater* updater = | 77 GpuBlacklistUpdater* updater = |
| 115 g_browser_process->gpu_blacklist_updater(); | 78 g_browser_process->gpu_blacklist_updater(); |
| 116 DCHECK(updater); | 79 DCHECK(updater); |
| 117 } | 80 } |
| 118 | 81 |
| 119 void GpuBlacklistUpdater::Unpack(const DictionaryValue& parsed_json) { | 82 void GpuBlacklistUpdater::Unpack(const DictionaryValue& parsed_json) { |
| 120 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 83 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 121 prefs_->Set(prefs::kGpuBlacklist, parsed_json); | 84 prefs_->Set(prefs::kGpuBlacklist, parsed_json); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 148 | 111 |
| 149 scoped_ptr<GpuBlacklist> gpu_blacklist( | 112 scoped_ptr<GpuBlacklist> gpu_blacklist( |
| 150 new GpuBlacklist(GetChromeVersionString())); | 113 new GpuBlacklist(GetChromeVersionString())); |
| 151 bool success = gpu_blacklist->LoadGpuBlacklist( | 114 bool success = gpu_blacklist->LoadGpuBlacklist( |
| 152 gpu_blacklist_cache, GpuBlacklist::kCurrentOsOnly); | 115 gpu_blacklist_cache, GpuBlacklist::kCurrentOsOnly); |
| 153 if (success) { | 116 if (success) { |
| 154 GpuDataManager::GetInstance()->UpdateGpuBlacklist( | 117 GpuDataManager::GetInstance()->UpdateGpuBlacklist( |
| 155 gpu_blacklist.release(), preliminary); | 118 gpu_blacklist.release(), preliminary); |
| 156 } | 119 } |
| 157 } | 120 } |
| OLD | NEW |