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

Side by Side Diff: chrome/browser/chromeos/policy/consumer_management_notifier_factory.cc

Issue 733613005: Move the notification part out of ConsumerEnrollmentHandler so that it can be reused for unenrollme… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@enroll
Patch Set: Added a check for UserManager. Created 6 years, 1 month 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 2014 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/chromeos/policy/consumer_management_notifier_factory.h"
6
7 #include "chrome/browser/browser_process.h"
8 #include "chrome/browser/browser_process_platform_part.h"
9 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
10 #include "chrome/browser/chromeos/policy/consumer_management_notifier.h"
11 #include "chrome/browser/chromeos/profiles/profile_helper.h"
12 #include "chrome/browser/profiles/profile.h"
13 #include "components/keyed_service/content/browser_context_dependency_manager.h"
14 #include "components/user_manager/user_manager.h"
15
16 namespace policy {
17
18 // static
19 ConsumerManagementNotifier*
20 ConsumerManagementNotifierFactory::GetForBrowserContext(
21 content::BrowserContext* context) {
22 return static_cast<ConsumerManagementNotifier*>(
23 GetInstance()->GetServiceForBrowserContext(context, true));
24 }
25
26 // static
27 ConsumerManagementNotifierFactory*
28 ConsumerManagementNotifierFactory::GetInstance() {
29 return Singleton<ConsumerManagementNotifierFactory>::get();
30 }
31
32 ConsumerManagementNotifierFactory::ConsumerManagementNotifierFactory()
33 : BrowserContextKeyedServiceFactory(
34 "ConsumerManagementNotifier",
35 BrowserContextDependencyManager::GetInstance()) {
36 }
37
38 ConsumerManagementNotifierFactory::~ConsumerManagementNotifierFactory() {
39 }
40
41 KeyedService* ConsumerManagementNotifierFactory::BuildServiceInstanceFor(
42 content::BrowserContext* context) const {
43 // Some tests don't have a user manager and may crash at IsOwnerProfile().
44 if (!user_manager::UserManager::IsInitialized())
45 return nullptr;
46
47 // On a fresh device, the first time the owner signs in, IsOwnerProfile()
48 // will return false. But it is okay since there's no notification to show.
49 Profile* profile = Profile::FromBrowserContext(context);
50 if (!chromeos::ProfileHelper::IsOwnerProfile(profile))
51 return nullptr;
52
53 ConsumerManagementService* service =
54 g_browser_process->platform_part()->browser_policy_connector_chromeos()->
55 GetConsumerManagementService();
56 if (!service)
57 return nullptr;
58
59 return new ConsumerManagementNotifier(profile, service);
60 }
61
62 bool ConsumerManagementNotifierFactory::ServiceIsCreatedWithBrowserContext()
63 const {
64 return true;
65 }
66
67 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698