OLD | NEW |
| (Empty) |
1 // Copyright 2016 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 "blimp/client/core/settings/settings.h" | |
6 | |
7 #include "base/bind.h" | |
8 #include "base/command_line.h" | |
9 #include "blimp/client/core/settings/settings_observer.h" | |
10 #include "blimp/client/core/settings/settings_prefs.h" | |
11 #include "blimp/client/core/switches/blimp_client_switches.h" | |
12 #include "components/prefs/pref_registry_simple.h" | |
13 | |
14 namespace blimp { | |
15 namespace client { | |
16 namespace { | |
17 | |
18 const CommandLinePrefStore::BooleanSwitchToPreferenceMapEntry | |
19 boolean_switch_map[] = { | |
20 {blimp::switches::kEnableBlimp, prefs::kBlimpEnabled, true}, | |
21 {blimp::switches::kDownloadWholeDocument, prefs::kRecordWholeDocument, | |
22 true}, | |
23 }; | |
24 | |
25 } // namespace | |
26 | |
27 Settings::Settings(PrefService* local_state) | |
28 : local_state_(local_state), show_network_stats_(false) { | |
29 pref_change_registrar_.Init(local_state); | |
30 pref_change_registrar_.Add( | |
31 prefs::kBlimpEnabled, | |
32 base::Bind(&Settings::OnPreferenceChanged, base::Unretained(this), | |
33 local_state, prefs::kBlimpEnabled)); | |
34 pref_change_registrar_.Add( | |
35 prefs::kRecordWholeDocument, | |
36 base::Bind(&Settings::OnPreferenceChanged, base::Unretained(this), | |
37 local_state, prefs::kRecordWholeDocument)); | |
38 } | |
39 | |
40 Settings::~Settings() = default; | |
41 | |
42 void Settings::AddObserver(SettingsObserver* observer) { | |
43 observers_.AddObserver(observer); | |
44 } | |
45 | |
46 void Settings::RemoveObserver(SettingsObserver* observer) { | |
47 observers_.RemoveObserver(observer); | |
48 } | |
49 | |
50 void Settings::SetShowNetworkStats(bool enable) { | |
51 if (show_network_stats_ == enable) | |
52 return; | |
53 | |
54 show_network_stats_ = enable; | |
55 for (auto& observer : observers_) | |
56 observer.OnShowNetworkStatsChanged(show_network_stats_); | |
57 } | |
58 | |
59 void Settings::SetEnableBlimpMode(bool enable) { | |
60 local_state_->SetBoolean(prefs::kBlimpEnabled, enable); | |
61 } | |
62 | |
63 void Settings::SetRecordWholeDocument(bool enable) { | |
64 local_state_->SetBoolean(prefs::kRecordWholeDocument, enable); | |
65 } | |
66 | |
67 void Settings::OnPreferenceChanged(PrefService* service, | |
68 const std::string& pref_name) { | |
69 if (pref_name == prefs::kBlimpEnabled) { | |
70 for (auto& observer : observers_) { | |
71 observer.OnBlimpModeEnabled(service->GetBoolean(pref_name)); | |
72 observer.OnRestartRequired(); | |
73 } | |
74 } else if (pref_name == prefs::kRecordWholeDocument) { | |
75 for (auto& observer : observers_) | |
76 observer.OnRecordWholeDocumentChanged(service->GetBoolean(pref_name)); | |
77 } | |
78 } | |
79 | |
80 bool Settings::IsBlimpEnabled() { | |
81 return local_state_->GetBoolean(prefs::kBlimpEnabled); | |
82 } | |
83 | |
84 bool Settings::IsRecordWholeDocument() { | |
85 return local_state_->GetBoolean(prefs::kRecordWholeDocument); | |
86 } | |
87 | |
88 // static | |
89 void Settings::RegisterPrefs(PrefRegistrySimple* registry) { | |
90 registry->RegisterBooleanPref(prefs::kBlimpEnabled, false); | |
91 registry->RegisterBooleanPref(prefs::kRecordWholeDocument, false); | |
92 } | |
93 | |
94 // static | |
95 void Settings::ApplyBlimpSwitches(CommandLinePrefStore* store) { | |
96 store->ApplyBooleanSwitches(boolean_switch_map, | |
97 arraysize(boolean_switch_map)); | |
98 } | |
99 | |
100 } // namespace client | |
101 } // namespace blimp | |
OLD | NEW |