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 "chrome/browser/prefs/preferences_manager.h" | |
8 #include "chrome/browser/profiles/profile.h" | |
9 #include "chrome/browser/profiles/profile_manager.h" | |
10 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | |
11 #include "components/keyed_service/content/browser_context_keyed_service_shutdow n_notifier_factory.h" | |
12 | |
13 namespace { | |
14 | |
15 // Required singleton subclass to control dependencies between | |
16 // PreferenceConnectionManager and the KeyedServiceShutdownNotifier. | |
17 class ShutdownNotifierFactory | |
18 : public BrowserContextKeyedServiceShutdownNotifierFactory { | |
19 public: | |
20 static ShutdownNotifierFactory* GetInstance() { | |
21 return base::Singleton<ShutdownNotifierFactory>::get(); | |
22 } | |
23 | |
24 private: | |
25 friend struct base::DefaultSingletonTraits<ShutdownNotifierFactory>; | |
26 | |
27 ShutdownNotifierFactory() | |
28 : BrowserContextKeyedServiceShutdownNotifierFactory( | |
29 "PreferencesConnectionManager") { | |
30 DependsOn(ProfileOAuth2TokenServiceFactory::GetInstance()); | |
31 } | |
32 ~ShutdownNotifierFactory() override {} | |
33 | |
34 DISALLOW_COPY_AND_ASSIGN(ShutdownNotifierFactory); | |
35 }; | |
36 | |
37 } // namespace | |
38 | |
39 namespace chrome { | |
40 | |
41 PreferencesConnectionManager::PreferencesConnectionManager() | |
42 : profile_shutdown_notification_( | |
43 ShutdownNotifierFactory::GetInstance() | |
44 ->Get(ProfileManager::GetActiveUserProfile()) | |
45 ->Subscribe( | |
46 base::Bind(&PreferencesConnectionManager::OnProfileDestroyed, | |
47 base::Unretained(this)))) {} | |
sadrul
2016/11/29 17:25:49
Since you are using Unretained(this) to create the
jonross
2016/11/30 01:01:31
|profile_shutdown_notification_| does that deep wi
| |
48 | |
49 PreferencesConnectionManager::~PreferencesConnectionManager() {} | |
50 | |
51 void PreferencesConnectionManager::ProcessRequest( | |
52 prefs::mojom::PreferencesManagerRequest request) { | |
53 Profile* profile = ProfileManager::GetActiveUserProfile(); | |
54 mojo::StrongBindingPtr<prefs::mojom::PreferencesManager> binding = | |
55 mojo::MakeStrongBinding(base::MakeUnique<PreferencesManager>(profile), | |
56 std::move(request)); | |
57 bindings_.push_back(binding); | |
58 } | |
59 | |
60 void PreferencesConnectionManager::OnProfileDestroyed() { | |
61 for (auto& it : bindings_) { | |
62 // Check that the PreferencesManager was not cleared from a connection | |
63 // error. | |
64 if (it) | |
65 (static_cast<PreferencesManager*>(it->impl()))->OnProfileDestroyed(); | |
sadrul
2016/11/29 17:25:49
Not a huge fan of the static_cast<>ing. Can Prefer
jonross
2016/11/30 01:01:31
This isn't for clearing out the bindings_, the Str
| |
66 } | |
67 | |
68 profile_shutdown_notification_.reset(); | |
69 } | |
70 | |
71 } // namespace chrome | |
OLD | NEW |