| OLD | NEW |
| (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_enrollment_handler_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_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" | |
| 18 | |
| 19 namespace policy { | |
| 20 | |
| 21 // static | |
| 22 ConsumerEnrollmentHandler* | |
| 23 ConsumerEnrollmentHandlerFactory::GetForBrowserContext( | |
| 24 content::BrowserContext* context) { | |
| 25 return static_cast<ConsumerEnrollmentHandler*>( | |
| 26 GetInstance()->GetServiceForBrowserContext(context, true)); | |
| 27 } | |
| 28 | |
| 29 // static | |
| 30 ConsumerEnrollmentHandlerFactory* | |
| 31 ConsumerEnrollmentHandlerFactory::GetInstance() { | |
| 32 return base::Singleton<ConsumerEnrollmentHandlerFactory>::get(); | |
| 33 } | |
| 34 | |
| 35 ConsumerEnrollmentHandlerFactory::ConsumerEnrollmentHandlerFactory() | |
| 36 : BrowserContextKeyedServiceFactory( | |
| 37 "ConsumerEnrollmentHandler", | |
| 38 BrowserContextDependencyManager::GetInstance()) { | |
| 39 DependsOn(ProfileOAuth2TokenServiceFactory::GetInstance()); | |
| 40 DependsOn(SigninManagerFactory::GetInstance()); | |
| 41 } | |
| 42 | |
| 43 ConsumerEnrollmentHandlerFactory::~ConsumerEnrollmentHandlerFactory() { | |
| 44 } | |
| 45 | |
| 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; | |
| 51 | |
| 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; | |
| 57 | |
| 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; | |
| 65 } | |
| 66 | |
| 67 return new ConsumerEnrollmentHandler( | |
| 68 profile, | |
| 69 service, | |
| 70 connector->GetDeviceManagementServiceForConsumer()); | |
| 71 } | |
| 72 | |
| 73 bool ConsumerEnrollmentHandlerFactory::ServiceIsCreatedWithBrowserContext() | |
| 74 const { | |
| 75 return true; | |
| 76 } | |
| 77 | |
| 78 } // namespace policy | |
| OLD | NEW |