Chromium Code Reviews| OLD | NEW |
|---|---|
| (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/command_line.h" | |
| 8 #include "blimp/client/core/settings/settings_observer.h" | |
| 9 #include "blimp/client/core/settings/settings_prefs.h" | |
| 10 #include "blimp/client/core/switches/blimp_client_switches.h" | |
| 11 #include "components/prefs/pref_registry_simple.h" | |
| 12 #include "components/prefs/pref_service.h" | |
| 13 | |
| 14 namespace blimp { | |
| 15 namespace client { | |
| 16 | |
| 17 Settings::Settings(PrefService* local_state) | |
| 18 : local_state_(local_state), | |
| 19 blimp_enabled_(false), | |
| 20 record_whole_document_(false), | |
| 21 show_network_stats_(false) { | |
| 22 InitializeFromCommandLineAndPref(); | |
| 23 } | |
| 24 | |
| 25 Settings::~Settings() = default; | |
| 26 | |
| 27 void Settings::AddObserver(SettingsObserver* observer) { | |
| 28 observers_.AddObserver(observer); | |
| 29 } | |
| 30 | |
| 31 void Settings::RemoveObserver(SettingsObserver* observer) { | |
| 32 observers_.RemoveObserver(observer); | |
| 33 } | |
| 34 | |
| 35 void Settings::SetShowNetworkStats(bool enable) { | |
| 36 if (show_network_stats_ == enable) | |
| 37 return; | |
| 38 | |
| 39 show_network_stats_ = enable; | |
| 40 FOR_EACH_OBSERVER(SettingsObserver, observers_, | |
| 41 OnShowNetworkStatsChanged(show_network_stats_)); | |
| 42 } | |
| 43 | |
| 44 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.
| |
| 45 if (blimp_enabled_ == enable) | |
| 46 return; | |
| 47 | |
| 48 blimp_enabled_ = enable; | |
| 49 local_state_->SetBoolean(prefs::kBlimpEnabled, enable); | |
| 50 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
| |
| 51 FOR_EACH_OBSERVER(SettingsObserver, observers_, OnRestartRequired()); | |
| 52 } | |
| 53 | |
| 54 void Settings::SetRecordWholeDocument(bool enable) { | |
| 55 if (record_whole_document_ == enable) | |
| 56 return; | |
| 57 | |
| 58 record_whole_document_ = enable; | |
| 59 local_state_->SetBoolean(prefs::kRecordWholeDocument, enable); | |
| 60 FOR_EACH_OBSERVER(SettingsObserver, observers_, OnRestartRequired()); | |
|
Menglin
2016/10/24 22:44:58
David, as we discussed, when this gets changed, no
| |
| 61 } | |
| 62 | |
| 63 void Settings::InitializeFromCommandLineAndPref() { | |
| 64 const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); | |
| 65 | |
| 66 // Get blimp_enabled_ from cmd line or persistent storage. | |
| 67 blimp_enabled_ = cmd_line->HasSwitch(switches::kEnableBlimp) || | |
| 68 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
| |
| 69 | |
| 70 // Get record_whole_document_ from cmd line or persistent storage. | |
| 71 record_whole_document_ = | |
| 72 cmd_line->HasSwitch(switches::kDownloadWholeDocument) || | |
| 73 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://
| |
| 74 } | |
| 75 | |
| 76 // static | |
| 77 void Settings::RegisterPrefs(PrefRegistrySimple* registry) { | |
| 78 registry->RegisterBooleanPref(prefs::kBlimpEnabled, false); | |
| 79 registry->RegisterBooleanPref(prefs::kRecordWholeDocument, false); | |
| 80 } | |
| 81 | |
| 82 } // namespace client | |
| 83 } // namespace blimp | |
| OLD | NEW |