Chromium Code Reviews| 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) { |
|
battre
2016/10/10 09:28:30
this is not a very idiomatic of the PrefService. I
Menglin
2016/10/10 17:51:35
Acknowledged.
|
| + if (blimp_enabled_ == enable) |
| + return; |
| + |
| + blimp_enabled_ = enable; |
| + local_state_->SetBoolean(prefs::kBlimpEnabled, enable); |
| + FOR_EACH_OBSERVER(SettingsObserver, observers_, OnBlimpModeEnabled(enable)); |
|
battre
2016/10/10 09:28:30
If a SettingsObserver subscribed to prefs instead
Bernhard Bauer
2016/10/10 13:02:18
Alternatively, keep the SettingsObserver interface
Menglin
2016/10/10 17:51:35
Thank you for your comments!
I think it's better t
David Trainor- moved to gerrit
2016/10/10 21:18:28
Ah yeah that's a really good point r.e. pushing pr
|
| + 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()); |
|
Menglin
2016/10/24 22:44:58
David, as we discussed, when this gets changed, no
|
| +} |
| + |
| +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); |
|
Menglin
2016/10/10 23:49:01
David, I also talked to khushal about this. looks
Bernhard Bauer
2016/10/11 09:17:04
CommandLinePrefStore will do exactly that for you
|
| + |
| + // Get record_whole_document_ from cmd line or persistent storage. |
| + record_whole_document_ = |
| + cmd_line->HasSwitch(switches::kDownloadWholeDocument) || |
| + local_state_->GetBoolean(prefs::kRecordWholeDocument); |
|
battre
2016/10/10 09:28:30
Commandline parameters are typically handled via h
Menglin
2016/10/10 17:51:35
blimp has been keeping its cmd line here. https://
David Trainor- moved to gerrit
2016/10/10 21:18:29
Ideally we wouldn't bleed all blimp switches into
Bernhard Bauer
2016/10/11 09:17:04
CommandLinePrefStore right now contains all the Ch
David Trainor- moved to gerrit
2016/10/11 16:25:31
Hmm I haven't looked into how to actually use this
Bernhard Bauer
2016/10/11 16:45:35
Wait, now I'm slightly confused. Do you want to us
Menglin
2016/10/11 16:57:38
we are using chrome's user profile prefs. https://
|
| +} |
| + |
| +// static |
| +void Settings::RegisterPrefs(PrefRegistrySimple* registry) { |
| + registry->RegisterBooleanPref(prefs::kBlimpEnabled, false); |
| + registry->RegisterBooleanPref(prefs::kRecordWholeDocument, false); |
| +} |
| + |
| +} // namespace client |
| +} // namespace blimp |