| 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_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 base::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 | |
| OLD | NEW |