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

Unified Diff: chrome/browser/prefs/preferences_connection_manager.cc

Issue 2474653003: PreferencesManager (Closed)
Patch Set: Rebase Created 4 years, 1 month 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: chrome/browser/prefs/preferences_connection_manager.cc
diff --git a/chrome/browser/prefs/preferences_connection_manager.cc b/chrome/browser/prefs/preferences_connection_manager.cc
new file mode 100644
index 0000000000000000000000000000000000000000..efa7406f4d7c446c3d519f272d9c6c377d18e9cd
--- /dev/null
+++ b/chrome/browser/prefs/preferences_connection_manager.cc
@@ -0,0 +1,71 @@
+// 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 "chrome/browser/prefs/preferences_connection_manager.h"
+
+#include "chrome/browser/prefs/preferences_manager.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/profiles/profile_manager.h"
+#include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
+#include "components/keyed_service/content/browser_context_keyed_service_shutdown_notifier_factory.h"
+
+namespace {
+
+// Required singleton subclass to control dependencies between
+// PreferenceConnectionManager and the KeyedServiceShutdownNotifier.
+class ShutdownNotifierFactory
+ : public BrowserContextKeyedServiceShutdownNotifierFactory {
+ public:
+ static ShutdownNotifierFactory* GetInstance() {
+ return base::Singleton<ShutdownNotifierFactory>::get();
+ }
+
+ private:
+ friend struct base::DefaultSingletonTraits<ShutdownNotifierFactory>;
+
+ ShutdownNotifierFactory()
+ : BrowserContextKeyedServiceShutdownNotifierFactory(
+ "PreferencesConnectionManager") {
+ DependsOn(ProfileOAuth2TokenServiceFactory::GetInstance());
+ }
+ ~ShutdownNotifierFactory() override {}
+
+ DISALLOW_COPY_AND_ASSIGN(ShutdownNotifierFactory);
+};
+
+} // namespace
+
+namespace chrome {
+
+PreferencesConnectionManager::PreferencesConnectionManager()
+ : profile_shutdown_notification_(
+ ShutdownNotifierFactory::GetInstance()
+ ->Get(ProfileManager::GetActiveUserProfile())
+ ->Subscribe(
+ base::Bind(&PreferencesConnectionManager::OnProfileDestroyed,
+ base::Unretained(this)))) {}
+
+PreferencesConnectionManager::~PreferencesConnectionManager() {}
+
+void PreferencesConnectionManager::ProcessRequest(
+ prefs::mojom::PreferencesManagerRequest request) {
+ Profile* profile = ProfileManager::GetActiveUserProfile();
+ mojo::StrongBindingPtr<prefs::mojom::PreferencesManager> binding =
+ mojo::MakeStrongBinding(base::MakeUnique<PreferencesManager>(profile),
msw 2016/11/18 00:32:57 I wonder if a single PreferencesManager instance c
jonross 2016/11/18 00:47:58 I originally had that, but wanted to handle differ
+ std::move(request));
+ bindings_.push_back(binding);
+}
+
+void PreferencesConnectionManager::OnProfileDestroyed() {
+ for (auto it : bindings_) {
James Cook 2016/11/18 00:50:34 auto& ? auto* ? Otherwise the copying (or not) i
jonross 2016/11/18 20:31:23 Done.
+ // Check that the PreferencesManager was not cleared from a connection
+ // error.
+ if (it)
+ (static_cast<PreferencesManager*>(it->impl()))->OnProfileDestroyed();
+ }
+
+ profile_shutdown_notification_.reset();
+}
+
+} // namespace chrome

Powered by Google App Engine
This is Rietveld 408576698