OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/web_resource/gpu_blacklist_updater.h" | |
6 | |
7 #include "base/bind.h" | |
8 #include "base/command_line.h" | |
9 #include "base/logging.h" | |
10 #include "base/values.h" | |
11 #include "chrome/browser/browser_process.h" | |
12 #include "chrome/browser/prefs/pref_service.h" | |
13 #include "chrome/browser/prefs/scoped_user_pref_update.h" | |
14 #include "chrome/browser/profiles/profile.h" | |
15 #include "chrome/browser/profiles/profile_manager.h" | |
16 #include "chrome/common/chrome_notification_types.h" | |
17 #include "chrome/common/chrome_version_info.h" | |
18 #include "chrome/common/pref_names.h" | |
19 #include "content/browser/gpu/gpu_blacklist.h" | |
20 #include "content/browser/gpu/gpu_data_manager.h" | |
21 #include "content/public/browser/browser_thread.h" | |
22 #include "content/public/common/content_switches.h" | |
23 #include "grit/browser_resources.h" | |
24 #include "ui/base/resource/resource_bundle.h" | |
25 #include "ui/gfx/gl/gl_implementation.h" | |
26 #include "ui/gfx/gl/gl_switches.h" | |
27 | |
28 using content::BrowserThread; | |
29 | |
30 namespace { | |
31 | |
32 // Delay on first fetch so we don't interfere with startup. | |
33 static const int kStartGpuBlacklistFetchDelay = 6000; | |
34 | |
35 // Delay between calls to update the gpu blacklist (48 hours). | |
36 static const int kCacheUpdateDelay = 48 * 60 * 60 * 1000; | |
37 | |
38 std::string GetChromeVersionString() { | |
39 chrome::VersionInfo version_info; | |
40 return version_info.is_valid() ? version_info.Version() : "0"; | |
41 } | |
42 | |
43 } // namespace anonymous | |
44 | |
45 const char* GpuBlacklistUpdater::kDefaultGpuBlacklistURL = | |
46 "https://ssl.gstatic.com/chrome/config/software_rendering_list.json"; | |
47 | |
48 GpuBlacklistUpdater::GpuBlacklistUpdater() | |
49 : WebResourceService(g_browser_process->local_state(), | |
50 GpuBlacklistUpdater::kDefaultGpuBlacklistURL, | |
51 false, // don't append locale to URL | |
52 chrome::NOTIFICATION_CHROME_END, | |
53 prefs::kGpuBlacklistUpdate, | |
54 kStartGpuBlacklistFetchDelay, | |
55 kCacheUpdateDelay) { | |
56 prefs_->RegisterDictionaryPref(prefs::kGpuBlacklist); | |
57 InitializeGpuBlacklist(); | |
58 } | |
59 | |
60 GpuBlacklistUpdater::~GpuBlacklistUpdater() { } | |
61 | |
62 // static | |
63 void GpuBlacklistUpdater::Setup() { | |
64 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
65 | |
66 // Initialize GpuDataManager instance, which collects preliminary | |
67 // graphics information. | |
68 GpuDataManager::GetInstance(); | |
69 | |
70 // Skip auto updates in tests. | |
71 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | |
72 if (command_line.HasSwitch(switches::kSkipGpuDataLoading)) | |
73 return; | |
74 | |
75 // Initialize GpuBlacklistUpdater, which loads the current blacklist; | |
76 // then Schedule a GPU blacklist auto update. | |
77 GpuBlacklistUpdater* updater = | |
78 g_browser_process->gpu_blacklist_updater(); | |
79 DCHECK(updater); | |
80 } | |
81 | |
82 void GpuBlacklistUpdater::Unpack(const DictionaryValue& parsed_json) { | |
83 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
84 prefs_->Set(prefs::kGpuBlacklist, parsed_json); | |
85 UpdateGpuBlacklist(parsed_json, false); | |
86 } | |
87 | |
88 void GpuBlacklistUpdater::InitializeGpuBlacklist() { | |
89 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
90 | |
91 // We first load it from the browser resources. | |
92 const base::StringPiece gpu_blacklist_json( | |
93 ResourceBundle::GetSharedInstance().GetRawDataResource( | |
94 IDR_GPU_BLACKLIST)); | |
95 GpuBlacklist* built_in_list = new GpuBlacklist(GetChromeVersionString()); | |
96 bool succeed = built_in_list->LoadGpuBlacklist( | |
97 gpu_blacklist_json.as_string(), GpuBlacklist::kCurrentOsOnly); | |
98 DCHECK(succeed); | |
99 GpuDataManager::GetInstance()->SetBuiltInGpuBlacklist(built_in_list); | |
100 | |
101 // Then we check if the cached version is more up-to-date. | |
102 const DictionaryValue* gpu_blacklist_cache = | |
103 prefs_->GetDictionary(prefs::kGpuBlacklist); | |
104 DCHECK(gpu_blacklist_cache); | |
105 UpdateGpuBlacklist(*gpu_blacklist_cache, true); | |
106 } | |
107 | |
108 void GpuBlacklistUpdater::UpdateGpuBlacklist( | |
109 const DictionaryValue& gpu_blacklist_cache, bool preliminary) { | |
110 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
111 | |
112 scoped_ptr<GpuBlacklist> gpu_blacklist( | |
113 new GpuBlacklist(GetChromeVersionString())); | |
114 bool success = gpu_blacklist->LoadGpuBlacklist( | |
115 gpu_blacklist_cache, GpuBlacklist::kCurrentOsOnly); | |
116 if (success) { | |
117 GpuDataManager::GetInstance()->UpdateGpuBlacklist( | |
118 gpu_blacklist.release(), preliminary); | |
119 } | |
120 } | |
OLD | NEW |