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

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

Issue 2349073002: Blimp Settings framework on the c++ side (Closed)
Patch Set: move the PrefService logic from blimp_main.cc 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
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/switches/blimp_client_switches.h"
11 #include "components/prefs/pref_registry_simple.h"
12
13 namespace blimp {
14 namespace client {
15
16 const CommandLinePrefStore::BooleanSwitchToPreferenceMapEntry
17 boolean_switch_map[] = {
18 {blimp::switches::kEnableBlimp, prefs::kBlimpEnabled, true},
19 {blimp::switches::kDownloadWholeDocument,
20 prefs::kRecordWholeDocument, true},
21 };
22
23 Settings::Settings(PrefService* local_state)
24 : local_state_(local_state),
25 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(
65 PrefService* service, 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_) {
Bernhard Bauer 2016/10/26 09:47:23 No braces here either.
Menglin 2016/10/26 19:28:33 Done.
73 observer.OnRecordWholeDocumentChanged(service->GetBoolean(pref_name));
74 }
75 }
76 }
77
78 // static
79 void Settings::RegisterPrefs(PrefRegistrySimple* registry) {
80 registry->RegisterBooleanPref(prefs::kBlimpEnabled, false);
81 registry->RegisterBooleanPref(prefs::kRecordWholeDocument, false);
82 }
83
84 // static
85 void Settings::ApplyBlimpSwitches(CommandLinePrefStore* store) {
86 store->ApplyBooleanSwitches(boolean_switch_map,
87 arraysize(boolean_switch_map));
88 }
89
90 } // namespace client
91 } // namespace blimp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698