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

Unified Diff: blimp/client/core/settings/settings.cc

Issue 2349073002: Blimp Settings framework on the c++ side (Closed)
Patch Set: Remove OnRecordWholeDocumentChanged from SettingsObserver and SettingsFeature Created 4 years, 2 months 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 side-by-side diff with in-line comments
Download patch
Index: blimp/client/core/settings/settings.cc
diff --git a/blimp/client/core/settings/settings.cc b/blimp/client/core/settings/settings.cc
new file mode 100644
index 0000000000000000000000000000000000000000..e61ed2d8f83094ee5f9b41d64f0bfc0f3da1d4a6
--- /dev/null
+++ b/blimp/client/core/settings/settings.cc
@@ -0,0 +1,83 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "blimp/client/core/settings/settings.h"
+
+#include "base/command_line.h"
+#include "blimp/client/core/settings/settings_observer.h"
+#include "blimp/client/core/settings/settings_prefs.h"
+#include "blimp/client/core/switches/blimp_client_switches.h"
+#include "components/prefs/pref_registry_simple.h"
+#include "components/prefs/pref_service.h"
+
+namespace blimp {
+namespace client {
+
+Settings::Settings(PrefService* local_state)
+ : local_state_(local_state),
+ blimp_enabled_(false),
+ record_whole_document_(false),
+ show_network_stats_(false) {
+ InitializeFromCommandLineAndPref();
+}
+
+Settings::~Settings() = default;
+
+void Settings::AddObserver(SettingsObserver* observer) {
+ observers_.AddObserver(observer);
+}
+
+void Settings::RemoveObserver(SettingsObserver* observer) {
+ observers_.RemoveObserver(observer);
+}
+
+void Settings::SetShowNetworkStats(bool enable) {
+ if (show_network_stats_ == enable)
+ return;
+
+ show_network_stats_ = enable;
+ FOR_EACH_OBSERVER(SettingsObserver, observers_,
+ OnShowNetworkStatsChanged(show_network_stats_));
+}
+
+void Settings::SetEnableBlimpMode(bool enable) {
+ if (blimp_enabled_ == enable)
+ return;
+
+ blimp_enabled_ = enable;
+ local_state_->SetBoolean(prefs::kBlimpEnabled, enable);
+ FOR_EACH_OBSERVER(SettingsObserver, observers_, OnBlimpModeEnabled(enable));
+ FOR_EACH_OBSERVER(SettingsObserver, observers_, OnRestartRequired());
+}
+
+void Settings::SetRecordWholeDocument(bool enable) {
+ if (record_whole_document_ == enable)
+ return;
+
+ record_whole_document_ = enable;
+ local_state_->SetBoolean(prefs::kRecordWholeDocument, enable);
+ FOR_EACH_OBSERVER(SettingsObserver, observers_, OnRestartRequired());
+}
+
+void Settings::InitializeFromCommandLineAndPref() {
+ const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess();
+
+ // Get blimp_enabled_ from cmd line or persistent storage.
+ blimp_enabled_ = cmd_line->HasSwitch(switches::kEnableBlimp) ||
+ local_state_->GetBoolean(prefs::kBlimpEnabled);
+
+ // Get record_whole_document_ from cmd line or persistent storage.
+ record_whole_document_ =
+ cmd_line->HasSwitch(switches::kDownloadWholeDocument) ||
+ local_state_->GetBoolean(prefs::kRecordWholeDocument);
+}
+
+// static
+void Settings::RegisterPrefs(PrefRegistrySimple* registry) {
+ registry->RegisterBooleanPref(prefs::kBlimpEnabled, false);
+ registry->RegisterBooleanPref(prefs::kRecordWholeDocument, false);
+}
+
+} // namespace client
+} // namespace blimp

Powered by Google App Engine
This is Rietveld 408576698