1 // Copyright (c) 2013 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/gpu/gpu_mode_manager.h" 6 7 #include "base/bind.h" 8 #include "base/metrics/histogram.h" 9 #include "base/prefs/pref_registry_simple.h" 10 #include "base/prefs/pref_service.h" 11 #include "chrome/browser/browser_process.h" 12 #include "chrome/common/pref_names.h" 13 #include "content/public/browser/gpu_data_manager.h" 14 #include "content/public/browser/user_metrics.h" 15 16 using content::UserMetricsAction; 17 18 namespace { 19 GetPreviousGpuModePref()20bool GetPreviousGpuModePref() { 21 PrefService* service = g_browser_process->local_state(); 22 DCHECK(service); 23 return service->GetBoolean(prefs::kHardwareAccelerationModePrevious); 24 } 25 SetPreviousGpuModePref(bool enabled)26void SetPreviousGpuModePref(bool enabled) { 27 PrefService* service = g_browser_process->local_state(); 28 DCHECK(service); 29 service->SetBoolean(prefs::kHardwareAccelerationModePrevious, enabled); 30 } 31 32 } // namespace anonymous 33 34 // static RegisterPrefs(PrefRegistrySimple * registry)35void GpuModeManager::RegisterPrefs(PrefRegistrySimple* registry) { 36 registry->RegisterBooleanPref( 37 prefs::kHardwareAccelerationModeEnabled, true); 38 registry->RegisterBooleanPref( 39 prefs::kHardwareAccelerationModePrevious, true); 40 } 41 GpuModeManager()42GpuModeManager::GpuModeManager() 43 : initial_gpu_mode_pref_(true) { 44 if (g_browser_process->local_state()) { // Skip for unit tests 45 pref_registrar_.Init(g_browser_process->local_state()); 46 // Do nothing when the pref changes. It takes effect after 47 // chrome restarts. 48 pref_registrar_.Add( 49 prefs::kHardwareAccelerationModeEnabled, 50 base::Bind(&base::DoNothing)); 51 52 initial_gpu_mode_pref_ = IsGpuModePrefEnabled(); 53 bool previous_gpu_mode_pref = GetPreviousGpuModePref(); 54 SetPreviousGpuModePref(initial_gpu_mode_pref_); 55 56 UMA_HISTOGRAM_BOOLEAN("GPU.HardwareAccelerationModeEnabled", 57 initial_gpu_mode_pref_); 58 if (previous_gpu_mode_pref && !initial_gpu_mode_pref_) 59 content::RecordAction(UserMetricsAction("GpuAccelerationDisabled")); 60 if (!previous_gpu_mode_pref && initial_gpu_mode_pref_) 61 content::RecordAction(UserMetricsAction("GpuAccelerationEnabled")); 62 63 if (!initial_gpu_mode_pref_) { 64 content::GpuDataManager* gpu_data_manager = 65 content::GpuDataManager::GetInstance(); 66 DCHECK(gpu_data_manager); 67 gpu_data_manager->DisableHardwareAcceleration(); 68 } 69 } 70 } 71 ~GpuModeManager()72GpuModeManager::~GpuModeManager() { 73 } 74 initial_gpu_mode_pref() const75bool GpuModeManager::initial_gpu_mode_pref() const { 76 return initial_gpu_mode_pref_; 77 } 78 79 // static IsGpuModePrefEnabled()80bool GpuModeManager::IsGpuModePrefEnabled() { 81 PrefService* service = g_browser_process->local_state(); 82 DCHECK(service); 83 return service->GetBoolean( 84 prefs::kHardwareAccelerationModeEnabled); 85 } 86 87