OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/chromeos/policy/consumer_enrollment_handler_factory.h" | 5 #include "chrome/browser/chromeos/policy/consumer_enrollment_handler_factory.h" |
6 | 6 |
7 #include "chrome/browser/browser_process.h" | 7 #include "chrome/browser/browser_process.h" |
8 #include "chrome/browser/browser_process_platform_part.h" | 8 #include "chrome/browser/browser_process_platform_part.h" |
9 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | 9 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
10 #include "chrome/browser/chromeos/policy/consumer_enrollment_handler.h" | 10 #include "chrome/browser/chromeos/policy/consumer_enrollment_handler.h" |
(...skipping 24 matching lines...) Expand all Loading... | |
35 : BrowserContextKeyedServiceFactory( | 35 : BrowserContextKeyedServiceFactory( |
36 "ConsumerEnrollmentHandler", | 36 "ConsumerEnrollmentHandler", |
37 BrowserContextDependencyManager::GetInstance()) { | 37 BrowserContextDependencyManager::GetInstance()) { |
38 DependsOn(ProfileOAuth2TokenServiceFactory::GetInstance()); | 38 DependsOn(ProfileOAuth2TokenServiceFactory::GetInstance()); |
39 DependsOn(SigninManagerFactory::GetInstance()); | 39 DependsOn(SigninManagerFactory::GetInstance()); |
40 } | 40 } |
41 | 41 |
42 ConsumerEnrollmentHandlerFactory::~ConsumerEnrollmentHandlerFactory() { | 42 ConsumerEnrollmentHandlerFactory::~ConsumerEnrollmentHandlerFactory() { |
43 } | 43 } |
44 | 44 |
45 bool ConsumerEnrollmentHandlerFactory::ShouldCreateHandler( | |
46 Profile* profile, | |
47 ConsumerManagementService* service) const { | |
48 if (!service) | |
49 return false; | |
50 | |
51 // On a fresh device, the first time the owner signs in, IsOwnerProfile() | |
52 // will return false. But it is okay since there's no enrollment in progress | |
53 // so we don't need to create a handler. | |
54 if (!chromeos::ProfileHelper::IsOwnerProfile(profile)) | |
55 return false; | |
56 | |
57 return service->GetStatus() == ConsumerManagementService::STATUS_ENROLLING || | |
58 service->HasPendingEnrollmentNotification(); | |
59 } | |
60 | |
61 KeyedService* ConsumerEnrollmentHandlerFactory::BuildServiceInstanceFor( | 45 KeyedService* ConsumerEnrollmentHandlerFactory::BuildServiceInstanceFor( |
62 content::BrowserContext* context) const { | 46 content::BrowserContext* context) const { |
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 enrollment in progress. | |
63 Profile* profile = Profile::FromBrowserContext(context); | 49 Profile* profile = Profile::FromBrowserContext(context); |
50 if (!chromeos::ProfileHelper::IsOwnerProfile(profile)) | |
51 return nullptr; | |
52 | |
64 BrowserPolicyConnectorChromeOS* connector = | 53 BrowserPolicyConnectorChromeOS* connector = |
65 g_browser_process->platform_part()->browser_policy_connector_chromeos(); | 54 g_browser_process->platform_part()->browser_policy_connector_chromeos(); |
66 ConsumerManagementService* service = | 55 ConsumerManagementService* service = |
67 connector->GetConsumerManagementService(); | 56 connector->GetConsumerManagementService(); |
57 if (!service) | |
58 return nullptr; | |
68 | 59 |
69 if (ShouldCreateHandler(profile, service)) { | 60 if (service->GetStatus() != ConsumerManagementService::STATUS_ENROLLING) |
Mattias Nissler (ping if slow)
2014/11/18 10:02:26
nit: could merge this conditional with the one in
davidyu
2014/11/19 02:54:21
Done.
| |
70 return new ConsumerEnrollmentHandler( | |
71 profile, | |
72 service, | |
73 connector->GetDeviceManagementServiceForConsumer()); | |
74 } else { | |
75 return nullptr; | 61 return nullptr; |
76 } | 62 |
63 return new ConsumerEnrollmentHandler( | |
64 profile, | |
65 service, | |
66 connector->GetDeviceManagementServiceForConsumer()); | |
77 } | 67 } |
78 | 68 |
79 bool ConsumerEnrollmentHandlerFactory::ServiceIsCreatedWithBrowserContext() | 69 bool ConsumerEnrollmentHandlerFactory::ServiceIsCreatedWithBrowserContext() |
80 const { | 70 const { |
81 return true; | 71 return true; |
82 } | 72 } |
83 | 73 |
84 } // namespace policy | 74 } // namespace policy |
OLD | NEW |