Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / chromeos / policy / consumer_enrollment_handler_factory.cc
blobbe40a02bc12027a086cd817e4a411bc77f355e25
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_enrollment_handler_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_enrollment_handler.h"
11 #include "chrome/browser/chromeos/policy/consumer_management_service.h"
12 #include "chrome/browser/chromeos/profiles/profile_helper.h"
13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
15 #include "chrome/browser/signin/signin_manager_factory.h"
16 #include "components/keyed_service/content/browser_context_dependency_manager.h"
17 #include "components/user_manager/user_manager.h"
19 namespace policy {
21 // static
22 ConsumerEnrollmentHandler*
23 ConsumerEnrollmentHandlerFactory::GetForBrowserContext(
24 content::BrowserContext* context) {
25 return static_cast<ConsumerEnrollmentHandler*>(
26 GetInstance()->GetServiceForBrowserContext(context, true));
29 // static
30 ConsumerEnrollmentHandlerFactory*
31 ConsumerEnrollmentHandlerFactory::GetInstance() {
32 return Singleton<ConsumerEnrollmentHandlerFactory>::get();
35 ConsumerEnrollmentHandlerFactory::ConsumerEnrollmentHandlerFactory()
36 : BrowserContextKeyedServiceFactory(
37 "ConsumerEnrollmentHandler",
38 BrowserContextDependencyManager::GetInstance()) {
39 DependsOn(ProfileOAuth2TokenServiceFactory::GetInstance());
40 DependsOn(SigninManagerFactory::GetInstance());
43 ConsumerEnrollmentHandlerFactory::~ConsumerEnrollmentHandlerFactory() {
46 KeyedService* ConsumerEnrollmentHandlerFactory::BuildServiceInstanceFor(
47 content::BrowserContext* context) const {
48 // Some tests don't have a user manager and may crash at IsOwnerProfile().
49 if (!user_manager::UserManager::IsInitialized())
50 return nullptr;
52 // On a fresh device, the first time the owner signs in, IsOwnerProfile()
53 // will return false. But it is okay since there's no enrollment in progress.
54 Profile* profile = Profile::FromBrowserContext(context);
55 if (!chromeos::ProfileHelper::IsOwnerProfile(profile))
56 return nullptr;
58 BrowserPolicyConnectorChromeOS* connector =
59 g_browser_process->platform_part()->browser_policy_connector_chromeos();
60 ConsumerManagementService* service =
61 connector->GetConsumerManagementService();
62 if (!service ||
63 service->GetStatus() != ConsumerManagementService::STATUS_ENROLLING) {
64 return nullptr;
67 return new ConsumerEnrollmentHandler(
68 profile,
69 service,
70 connector->GetDeviceManagementServiceForConsumer());
73 bool ConsumerEnrollmentHandlerFactory::ServiceIsCreatedWithBrowserContext()
74 const {
75 return true;
78 } // namespace policy