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