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

Side by Side Diff: chrome/browser/prefs/preferences_connection_manager.cc

Issue 2710733002: Fix PreferenceConnectionManagerTeardown (Closed)
Patch Set: Created 3 years, 10 months 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 unified diff | Download patch
« no previous file with comments | « chrome/browser/prefs/preferences_connection_manager.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_service.h" 9 #include "chrome/browser/prefs/preferences_service.h"
10 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
(...skipping 25 matching lines...) Expand all
36 36
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(
47 mojo::StrongBindingPtr<prefs::mojom::PreferencesService> binding) {
48 if (!binding)
49 return;
50 for (auto it = manager_bindings_.begin(); it != manager_bindings_.end();
51 ++it) {
52 if (it->get() == binding.get()) {
53 manager_bindings_.erase(it);
54 return;
55 }
56 }
57 }
58
59 void PreferencesConnectionManager::OnProfileDestroyed() { 46 void PreferencesConnectionManager::OnProfileDestroyed() {
60 for (auto& it : manager_bindings_) { 47 // Shutdown any PreferenceService that is still alive.
61 // Shutdown any PreferenceManager that is still alive. 48 manager_bindings_.CloseAllBindings();
62 if (it)
63 it->Close();
64 }
65
66 profile_shutdown_notification_.reset(); 49 profile_shutdown_notification_.reset();
67 } 50 }
68 51
69 void PreferencesConnectionManager::Create( 52 void PreferencesConnectionManager::Create(
70 prefs::mojom::PreferencesServiceClientPtr client, 53 prefs::mojom::PreferencesServiceClientPtr client,
71 prefs::mojom::PreferencesServiceRequest service) { 54 prefs::mojom::PreferencesServiceRequest service) {
72 // Certain tests have no profiles to connect to, and static initializers 55 // Certain tests have no profiles to connect to, and static initializers
73 // which block the creation of test profiles. 56 // which block the creation of test profiles.
74 if (!g_browser_process->profile_manager()->GetNumberOfProfiles()) 57 if (!g_browser_process->profile_manager()->GetNumberOfProfiles())
75 return; 58 return;
76 59
77 Profile* profile = ProfileManager::GetActiveUserProfile(); 60 manager_bindings_.AddBinding(
78 mojo::StrongBindingPtr<prefs::mojom::PreferencesService> binding = 61 base::MakeUnique<PreferencesService>(
79 mojo::MakeStrongBinding( 62 std::move(client), ProfileManager::GetActiveUserProfile()),
80 base::MakeUnique<PreferencesService>(std::move(client), profile), 63 std::move(service));
81 std::move(service));
82 // Copying the base::WeakPtr for future deletion.
83 binding->set_connection_error_handler(
84 base::Bind(&PreferencesConnectionManager::OnConnectionError,
85 base::Unretained(this), binding));
86 manager_bindings_.push_back(std::move(binding));
87 } 64 }
88 65
89 void PreferencesConnectionManager::Create( 66 void PreferencesConnectionManager::Create(
90 const service_manager::Identity& remote_identity, 67 const service_manager::Identity& remote_identity,
91 prefs::mojom::PreferencesServiceFactoryRequest request) { 68 prefs::mojom::PreferencesServiceFactoryRequest request) {
92 factory_bindings_.AddBinding(this, std::move(request)); 69 factory_bindings_.AddBinding(this, std::move(request));
93 70
94 if (!profile_shutdown_notification_) { 71 if (!profile_shutdown_notification_) {
95 profile_shutdown_notification_ = 72 profile_shutdown_notification_ =
96 ShutdownNotifierFactory::GetInstance() 73 ShutdownNotifierFactory::GetInstance()
97 ->Get(ProfileManager::GetActiveUserProfile()) 74 ->Get(ProfileManager::GetActiveUserProfile())
98 ->Subscribe( 75 ->Subscribe(
99 base::Bind(&PreferencesConnectionManager::OnProfileDestroyed, 76 base::Bind(&PreferencesConnectionManager::OnProfileDestroyed,
100 base::Unretained(this))); 77 base::Unretained(this)));
101 } 78 }
102 } 79 }
103 80
104 void PreferencesConnectionManager::OnStart() {
105 // Certain tests have no profiles to connect to, and static initializers
106 // which block the creation of test profiles.
107 if (!g_browser_process->profile_manager()->GetNumberOfProfiles())
108 return;
109 }
jonross 2017/02/21 15:55:54 The functionality that was here was moved to Creat
110
111 bool PreferencesConnectionManager::OnConnect( 81 bool PreferencesConnectionManager::OnConnect(
112 const service_manager::ServiceInfo& remote_info, 82 const service_manager::ServiceInfo& remote_info,
113 service_manager::InterfaceRegistry* registry) { 83 service_manager::InterfaceRegistry* registry) {
114 registry->AddInterface<prefs::mojom::PreferencesServiceFactory>(this); 84 registry->AddInterface<prefs::mojom::PreferencesServiceFactory>(this);
115 return true; 85 return true;
116 } 86 }
OLDNEW
« no previous file with comments | « chrome/browser/prefs/preferences_connection_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698