1 // Copyright 2013 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.
5 #include "chrome/browser/chromeos/policy/device_network_configuration_updater.h"
8 #include "base/bind_helpers.h"
9 #include "chrome/browser/chromeos/settings/cros_settings.h"
10 #include "chromeos/network/managed_network_configuration_handler.h"
11 #include "chromeos/network/network_device_handler.h"
12 #include "chromeos/network/onc/onc_certificate_importer.h"
13 #include "chromeos/settings/cros_settings_names.h"
14 #include "chromeos/settings/cros_settings_provider.h"
15 #include "policy/policy_constants.h"
19 DeviceNetworkConfigurationUpdater::~DeviceNetworkConfigurationUpdater() {}
22 scoped_ptr
<DeviceNetworkConfigurationUpdater
>
23 DeviceNetworkConfigurationUpdater::CreateForDevicePolicy(
24 scoped_ptr
<chromeos::onc::CertificateImporter
> certificate_importer
,
25 PolicyService
* policy_service
,
26 chromeos::ManagedNetworkConfigurationHandler
* network_config_handler
,
27 chromeos::NetworkDeviceHandler
* network_device_handler
,
28 chromeos::CrosSettings
* cros_settings
) {
29 scoped_ptr
<DeviceNetworkConfigurationUpdater
> updater(
30 new DeviceNetworkConfigurationUpdater(certificate_importer
.Pass(),
32 network_config_handler
,
33 network_device_handler
,
36 return updater
.Pass();
39 DeviceNetworkConfigurationUpdater::DeviceNetworkConfigurationUpdater(
40 scoped_ptr
<chromeos::onc::CertificateImporter
> certificate_importer
,
41 PolicyService
* policy_service
,
42 chromeos::ManagedNetworkConfigurationHandler
* network_config_handler
,
43 chromeos::NetworkDeviceHandler
* network_device_handler
,
44 chromeos::CrosSettings
* cros_settings
)
45 : NetworkConfigurationUpdater(onc::ONC_SOURCE_DEVICE_POLICY
,
46 key::kDeviceOpenNetworkConfiguration
,
47 certificate_importer
.Pass(),
49 network_config_handler
),
50 network_device_handler_(network_device_handler
),
51 cros_settings_(cros_settings
),
53 DCHECK(network_device_handler_
);
54 data_roaming_setting_subscription_
= cros_settings
->AddSettingsObserver(
55 chromeos::kSignedDataRoamingEnabled
,
57 &DeviceNetworkConfigurationUpdater::OnDataRoamingSettingChanged
,
58 base::Unretained(this)));
61 void DeviceNetworkConfigurationUpdater::Init() {
62 NetworkConfigurationUpdater::Init();
64 // Apply the roaming setting initially.
65 OnDataRoamingSettingChanged();
68 void DeviceNetworkConfigurationUpdater::ImportCertificates(
69 const base::ListValue
& certificates_onc
) {
70 certificate_importer_
->ImportCertificates(
71 certificates_onc
, onc_source_
, NULL
);
74 void DeviceNetworkConfigurationUpdater::ApplyNetworkPolicy(
75 base::ListValue
* network_configs_onc
,
76 base::DictionaryValue
* global_network_config
) {
77 network_config_handler_
->SetPolicy(onc_source_
,
78 std::string() /* no username hash */,
80 *global_network_config
);
83 void DeviceNetworkConfigurationUpdater::OnDataRoamingSettingChanged() {
84 chromeos::CrosSettingsProvider::TrustedStatus trusted_status
=
85 cros_settings_
->PrepareTrustedValues(base::Bind(
86 &DeviceNetworkConfigurationUpdater::OnDataRoamingSettingChanged
,
87 weak_factory_
.GetWeakPtr()));
89 if (trusted_status
== chromeos::CrosSettingsProvider::TEMPORARILY_UNTRUSTED
) {
90 // Return, this function will be called again later by
91 // PrepareTrustedValues.
95 bool data_roaming_setting
= false;
96 if (trusted_status
== chromeos::CrosSettingsProvider::TRUSTED
) {
97 if (!cros_settings_
->GetBoolean(chromeos::kSignedDataRoamingEnabled
,
98 &data_roaming_setting
)) {
99 LOG(ERROR
) << "Couldn't get device setting "
100 << chromeos::kSignedDataRoamingEnabled
;
101 data_roaming_setting
= false;
104 DCHECK_EQ(trusted_status
,
105 chromeos::CrosSettingsProvider::PERMANENTLY_UNTRUSTED
);
106 // Roaming is disabled as we can't determine the correct setting.
109 network_device_handler_
->SetCellularAllowRoaming(data_roaming_setting
);
112 } // namespace policy