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