| OLD | NEW | 
|---|
|  | (Empty) | 
| 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 |  | 
| 3 // found in the LICENSE file. |  | 
| 4 |  | 
| 5 #include "chrome/browser/prefs/preferences_connection_manager.h" |  | 
| 6 |  | 
| 7 #include "base/memory/ptr_util.h" |  | 
| 8 #include "chrome/browser/browser_process.h" |  | 
| 9 #include "chrome/browser/prefs/preferences_service.h" |  | 
| 10 #include "chrome/browser/profiles/profile.h" |  | 
| 11 #include "chrome/browser/profiles/profile_manager.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" |  | 
| 14 #include "services/service_manager/public/cpp/interface_registry.h" |  | 
| 15 |  | 
| 16 namespace { |  | 
| 17 |  | 
| 18 // Required singleton subclass to control dependencies between |  | 
| 19 // PreferenceConnectionManager and the KeyedServiceShutdownNotifier. |  | 
| 20 class ShutdownNotifierFactory |  | 
| 21     : public BrowserContextKeyedServiceShutdownNotifierFactory { |  | 
| 22  public: |  | 
| 23   static ShutdownNotifierFactory* GetInstance() { |  | 
| 24     return base::Singleton<ShutdownNotifierFactory>::get(); |  | 
| 25   } |  | 
| 26 |  | 
| 27  private: |  | 
| 28   friend struct base::DefaultSingletonTraits<ShutdownNotifierFactory>; |  | 
| 29 |  | 
| 30   ShutdownNotifierFactory() |  | 
| 31       : BrowserContextKeyedServiceShutdownNotifierFactory( |  | 
| 32             "PreferencesConnectionManager") { |  | 
| 33     DependsOn(ProfileOAuth2TokenServiceFactory::GetInstance()); |  | 
| 34   } |  | 
| 35   ~ShutdownNotifierFactory() override {} |  | 
| 36 |  | 
| 37   DISALLOW_COPY_AND_ASSIGN(ShutdownNotifierFactory); |  | 
| 38 }; |  | 
| 39 |  | 
| 40 }  // namespace |  | 
| 41 |  | 
| 42 PreferencesConnectionManager::PreferencesConnectionManager() {} |  | 
| 43 |  | 
| 44 PreferencesConnectionManager::~PreferencesConnectionManager() {} |  | 
| 45 |  | 
| 46 void PreferencesConnectionManager::OnProfileDestroyed() { |  | 
| 47   // Shutdown any PreferenceService that is still alive. |  | 
| 48   manager_bindings_.CloseAllBindings(); |  | 
| 49   profile_shutdown_notification_.reset(); |  | 
| 50 } |  | 
| 51 |  | 
| 52 void PreferencesConnectionManager::Create( |  | 
| 53     prefs::mojom::PreferencesServiceClientPtr client, |  | 
| 54     prefs::mojom::PreferencesServiceRequest service) { |  | 
| 55   // Certain tests have no profiles to connect to, and static initializers |  | 
| 56   // which block the creation of test profiles. |  | 
| 57   if (!g_browser_process->profile_manager()->GetNumberOfProfiles()) |  | 
| 58     return; |  | 
| 59 |  | 
| 60   manager_bindings_.AddBinding( |  | 
| 61       base::MakeUnique<PreferencesService>( |  | 
| 62           std::move(client), ProfileManager::GetActiveUserProfile()), |  | 
| 63       std::move(service)); |  | 
| 64 } |  | 
| 65 |  | 
| 66 void PreferencesConnectionManager::Create( |  | 
| 67     const service_manager::Identity& remote_identity, |  | 
| 68     prefs::mojom::PreferencesServiceFactoryRequest request) { |  | 
| 69   factory_bindings_.AddBinding(this, std::move(request)); |  | 
| 70 |  | 
| 71   if (!profile_shutdown_notification_) { |  | 
| 72     profile_shutdown_notification_ = |  | 
| 73         ShutdownNotifierFactory::GetInstance() |  | 
| 74             ->Get(ProfileManager::GetActiveUserProfile()) |  | 
| 75             ->Subscribe( |  | 
| 76                 base::Bind(&PreferencesConnectionManager::OnProfileDestroyed, |  | 
| 77                            base::Unretained(this))); |  | 
| 78   } |  | 
| 79 } |  | 
| 80 |  | 
| 81 bool PreferencesConnectionManager::OnConnect( |  | 
| 82     const service_manager::ServiceInfo& remote_info, |  | 
| 83     service_manager::InterfaceRegistry* registry) { |  | 
| 84   registry->AddInterface<prefs::mojom::PreferencesServiceFactory>(this); |  | 
| 85   return true; |  | 
| 86 } |  | 
| OLD | NEW | 
|---|