blob: be40a02bc12027a086cd817e4a411bc77f355e25 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/chromeos/policy/consumer_enrollment_handler_factory.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/browser_process_platform_part.h"
#include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
#include "chrome/browser/chromeos/policy/consumer_enrollment_handler.h"
#include "chrome/browser/chromeos/policy/consumer_management_service.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
#include "chrome/browser/signin/signin_manager_factory.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/user_manager/user_manager.h"
namespace policy {
// static
ConsumerEnrollmentHandler*
ConsumerEnrollmentHandlerFactory::GetForBrowserContext(
content::BrowserContext* context) {
return static_cast<ConsumerEnrollmentHandler*>(
GetInstance()->GetServiceForBrowserContext(context, true));
}
// static
ConsumerEnrollmentHandlerFactory*
ConsumerEnrollmentHandlerFactory::GetInstance() {
return Singleton<ConsumerEnrollmentHandlerFactory>::get();
}
ConsumerEnrollmentHandlerFactory::ConsumerEnrollmentHandlerFactory()
: BrowserContextKeyedServiceFactory(
"ConsumerEnrollmentHandler",
BrowserContextDependencyManager::GetInstance()) {
DependsOn(ProfileOAuth2TokenServiceFactory::GetInstance());
DependsOn(SigninManagerFactory::GetInstance());
}
ConsumerEnrollmentHandlerFactory::~ConsumerEnrollmentHandlerFactory() {
}
KeyedService* ConsumerEnrollmentHandlerFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const {
// Some tests don't have a user manager and may crash at IsOwnerProfile().
if (!user_manager::UserManager::IsInitialized())
return nullptr;
// On a fresh device, the first time the owner signs in, IsOwnerProfile()
// will return false. But it is okay since there's no enrollment in progress.
Profile* profile = Profile::FromBrowserContext(context);
if (!chromeos::ProfileHelper::IsOwnerProfile(profile))
return nullptr;
BrowserPolicyConnectorChromeOS* connector =
g_browser_process->platform_part()->browser_policy_connector_chromeos();
ConsumerManagementService* service =
connector->GetConsumerManagementService();
if (!service ||
service->GetStatus() != ConsumerManagementService::STATUS_ENROLLING) {
return nullptr;
}
return new ConsumerEnrollmentHandler(
profile,
service,
connector->GetDeviceManagementServiceForConsumer());
}
bool ConsumerEnrollmentHandlerFactory::ServiceIsCreatedWithBrowserContext()
const {
return true;
}
} // namespace policy
|