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

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

Issue 2635093002: Switch Preferences to use Factory (Closed)
Patch Set: dcheck for bound Created 3 years, 11 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
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_manager.h" 9 #include "chrome/browser/prefs/preferences_manager.h"
10 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
(...skipping 29 matching lines...) Expand all
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::PreferencesManager> binding) {
48 if (!binding) 48 if (!binding)
49 return; 49 return;
50 for (auto it = std::begin(bindings_); it != std::end(bindings_); ++it) { 50 for (auto it = std::begin(manager_bindings_);
sky 2017/01/17 23:45:04 Why do you need std::begin/std::end here?
jonross 2017/01/18 23:13:02 I need the iterator for std::vector.erase, and ran
sky 2017/01/18 23:38:25 Sorry for not being clear. I'm asking why you can'
jonross 2017/01/19 15:24:13 You aren't missing anything, and now I'm wondering
51 it != std::end(manager_bindings_); ++it) {
51 if (it->get() == binding.get()) { 52 if (it->get() == binding.get()) {
52 bindings_.erase(it); 53 manager_bindings_.erase(it);
53 return; 54 return;
54 } 55 }
55 } 56 }
56 } 57 }
57 58
58 void PreferencesConnectionManager::OnProfileDestroyed() { 59 void PreferencesConnectionManager::OnProfileDestroyed() {
59 for (auto& it : bindings_) { 60 for (auto& it : manager_bindings_) {
60 // Shutdown any PreferenceManager that is still alive. 61 // Shutdown any PreferenceManager that is still alive.
61 if (it) 62 if (it)
62 it->Close(); 63 it->Close();
63 } 64 }
64 65
65 profile_shutdown_notification_.reset(); 66 profile_shutdown_notification_.reset();
66 } 67 }
67 68
68 void PreferencesConnectionManager::Create( 69 void PreferencesConnectionManager::Create(
69 const service_manager::Identity& remote_identity, 70 prefs::mojom::PreferencesObserverPtr observer,
70 prefs::mojom::PreferencesManagerRequest request) { 71 prefs::mojom::PreferencesManagerRequest manager) {
71 // Certain tests have no profiles to connect to, and static initializers 72 // Certain tests have no profiles to connect to, and static initializers
72 // which block the creation of test profiles. 73 // which block the creation of test profiles.
73 if (!g_browser_process->profile_manager()->GetNumberOfProfiles()) 74 if (!g_browser_process->profile_manager()->GetNumberOfProfiles())
74 return; 75 return;
75 76
76 Profile* profile = ProfileManager::GetActiveUserProfile(); 77 Profile* profile = ProfileManager::GetActiveUserProfile();
77 mojo::StrongBindingPtr<prefs::mojom::PreferencesManager> binding = 78 mojo::StrongBindingPtr<prefs::mojom::PreferencesManager> binding =
78 mojo::MakeStrongBinding(base::MakeUnique<PreferencesManager>(profile), 79 mojo::MakeStrongBinding(
79 std::move(request)); 80 base::MakeUnique<PreferencesManager>(std::move(observer), profile),
81 std::move(manager));
80 // Copying the base::WeakPtr for future deletion. 82 // Copying the base::WeakPtr for future deletion.
81 binding->set_connection_error_handler( 83 binding->set_connection_error_handler(
82 base::Bind(&PreferencesConnectionManager::OnConnectionError, 84 base::Bind(&PreferencesConnectionManager::OnConnectionError,
83 base::Unretained(this), binding)); 85 base::Unretained(this), binding));
84 bindings_.push_back(std::move(binding)); 86 manager_bindings_.push_back(std::move(binding));
87 }
88
89 void PreferencesConnectionManager::Create(
90 const service_manager::Identity& remote_identity,
91 prefs::mojom::PreferencesFactoryRequest request) {
92 factory_bindings_.AddBinding(this, std::move(request));
85 } 93 }
86 94
87 void PreferencesConnectionManager::OnStart() { 95 void PreferencesConnectionManager::OnStart() {
88 // Certain tests have no profiles to connect to, and static initializers 96 // Certain tests have no profiles to connect to, and static initializers
89 // which block the creation of test profiles. 97 // which block the creation of test profiles.
90 if (!g_browser_process->profile_manager()->GetNumberOfProfiles()) 98 if (!g_browser_process->profile_manager()->GetNumberOfProfiles())
91 return; 99 return;
92 100
93 profile_shutdown_notification_ = 101 profile_shutdown_notification_ =
94 ShutdownNotifierFactory::GetInstance() 102 ShutdownNotifierFactory::GetInstance()
95 ->Get(ProfileManager::GetActiveUserProfile()) 103 ->Get(ProfileManager::GetActiveUserProfile())
96 ->Subscribe( 104 ->Subscribe(
97 base::Bind(&PreferencesConnectionManager::OnProfileDestroyed, 105 base::Bind(&PreferencesConnectionManager::OnProfileDestroyed,
98 base::Unretained(this))); 106 base::Unretained(this)));
99 } 107 }
100 108
101 bool PreferencesConnectionManager::OnConnect( 109 bool PreferencesConnectionManager::OnConnect(
102 const service_manager::ServiceInfo& remote_info, 110 const service_manager::ServiceInfo& remote_info,
103 service_manager::InterfaceRegistry* registry) { 111 service_manager::InterfaceRegistry* registry) {
104 registry->AddInterface<prefs::mojom::PreferencesManager>(this); 112 registry->AddInterface<prefs::mojom::PreferencesFactory>(this);
105 return true; 113 return true;
106 } 114 }
OLDNEW
« no previous file with comments | « chrome/browser/prefs/preferences_connection_manager.h ('k') | chrome/browser/prefs/preferences_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698