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

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

Issue 2474653003: PreferencesManager (Closed)
Patch Set: Update PreferencesManager to account for base::Value API change Created 4 years 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
« no previous file with comments | « chrome/browser/prefs/preferences_connection_manager.h ('k') | chrome/browser/prefs/preferences_manager.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..8a97e55e957a89c4c57a643e95341a20c8781dc7
--- /dev/null
+++ b/chrome/browser/prefs/preferences_connection_manager.cc
@@ -0,0 +1,105 @@
+// 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/browser_process.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"
+#include "services/service_manager/public/cpp/interface_registry.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
+
+PreferencesConnectionManager::PreferencesConnectionManager() {}
+
+PreferencesConnectionManager::~PreferencesConnectionManager() {}
+
+void PreferencesConnectionManager::OnConnectionError(
+ mojo::StrongBindingPtr<prefs::mojom::PreferencesManager> binding) {
+ if (!binding)
+ return;
+ for (auto it = std::begin(bindings_); it != std::end(bindings_); ++it) {
+ if (it->get() == binding.get()) {
+ bindings_.erase(it);
+ return;
+ }
+ }
+}
+
+void PreferencesConnectionManager::OnProfileDestroyed() {
+ for (auto& it : bindings_) {
+ // Shutdown any PreferenceManager that is still alive.
+ if (it)
+ it->Close();
+ }
+
+ profile_shutdown_notification_.reset();
+}
+
+void PreferencesConnectionManager::Create(
+ const service_manager::Identity& remote_identity,
+ prefs::mojom::PreferencesManagerRequest request) {
+ // Certain tests have no profiles to connect to, and static initializers
+ // which block the creation of test profiles.
+ if (!g_browser_process->profile_manager()->GetNumberOfProfiles())
+ return;
+
+ Profile* profile = ProfileManager::GetActiveUserProfile();
+ mojo::StrongBindingPtr<prefs::mojom::PreferencesManager> binding =
+ mojo::MakeStrongBinding(base::MakeUnique<PreferencesManager>(profile),
+ std::move(request));
+ // Copying the base::WeakPtr for future deletion.
+ binding->set_connection_error_handler(
+ base::Bind(&PreferencesConnectionManager::OnConnectionError,
+ base::Unretained(this), binding));
+ bindings_.push_back(std::move(binding));
+}
+
+void PreferencesConnectionManager::OnStart() {
+ // Certain tests have no profiles to connect to, and static initializers
+ // which block the creation of test profiles.
+ if (!g_browser_process->profile_manager()->GetNumberOfProfiles())
+ return;
+
+ profile_shutdown_notification_ =
+ ShutdownNotifierFactory::GetInstance()
+ ->Get(ProfileManager::GetActiveUserProfile())
+ ->Subscribe(
+ base::Bind(&PreferencesConnectionManager::OnProfileDestroyed,
+ base::Unretained(this)));
+}
+
+bool PreferencesConnectionManager::OnConnect(
+ const service_manager::ServiceInfo& remote_info,
+ service_manager::InterfaceRegistry* registry) {
+ registry->AddInterface<prefs::mojom::PreferencesManager>(this);
+ return true;
+}
« no previous file with comments | « chrome/browser/prefs/preferences_connection_manager.h ('k') | chrome/browser/prefs/preferences_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698