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.
5 #include "chrome/browser/gpu/gpu_mode_manager.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"
16 using base::UserMetricsAction
;
20 bool GetPreviousGpuModePref() {
21 PrefService
* service
= g_browser_process
->local_state();
23 return service
->GetBoolean(prefs::kHardwareAccelerationModePrevious
);
26 void SetPreviousGpuModePref(bool enabled
) {
27 PrefService
* service
= g_browser_process
->local_state();
29 service
->SetBoolean(prefs::kHardwareAccelerationModePrevious
, enabled
);
32 } // namespace anonymous
35 void GpuModeManager::RegisterPrefs(PrefRegistrySimple
* registry
) {
36 registry
->RegisterBooleanPref(
37 prefs::kHardwareAccelerationModeEnabled
, true);
38 registry
->RegisterBooleanPref(
39 prefs::kHardwareAccelerationModePrevious
, true);
42 GpuModeManager::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
49 prefs::kHardwareAccelerationModeEnabled
,
50 base::Bind(&base::DoNothing
));
52 initial_gpu_mode_pref_
= IsGpuModePrefEnabled();
53 bool previous_gpu_mode_pref
= GetPreviousGpuModePref();
54 SetPreviousGpuModePref(initial_gpu_mode_pref_
);
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"));
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();
72 GpuModeManager::~GpuModeManager() {
75 bool GpuModeManager::initial_gpu_mode_pref() const {
76 return initial_gpu_mode_pref_
;
80 bool GpuModeManager::IsGpuModePrefEnabled() {
81 PrefService
* service
= g_browser_process
->local_state();
83 return service
->GetBoolean(
84 prefs::kHardwareAccelerationModeEnabled
);