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

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

Issue 2474653003: PreferencesManager (Closed)
Patch Set: Address Review Comments Created 4 years 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
(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)))) {}
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();
66 }
67
68 profile_shutdown_notification_.reset();
69 }
70
71 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698