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

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

Issue 2349073002: Blimp Settings framework on the c++ side (Closed)
Patch Set: Settings doesn't own its observer anymore. SettingsFeature subclass SettingsObserver Created 4 years, 3 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..81d9781aa0c5cebfae3b3e7c4be118095739d2c7
--- /dev/null
+++ b/blimp/client/core/settings/settings.cc
@@ -0,0 +1,84 @@
+// 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/blimp_client_switches.h"
+#include "blimp/client/core/settings/settings_observer.h"
+#include "blimp/client/core/settings/settings_prefs.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;
David Trainor- moved to gerrit 2016/10/01 03:26:34 if (show_network_stats_ == enable) return; Same
Menglin 2016/10/03 23:08:26 Done.
+
+ 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_,
+ OnRecordWholeDocumentChanged(enable));
+ FOR_EACH_OBSERVER(SettingsObserver, observers_, OnRestartRequired());
+}
+
+void Settings::InitializeFromCommandLineAndPref() {
+ const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess();
+
+ // Get blimp_enabled_ from cmd line and persistent storage.
+ blimp_enabled_ = cmd_line->HasSwitch(switches::kEnableBlimp) ||
+ local_state_->GetBoolean(prefs::kBlimpEnabled);
+
+ // Get blimp_enabled_ from cmd line and persistent storage, and save the
David Trainor- moved to gerrit 2016/10/01 03:26:34 blimp_enabled_ -> record_whole_document_?
Menglin 2016/10/03 23:08:26 Yeah. bad idea to copy around... thanks!
+ // result to persistent storage.
+ record_whole_document_ =
+ cmd_line->HasSwitch(switches::kDownloadWholeDocument) ||
+ local_state_->GetBoolean(prefs::kRecordWholeDocument);
+ local_state_->SetBoolean(prefs::kRecordWholeDocument, record_whole_document_);
+}
+
+// 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