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.
5 #include "chrome/browser/chromeos/policy/consumer_management_notifier_factory.h"
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"
19 ConsumerManagementNotifier
*
20 ConsumerManagementNotifierFactory::GetForBrowserContext(
21 content::BrowserContext
* context
) {
22 return static_cast<ConsumerManagementNotifier
*>(
23 GetInstance()->GetServiceForBrowserContext(context
, true));
27 ConsumerManagementNotifierFactory
*
28 ConsumerManagementNotifierFactory::GetInstance() {
29 return base::Singleton
<ConsumerManagementNotifierFactory
>::get();
32 ConsumerManagementNotifierFactory::ConsumerManagementNotifierFactory()
33 : BrowserContextKeyedServiceFactory(
34 "ConsumerManagementNotifier",
35 BrowserContextDependencyManager::GetInstance()) {
38 ConsumerManagementNotifierFactory::~ConsumerManagementNotifierFactory() {
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())
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
))
53 ConsumerManagementService
* service
=
54 g_browser_process
->platform_part()->browser_policy_connector_chromeos()->
55 GetConsumerManagementService();
59 return new ConsumerManagementNotifier(profile
, service
);
62 bool ConsumerManagementNotifierFactory::ServiceIsCreatedWithBrowserContext()