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 PreferencesConnectionManager::PreferencesConnectionManager() | |
40 : profile_shutdown_notification_( | |
41 ShutdownNotifierFactory::GetInstance() | |
42 ->Get(ProfileManager::GetActiveUserProfile()) | |
43 ->Subscribe( | |
44 base::Bind(&PreferencesConnectionManager::OnProfileDestroyed, | |
45 base::Unretained(this)))) {} | |
46 | |
47 PreferencesConnectionManager::~PreferencesConnectionManager() {} | |
48 | |
49 void PreferencesConnectionManager::ProcessRequest( | |
50 prefs::mojom::PreferencesManagerRequest request) { | |
51 Profile* profile = ProfileManager::GetActiveUserProfile(); | |
52 mojo::StrongBindingPtr<prefs::mojom::PreferencesManager> binding = | |
53 mojo::MakeStrongBinding(base::MakeUnique<PreferencesManager>(profile), | |
54 std::move(request)); | |
55 bindings_.push_back(std::move(binding)); | |
56 } | |
57 | |
58 void PreferencesConnectionManager::OnProfileDestroyed() { | |
59 for (auto& it : bindings_) { | |
60 // Check that the PreferencesManager was not cleared from a connection | |
sky
2016/12/07 23:54:25
This description doesn't really match what happens
jonross
2016/12/08 01:03:19
Maybe tweak the wording? As its possible that arri
dcheng
2016/12/08 23:13:01
Maybe just "shut down any preference managers that
jonross
2016/12/08 23:32:55
I'll switch to the cleaner doc you suggest.
I wen
dcheng
2016/12/09 05:26:41
It feels a bit inelegant, since dead weak pointers
jonross
2016/12/09 16:49:16
Yeah I agree if that.
I've filed crbug.com/672881
| |
61 // error. Then close the connection. | |
62 if (it) | |
63 it->Close(); | |
64 } | |
65 | |
66 profile_shutdown_notification_.reset(); | |
67 } | |
OLD | NEW |