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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
|
// 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/browser_policy_connector_chromeos.h"
#include <string>
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/logging.h"
#include "base/message_loop/message_loop_proxy.h"
#include "base/path_service.h"
#include "base/prefs/pref_registry_simple.h"
#include "base/sequenced_task_runner.h"
#include "base/strings/utf_string_conversions.h"
#include "base/threading/sequenced_worker_pool.h"
#include "chrome/browser/chromeos/policy/app_pack_updater.h"
#include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h"
#include "chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos.h"
#include "chrome/browser/chromeos/policy/device_local_account.h"
#include "chrome/browser/chromeos/policy/device_local_account_policy_service.h"
#include "chrome/browser/chromeos/policy/device_network_configuration_updater.h"
#include "chrome/browser/chromeos/policy/device_status_collector.h"
#include "chrome/browser/chromeos/policy/enterprise_install_attributes.h"
#include "chrome/browser/chromeos/policy/server_backed_state_keys_broker.h"
#include "chrome/browser/chromeos/settings/cros_settings.h"
#include "chrome/browser/chromeos/settings/device_settings_service.h"
#include "chrome/browser/policy/device_management_service_configuration.h"
#include "chrome/common/pref_names.h"
#include "chromeos/chromeos_paths.h"
#include "chromeos/chromeos_switches.h"
#include "chromeos/cryptohome/system_salt_getter.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/network/network_handler.h"
#include "chromeos/network/onc/onc_certificate_importer_impl.h"
#include "chromeos/settings/cros_settings_names.h"
#include "chromeos/settings/cros_settings_provider.h"
#include "chromeos/settings/timezone_settings.h"
#include "chromeos/system/statistics_provider.h"
#include "components/policy/core/common/cloud/cloud_policy_client.h"
#include "components/policy/core/common/cloud/cloud_policy_refresh_scheduler.h"
#include "components/policy/core/common/proxy_policy_provider.h"
#include "content/public/browser/browser_thread.h"
#include "google_apis/gaia/gaia_auth_util.h"
#include "net/url_request/url_request_context_getter.h"
using content::BrowserThread;
namespace policy {
namespace {
// TODO(davidyu): Update the URL to the real one once it is ready.
// http://crbug.com/366491.
//
// The URL for the consumer device management server.
const char kDefaultConsumerDeviceManagementServerUrl[] =
"https://m.google.com/devicemanagement/data/api";
// Install attributes for tests.
EnterpriseInstallAttributes* g_testing_install_attributes = NULL;
// Helper that returns a new SequencedTaskRunner backed by the blocking pool.
// Each SequencedTaskRunner returned is independent from the others.
scoped_refptr<base::SequencedTaskRunner> GetBackgroundTaskRunner() {
base::SequencedWorkerPool* pool = BrowserThread::GetBlockingPool();
CHECK(pool);
return pool->GetSequencedTaskRunnerWithShutdownBehavior(
pool->GetSequenceToken(), base::SequencedWorkerPool::SKIP_ON_SHUTDOWN);
}
std::string GetConsumerDeviceManagementServerUrl() {
const CommandLine* command_line = CommandLine::ForCurrentProcess();
if (command_line->HasSwitch(
chromeos::switches::kConsumerDeviceManagementUrl)) {
return command_line->GetSwitchValueASCII(
chromeos::switches::kConsumerDeviceManagementUrl);
}
return kDefaultConsumerDeviceManagementServerUrl;
};
} // namespace
BrowserPolicyConnectorChromeOS::BrowserPolicyConnectorChromeOS()
: device_cloud_policy_manager_(NULL),
global_user_cloud_policy_provider_(NULL),
weak_ptr_factory_(this) {
if (g_testing_install_attributes) {
install_attributes_.reset(g_testing_install_attributes);
g_testing_install_attributes = NULL;
}
// SystemSaltGetter or DBusThreadManager may be uninitialized on unit tests.
// TODO(satorux): Remove SystemSaltGetter::IsInitialized() when it's ready
// (removing it now breaks tests). crbug.com/141016.
if (chromeos::SystemSaltGetter::IsInitialized() &&
chromeos::DBusThreadManager::IsInitialized()) {
state_keys_broker_.reset(new ServerBackedStateKeysBroker(
chromeos::DBusThreadManager::Get()->GetSessionManagerClient(),
base::MessageLoopProxy::current()));
chromeos::CryptohomeClient* cryptohome_client =
chromeos::DBusThreadManager::Get()->GetCryptohomeClient();
if (!install_attributes_) {
install_attributes_.reset(
new EnterpriseInstallAttributes(cryptohome_client));
}
base::FilePath install_attrs_file;
CHECK(PathService::Get(chromeos::FILE_INSTALL_ATTRIBUTES,
&install_attrs_file));
install_attributes_->ReadCacheFile(install_attrs_file);
scoped_ptr<DeviceCloudPolicyStoreChromeOS> device_cloud_policy_store(
new DeviceCloudPolicyStoreChromeOS(
chromeos::DeviceSettingsService::Get(),
install_attributes_.get(),
GetBackgroundTaskRunner()));
device_cloud_policy_manager_ =
new DeviceCloudPolicyManagerChromeOS(device_cloud_policy_store.Pass(),
base::MessageLoopProxy::current(),
GetBackgroundTaskRunner(),
install_attributes_.get(),
state_keys_broker_.get());
AddPolicyProvider(
scoped_ptr<ConfigurationPolicyProvider>(device_cloud_policy_manager_));
}
global_user_cloud_policy_provider_ = new ProxyPolicyProvider();
AddPolicyProvider(scoped_ptr<ConfigurationPolicyProvider>(
global_user_cloud_policy_provider_));
}
BrowserPolicyConnectorChromeOS::~BrowserPolicyConnectorChromeOS() {}
void BrowserPolicyConnectorChromeOS::Init(
PrefService* local_state,
scoped_refptr<net::URLRequestContextGetter> request_context) {
ChromeBrowserPolicyConnector::Init(local_state, request_context);
scoped_ptr<DeviceManagementService::Configuration> configuration(
new DeviceManagementServiceConfiguration(
GetConsumerDeviceManagementServerUrl()));
consumer_device_management_service_.reset(
new DeviceManagementService(configuration.Pass()));
consumer_device_management_service_->ScheduleInitialization(
kServiceInitializationStartupDelay);
if (device_cloud_policy_manager_) {
// Note: for now the |device_cloud_policy_manager_| is using the global
// schema registry. Eventually it will have its own registry, once device
// cloud policy for extensions is introduced. That means it'd have to be
// initialized from here instead of BrowserPolicyConnector::Init().
scoped_ptr<CloudPolicyClient::StatusProvider> status_provider(
new DeviceStatusCollector(
local_state,
chromeos::system::StatisticsProvider::GetInstance(),
NULL));
device_cloud_policy_manager_->Connect(
local_state, device_management_service(), status_provider.Pass());
}
device_local_account_policy_service_.reset(
new DeviceLocalAccountPolicyService(
chromeos::DBusThreadManager::Get()->GetSessionManagerClient(),
chromeos::DeviceSettingsService::Get(),
chromeos::CrosSettings::Get(),
GetBackgroundTaskRunner(),
GetBackgroundTaskRunner(),
GetBackgroundTaskRunner(),
content::BrowserThread::GetMessageLoopProxyForThread(
content::BrowserThread::IO),
request_context));
device_local_account_policy_service_->Connect(device_management_service());
// request_context is NULL in unit tests.
if (request_context && install_attributes_) {
app_pack_updater_.reset(
new AppPackUpdater(request_context, install_attributes_.get()));
}
SetTimezoneIfPolicyAvailable();
network_configuration_updater_ =
DeviceNetworkConfigurationUpdater::CreateForDevicePolicy(
GetPolicyService(),
chromeos::NetworkHandler::Get()
->managed_network_configuration_handler(),
chromeos::NetworkHandler::Get()->network_device_handler(),
chromeos::CrosSettings::Get());
}
void BrowserPolicyConnectorChromeOS::Shutdown() {
// The AppPackUpdater may be observing the |device_cloud_policy_manager_|.
// Delete it first.
app_pack_updater_.reset();
network_configuration_updater_.reset();
if (device_local_account_policy_service_)
device_local_account_policy_service_->Shutdown();
ChromeBrowserPolicyConnector::Shutdown();
}
bool BrowserPolicyConnectorChromeOS::IsEnterpriseManaged() {
return install_attributes_ && install_attributes_->IsEnterpriseDevice();
}
std::string BrowserPolicyConnectorChromeOS::GetEnterpriseDomain() {
return install_attributes_ ? install_attributes_->GetDomain() : std::string();
}
DeviceMode BrowserPolicyConnectorChromeOS::GetDeviceMode() {
return install_attributes_ ? install_attributes_->GetMode()
: DEVICE_MODE_NOT_SET;
}
UserAffiliation BrowserPolicyConnectorChromeOS::GetUserAffiliation(
const std::string& user_name) {
// An empty username means incognito user in case of ChromiumOS and
// no logged-in user in case of Chromium (SigninService). Many tests use
// nonsense email addresses (e.g. 'test') so treat those as non-enterprise
// users.
if (user_name.empty() || user_name.find('@') == std::string::npos)
return USER_AFFILIATION_NONE;
if (install_attributes_ &&
(gaia::ExtractDomainName(gaia::CanonicalizeEmail(user_name)) ==
install_attributes_->GetDomain() ||
policy::IsDeviceLocalAccountUser(user_name, NULL))) {
return USER_AFFILIATION_MANAGED;
}
return USER_AFFILIATION_NONE;
}
AppPackUpdater* BrowserPolicyConnectorChromeOS::GetAppPackUpdater() {
return app_pack_updater_.get();
}
void BrowserPolicyConnectorChromeOS::SetUserPolicyDelegate(
ConfigurationPolicyProvider* user_policy_provider) {
global_user_cloud_policy_provider_->SetDelegate(user_policy_provider);
}
void BrowserPolicyConnectorChromeOS::SetInstallAttributesForTesting(
EnterpriseInstallAttributes* attributes) {
DCHECK(!g_testing_install_attributes);
g_testing_install_attributes = attributes;
}
void BrowserPolicyConnectorChromeOS::RemoveInstallAttributesForTesting() {
if (g_testing_install_attributes) {
delete g_testing_install_attributes;
g_testing_install_attributes = NULL;
}
}
// static
void BrowserPolicyConnectorChromeOS::RegisterPrefs(
PrefRegistrySimple* registry) {
registry->RegisterIntegerPref(
prefs::kDevicePolicyRefreshRate,
CloudPolicyRefreshScheduler::kDefaultRefreshDelayMs);
}
void BrowserPolicyConnectorChromeOS::SetTimezoneIfPolicyAvailable() {
typedef chromeos::CrosSettingsProvider Provider;
Provider::TrustedStatus result =
chromeos::CrosSettings::Get()->PrepareTrustedValues(base::Bind(
&BrowserPolicyConnectorChromeOS::SetTimezoneIfPolicyAvailable,
weak_ptr_factory_.GetWeakPtr()));
if (result != Provider::TRUSTED)
return;
std::string timezone;
if (chromeos::CrosSettings::Get()->GetString(chromeos::kSystemTimezonePolicy,
&timezone) &&
!timezone.empty()) {
chromeos::system::TimezoneSettings::GetInstance()->SetTimezoneFromID(
base::UTF8ToUTF16(timezone));
}
}
} // namespace policy
|