Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(118)

Side by Side Diff: blimp/client/core/settings/settings.cc

Issue 2349073002: Blimp Settings framework on the c++ side (Closed)
Patch Set: nits and sync to head Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « blimp/client/core/settings/settings.h ('k') | blimp/client/core/settings/settings_feature.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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
17 const CommandLinePrefStore::BooleanSwitchToPreferenceMapEntry
18 boolean_switch_map[] = {
19 {blimp::switches::kEnableBlimp, prefs::kBlimpEnabled, true},
20 {blimp::switches::kDownloadWholeDocument, prefs::kRecordWholeDocument,
21 true},
22 };
23
24 Settings::Settings(PrefService* local_state)
25 : local_state_(local_state), show_network_stats_(false) {
26 pref_change_registrar_.Init(local_state);
27 pref_change_registrar_.Add(
28 prefs::kBlimpEnabled,
29 base::Bind(&Settings::OnPreferenceChanged, base::Unretained(this),
30 local_state, prefs::kBlimpEnabled));
31 pref_change_registrar_.Add(
32 prefs::kRecordWholeDocument,
33 base::Bind(&Settings::OnPreferenceChanged, base::Unretained(this),
34 local_state, prefs::kRecordWholeDocument));
35 }
36
37 Settings::~Settings() = default;
38
39 void Settings::AddObserver(SettingsObserver* observer) {
40 observers_.AddObserver(observer);
41 }
42
43 void Settings::RemoveObserver(SettingsObserver* observer) {
44 observers_.RemoveObserver(observer);
45 }
46
47 void Settings::SetShowNetworkStats(bool enable) {
48 if (show_network_stats_ == enable)
49 return;
50
51 show_network_stats_ = enable;
52 for (auto& observer : observers_)
53 observer.OnShowNetworkStatsChanged(show_network_stats_);
54 }
55
56 void Settings::SetEnableBlimpMode(bool enable) {
57 local_state_->SetBoolean(prefs::kBlimpEnabled, enable);
58 }
59
60 void Settings::SetRecordWholeDocument(bool enable) {
61 local_state_->SetBoolean(prefs::kRecordWholeDocument, enable);
62 }
63
64 void Settings::OnPreferenceChanged(PrefService* service,
65 const std::string& pref_name) {
66 if (pref_name == prefs::kBlimpEnabled) {
67 for (auto& observer : observers_) {
68 observer.OnBlimpModeEnabled(service->GetBoolean(pref_name));
69 observer.OnRestartRequired();
70 }
71 } else if (pref_name == prefs::kRecordWholeDocument) {
72 for (auto& observer : observers_)
73 observer.OnRecordWholeDocumentChanged(service->GetBoolean(pref_name));
74 }
75 }
76
77 bool Settings::IsBlimpEnabled() {
78 return local_state_->GetBoolean(prefs::kBlimpEnabled);
79 }
80
81 bool Settings::IsRecordWholeDocument() {
82 return local_state_->GetBoolean(prefs::kRecordWholeDocument);
83 }
84
85 // static
86 void Settings::RegisterPrefs(PrefRegistrySimple* registry) {
87 registry->RegisterBooleanPref(prefs::kBlimpEnabled, false);
88 registry->RegisterBooleanPref(prefs::kRecordWholeDocument, false);
89 }
90
91 // static
92 void Settings::ApplyBlimpSwitches(CommandLinePrefStore* store) {
93 store->ApplyBooleanSwitches(boolean_switch_map,
94 arraysize(boolean_switch_map));
95 }
96
97 } // namespace client
98 } // namespace blimp
OLDNEW
« no previous file with comments | « blimp/client/core/settings/settings.h ('k') | blimp/client/core/settings/settings_feature.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698