| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/prefs/preferences_connection_manager.h" | 5 #include "chrome/browser/prefs/preferences_connection_manager.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
| 9 #include "chrome/browser/prefs/preferences_manager.h" | 9 #include "chrome/browser/prefs/preferences_service.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 11 #include "chrome/browser/profiles/profile_manager.h" | 11 #include "chrome/browser/profiles/profile_manager.h" |
| 12 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 12 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 13 #include "components/keyed_service/content/browser_context_keyed_service_shutdow
n_notifier_factory.h" | 13 #include "components/keyed_service/content/browser_context_keyed_service_shutdow
n_notifier_factory.h" |
| 14 #include "services/service_manager/public/cpp/interface_registry.h" | 14 #include "services/service_manager/public/cpp/interface_registry.h" |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 // Required singleton subclass to control dependencies between | 18 // Required singleton subclass to control dependencies between |
| 19 // PreferenceConnectionManager and the KeyedServiceShutdownNotifier. | 19 // PreferenceConnectionManager and the KeyedServiceShutdownNotifier. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 37 DISALLOW_COPY_AND_ASSIGN(ShutdownNotifierFactory); | 37 DISALLOW_COPY_AND_ASSIGN(ShutdownNotifierFactory); |
| 38 }; | 38 }; |
| 39 | 39 |
| 40 } // namespace | 40 } // namespace |
| 41 | 41 |
| 42 PreferencesConnectionManager::PreferencesConnectionManager() {} | 42 PreferencesConnectionManager::PreferencesConnectionManager() {} |
| 43 | 43 |
| 44 PreferencesConnectionManager::~PreferencesConnectionManager() {} | 44 PreferencesConnectionManager::~PreferencesConnectionManager() {} |
| 45 | 45 |
| 46 void PreferencesConnectionManager::OnConnectionError( | 46 void PreferencesConnectionManager::OnConnectionError( |
| 47 mojo::StrongBindingPtr<prefs::mojom::PreferencesManager> binding) { | 47 mojo::StrongBindingPtr<prefs::mojom::PreferencesService> binding) { |
| 48 if (!binding) | 48 if (!binding) |
| 49 return; | 49 return; |
| 50 for (auto it = manager_bindings_.begin(); it != manager_bindings_.end(); | 50 for (auto it = manager_bindings_.begin(); it != manager_bindings_.end(); |
| 51 ++it) { | 51 ++it) { |
| 52 if (it->get() == binding.get()) { | 52 if (it->get() == binding.get()) { |
| 53 manager_bindings_.erase(it); | 53 manager_bindings_.erase(it); |
| 54 return; | 54 return; |
| 55 } | 55 } |
| 56 } | 56 } |
| 57 } | 57 } |
| 58 | 58 |
| 59 void PreferencesConnectionManager::OnProfileDestroyed() { | 59 void PreferencesConnectionManager::OnProfileDestroyed() { |
| 60 for (auto& it : manager_bindings_) { | 60 for (auto& it : manager_bindings_) { |
| 61 // Shutdown any PreferenceManager that is still alive. | 61 // Shutdown any PreferenceManager that is still alive. |
| 62 if (it) | 62 if (it) |
| 63 it->Close(); | 63 it->Close(); |
| 64 } | 64 } |
| 65 | 65 |
| 66 profile_shutdown_notification_.reset(); | 66 profile_shutdown_notification_.reset(); |
| 67 } | 67 } |
| 68 | 68 |
| 69 void PreferencesConnectionManager::Create( | 69 void PreferencesConnectionManager::Create( |
| 70 prefs::mojom::PreferencesObserverPtr observer, | 70 prefs::mojom::PreferencesServiceClientPtr client, |
| 71 prefs::mojom::PreferencesManagerRequest manager) { | 71 prefs::mojom::PreferencesServiceRequest service) { |
| 72 // Certain tests have no profiles to connect to, and static initializers | 72 // Certain tests have no profiles to connect to, and static initializers |
| 73 // which block the creation of test profiles. | 73 // which block the creation of test profiles. |
| 74 if (!g_browser_process->profile_manager()->GetNumberOfProfiles()) | 74 if (!g_browser_process->profile_manager()->GetNumberOfProfiles()) |
| 75 return; | 75 return; |
| 76 | 76 |
| 77 Profile* profile = ProfileManager::GetActiveUserProfile(); | 77 Profile* profile = ProfileManager::GetActiveUserProfile(); |
| 78 mojo::StrongBindingPtr<prefs::mojom::PreferencesManager> binding = | 78 mojo::StrongBindingPtr<prefs::mojom::PreferencesService> binding = |
| 79 mojo::MakeStrongBinding( | 79 mojo::MakeStrongBinding( |
| 80 base::MakeUnique<PreferencesManager>(std::move(observer), profile), | 80 base::MakeUnique<PreferencesService>(std::move(client), profile), |
| 81 std::move(manager)); | 81 std::move(service)); |
| 82 // Copying the base::WeakPtr for future deletion. | 82 // Copying the base::WeakPtr for future deletion. |
| 83 binding->set_connection_error_handler( | 83 binding->set_connection_error_handler( |
| 84 base::Bind(&PreferencesConnectionManager::OnConnectionError, | 84 base::Bind(&PreferencesConnectionManager::OnConnectionError, |
| 85 base::Unretained(this), binding)); | 85 base::Unretained(this), binding)); |
| 86 manager_bindings_.push_back(std::move(binding)); | 86 manager_bindings_.push_back(std::move(binding)); |
| 87 } | 87 } |
| 88 | 88 |
| 89 void PreferencesConnectionManager::Create( | 89 void PreferencesConnectionManager::Create( |
| 90 const service_manager::Identity& remote_identity, | 90 const service_manager::Identity& remote_identity, |
| 91 prefs::mojom::PreferencesFactoryRequest request) { | 91 prefs::mojom::PreferencesServiceFactoryRequest request) { |
| 92 factory_bindings_.AddBinding(this, std::move(request)); | 92 factory_bindings_.AddBinding(this, std::move(request)); |
| 93 } | 93 } |
| 94 | 94 |
| 95 void PreferencesConnectionManager::OnStart() { | 95 void PreferencesConnectionManager::OnStart() { |
| 96 // Certain tests have no profiles to connect to, and static initializers | 96 // Certain tests have no profiles to connect to, and static initializers |
| 97 // which block the creation of test profiles. | 97 // which block the creation of test profiles. |
| 98 if (!g_browser_process->profile_manager()->GetNumberOfProfiles()) | 98 if (!g_browser_process->profile_manager()->GetNumberOfProfiles()) |
| 99 return; | 99 return; |
| 100 | 100 |
| 101 profile_shutdown_notification_ = | 101 profile_shutdown_notification_ = |
| 102 ShutdownNotifierFactory::GetInstance() | 102 ShutdownNotifierFactory::GetInstance() |
| 103 ->Get(ProfileManager::GetActiveUserProfile()) | 103 ->Get(ProfileManager::GetActiveUserProfile()) |
| 104 ->Subscribe( | 104 ->Subscribe( |
| 105 base::Bind(&PreferencesConnectionManager::OnProfileDestroyed, | 105 base::Bind(&PreferencesConnectionManager::OnProfileDestroyed, |
| 106 base::Unretained(this))); | 106 base::Unretained(this))); |
| 107 } | 107 } |
| 108 | 108 |
| 109 bool PreferencesConnectionManager::OnConnect( | 109 bool PreferencesConnectionManager::OnConnect( |
| 110 const service_manager::ServiceInfo& remote_info, | 110 const service_manager::ServiceInfo& remote_info, |
| 111 service_manager::InterfaceRegistry* registry) { | 111 service_manager::InterfaceRegistry* registry) { |
| 112 registry->AddInterface<prefs::mojom::PreferencesFactory>(this); | 112 registry->AddInterface<prefs::mojom::PreferencesServiceFactory>(this); |
| 113 return true; | 113 return true; |
| 114 } | 114 } |
| OLD | NEW |