| 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 #ifndef CHROME_BROWSER_PREFS_PREFERENCES_CONNECTION_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_PREFS_PREFERENCES_CONNECTION_MANAGER_H_ |
| 6 #define CHROME_BROWSER_PREFS_PREFERENCES_CONNECTION_MANAGER_H_ | 6 #define CHROME_BROWSER_PREFS_PREFERENCES_CONNECTION_MANAGER_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "components/keyed_service/core/keyed_service_shutdown_notifier.h" | 12 #include "components/keyed_service/core/keyed_service_shutdown_notifier.h" |
| 13 #include "mojo/public/cpp/bindings/binding_set.h" | 13 #include "mojo/public/cpp/bindings/binding_set.h" |
| 14 #include "mojo/public/cpp/bindings/strong_binding.h" | 14 #include "mojo/public/cpp/bindings/strong_binding_set.h" |
| 15 #include "services/preferences/public/interfaces/preferences.mojom.h" | 15 #include "services/preferences/public/interfaces/preferences.mojom.h" |
| 16 #include "services/service_manager/public/cpp/interface_factory.h" | 16 #include "services/service_manager/public/cpp/interface_factory.h" |
| 17 #include "services/service_manager/public/cpp/service.h" | 17 #include "services/service_manager/public/cpp/service.h" |
| 18 | 18 |
| 19 // Handles all incoming prefs::mojom::PreferenceManagerRequest, providing a | 19 // Handles all incoming prefs::mojom::PreferenceManagerRequest, providing a |
| 20 // separate PreferencesService per connection request. | 20 // separate PreferencesService per connection request. |
| 21 // | 21 // |
| 22 // Additionally monitors system shutdown to clean up connections to PrefService. | 22 // Additionally monitors system shutdown to clean up connections to PrefService. |
| 23 // | 23 // |
| 24 // TODO(jonross): Observe profile switching and update PreferenceManager | 24 // TODO(jonross): Observe profile switching and update PreferenceManager |
| 25 // connections. | 25 // connections. |
| 26 class PreferencesConnectionManager | 26 class PreferencesConnectionManager |
| 27 : public NON_EXPORTED_BASE(prefs::mojom::PreferencesServiceFactory), | 27 : public NON_EXPORTED_BASE(prefs::mojom::PreferencesServiceFactory), |
| 28 public NON_EXPORTED_BASE(service_manager::InterfaceFactory< | 28 public NON_EXPORTED_BASE(service_manager::InterfaceFactory< |
| 29 prefs::mojom::PreferencesServiceFactory>), | 29 prefs::mojom::PreferencesServiceFactory>), |
| 30 public NON_EXPORTED_BASE(service_manager::Service) { | 30 public NON_EXPORTED_BASE(service_manager::Service) { |
| 31 public: | 31 public: |
| 32 PreferencesConnectionManager(); | 32 PreferencesConnectionManager(); |
| 33 ~PreferencesConnectionManager() override; | 33 ~PreferencesConnectionManager() override; |
| 34 | 34 |
| 35 private: | 35 private: |
| 36 // mojo::StrongBinding callback: | |
| 37 void OnConnectionError( | |
| 38 mojo::StrongBindingPtr<prefs::mojom::PreferencesService> binding); | |
| 39 | |
| 40 // KeyedServiceShutdownNotifier::Subscription callback. Used to cleanup when | 36 // KeyedServiceShutdownNotifier::Subscription callback. Used to cleanup when |
| 41 // the active PrefService is being destroyed. | 37 // the active PrefService is being destroyed. |
| 42 void OnProfileDestroyed(); | 38 void OnProfileDestroyed(); |
| 43 | 39 |
| 44 // prefs::mojom::PreferencesServiceFactory: | 40 // prefs::mojom::PreferencesServiceFactory: |
| 45 void Create(prefs::mojom::PreferencesServiceClientPtr client, | 41 void Create(prefs::mojom::PreferencesServiceClientPtr client, |
| 46 prefs::mojom::PreferencesServiceRequest service) override; | 42 prefs::mojom::PreferencesServiceRequest service) override; |
| 47 | 43 |
| 48 // service_manager::InterfaceFactory<PreferencesServiceFactory>: | 44 // service_manager::InterfaceFactory<PreferencesServiceFactory>: |
| 49 void Create(const service_manager::Identity& remote_identity, | 45 void Create(const service_manager::Identity& remote_identity, |
| 50 prefs::mojom::PreferencesServiceFactoryRequest request) override; | 46 prefs::mojom::PreferencesServiceFactoryRequest request) override; |
| 51 | 47 |
| 52 // service_manager::Service: | 48 // service_manager::Service: |
| 53 void OnStart() override; | |
| 54 bool OnConnect(const service_manager::ServiceInfo& remote_info, | 49 bool OnConnect(const service_manager::ServiceInfo& remote_info, |
| 55 service_manager::InterfaceRegistry* registry) override; | 50 service_manager::InterfaceRegistry* registry) override; |
| 56 | 51 |
| 57 mojo::BindingSet<prefs::mojom::PreferencesServiceFactory> factory_bindings_; | 52 mojo::BindingSet<prefs::mojom::PreferencesServiceFactory> factory_bindings_; |
| 58 | 53 |
| 59 // Bindings that automatically cleanup during connection errors. | 54 // Bindings that automatically cleanup during connection errors. |
| 60 std::vector<mojo::StrongBindingPtr<prefs::mojom::PreferencesService>> | 55 mojo::StrongBindingSet<prefs::mojom::PreferencesService> manager_bindings_; |
| 61 manager_bindings_; | |
| 62 | 56 |
| 63 // Observes shutdown, when PrefService is being destroyed. | 57 // Observes shutdown, when PrefService is being destroyed. |
| 64 std::unique_ptr<KeyedServiceShutdownNotifier::Subscription> | 58 std::unique_ptr<KeyedServiceShutdownNotifier::Subscription> |
| 65 profile_shutdown_notification_; | 59 profile_shutdown_notification_; |
| 66 | 60 |
| 67 DISALLOW_COPY_AND_ASSIGN(PreferencesConnectionManager); | 61 DISALLOW_COPY_AND_ASSIGN(PreferencesConnectionManager); |
| 68 }; | 62 }; |
| 69 | 63 |
| 70 #endif // CHROME_BROWSER_PREFS_PREFERENCES_CONNECTION_MANAGER_H_ | 64 #endif // CHROME_BROWSER_PREFS_PREFERENCES_CONNECTION_MANAGER_H_ |
| OLD | NEW |