 Chromium Code Reviews
 Chromium Code Reviews Issue 2772673002:
  mash: switch to the new pref service  (Closed)
    
  
    Issue 2772673002:
  mash: switch to the new pref service  (Closed) 
  | Index: ash/shell.cc | 
| diff --git a/ash/shell.cc b/ash/shell.cc | 
| index b08021413c6e2188221ca9c02c7951733b8fecbd..43361f33a7543d459479eb25eb2358a2dbae0676 100644 | 
| --- a/ash/shell.cc | 
| +++ b/ash/shell.cc | 
| @@ -124,8 +124,10 @@ | 
| #include "chromeos/chromeos_switches.h" | 
| #include "chromeos/dbus/dbus_thread_manager.h" | 
| #include "chromeos/system/devicemode.h" | 
| +#include "components/prefs/pref_registry_simple.h" | 
| +#include "components/prefs/pref_service.h" | 
| #include "components/ui_devtools/devtools_server.h" | 
| -#include "services/preferences/public/cpp/pref_client_store.h" | 
| +#include "services/preferences/public/cpp/pref_service_factory.h" | 
| #include "services/preferences/public/interfaces/preferences.mojom.h" | 
| #include "services/service_manager/public/cpp/connector.h" | 
| #include "services/ui/public/interfaces/constants.mojom.h" | 
| @@ -728,7 +730,7 @@ Shell::~Shell() { | 
| // Must be destroyed before FocusController. | 
| shelf_delegate_.reset(); | 
| - // Removes itself as an observer of |pref_store_|. | 
| + // Removes itself as an observer of |pref_service_|. | 
| shelf_controller_.reset(); | 
| wm_shell_->Shutdown(); | 
| @@ -760,7 +762,7 @@ Shell::~Shell() { | 
| wm_shell_.reset(); | 
| session_controller_->RemoveSessionStateObserver(this); | 
| wallpaper_delegate_.reset(); | 
| - pref_store_ = nullptr; | 
| + pref_service_ = nullptr; | 
| shell_delegate_.reset(); | 
| DCHECK(instance_ == this); | 
| @@ -775,11 +777,12 @@ void Shell::Init(const ShellInitParams& init_params) { | 
| wallpaper_delegate_ = shell_delegate_->CreateWallpaperDelegate(); | 
| // Can be null in tests. | 
| - if (shell_delegate_->GetShellConnector()) { | 
| - prefs::mojom::PreferencesServiceFactoryPtr pref_factory_ptr; | 
| - shell_delegate_->GetShellConnector()->BindInterface( | 
| - prefs::mojom::kServiceName, &pref_factory_ptr); | 
| - pref_store_ = new preferences::PrefClientStore(std::move(pref_factory_ptr)); | 
| + if (wm_shell_->IsRunningInMash() && shell_delegate_->GetShellConnector()) { | 
| 
jonross
2017/03/27 14:26:38
More detailed notes given for PrefServiceEnabled()
 
sky
2017/03/27 16:00:10
How come the pref-service is specific to mash?
 
tibell
2017/03/28 00:34:31
I'm happy to use whatever predicate you prefer. It
 
tibell
2017/03/28 00:34:31
I didn't explain this clearly enough.
The pref se
 
jonross
2017/03/28 13:57:26
I hadn't realized the concerns around performance.
 
tibell
2017/03/29 02:59:14
For the record, jonross@ and I discussed this offl
 | 
| + prefs::ConnectToPrefService( | 
| + shell_delegate_->GetShellConnector(), | 
| + make_scoped_refptr(new PrefRegistrySimple()), | 
| + base::Bind(&Shell::OnPrefServiceInitialized, base::Unretained(this)), | 
| 
jonross
2017/03/27 14:26:38
Slightly concerned about an Unretained ref.
'Shou
 
tibell
2017/03/28 00:34:31
Acknowledged.
 | 
| + prefs::mojom::kForwarderServiceName); | 
| } | 
| // Some delegates access WmShell during their construction. Create them here | 
| @@ -1226,4 +1229,10 @@ void Shell::SessionStateChanged(session_manager::SessionState state) { | 
| } | 
| } | 
| +void Shell::OnPrefServiceInitialized( | 
| + std::unique_ptr<::PrefService> pref_service) { | 
| 
jonross
2017/03/27 14:26:38
We could protect against the base::Unretained by e
 
tibell
2017/03/28 00:34:31
Done.
 | 
| + DCHECK(pref_service); | 
| + pref_service_ = std::move(pref_service); | 
| +} | 
| + | 
| } // namespace ash |