Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(144)

Side by Side Diff: chrome/browser/policy/network_configuration_updater.cc

Issue 12189011: Split up chrome/browser/policy subdirectory (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase, add chrome/browser/chromeos/policy/OWNERS Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 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/policy/network_configuration_updater.h"
6
7 #include <string>
8
9 #include "base/bind.h"
10 #include "base/bind_helpers.h"
11 #include "chrome/browser/chromeos/cros/network_library.h"
12 #include "chrome/browser/policy/policy_map.h"
13 #include "chromeos/network/onc/onc_constants.h"
14 #include "chromeos/network/onc/onc_utils.h"
15 #include "policy/policy_constants.h"
16
17 namespace policy {
18
19 NetworkConfigurationUpdater::NetworkConfigurationUpdater(
20 PolicyService* policy_service,
21 chromeos::NetworkLibrary* network_library)
22 : policy_change_registrar_(
23 policy_service, PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())),
24 network_library_(network_library),
25 user_policy_initialized_(false),
26 allow_web_trust_(false),
27 policy_service_(policy_service) {
28 DCHECK(network_library_);
29 policy_change_registrar_.Observe(
30 key::kDeviceOpenNetworkConfiguration,
31 base::Bind(&NetworkConfigurationUpdater::OnPolicyChanged,
32 base::Unretained(this),
33 chromeos::onc::ONC_SOURCE_DEVICE_POLICY));
34 policy_change_registrar_.Observe(
35 key::kOpenNetworkConfiguration,
36 base::Bind(&NetworkConfigurationUpdater::OnPolicyChanged,
37 base::Unretained(this),
38 chromeos::onc::ONC_SOURCE_USER_POLICY));
39
40 network_library_->AddNetworkProfileObserver(this);
41
42 // Apply the current policies immediately.
43 ApplyNetworkConfigurations();
44 }
45
46 NetworkConfigurationUpdater::~NetworkConfigurationUpdater() {
47 network_library_->RemoveNetworkProfileObserver(this);
48 }
49
50 void NetworkConfigurationUpdater::OnProfileListChanged() {
51 VLOG(1) << "Network profile list changed, applying policies.";
52 ApplyNetworkConfigurations();
53 }
54
55 void NetworkConfigurationUpdater::OnUserPolicyInitialized() {
56 VLOG(1) << "User policy initialized, applying policies.";
57 user_policy_initialized_ = true;
58 ApplyNetworkConfigurations();
59 }
60
61 void NetworkConfigurationUpdater::OnPolicyChanged(
62 chromeos::onc::ONCSource onc_source,
63 const base::Value* previous,
64 const base::Value* current) {
65 VLOG(1) << "Policy for ONC source "
66 << chromeos::onc::GetSourceAsString(onc_source) << " changed.";
67 ApplyNetworkConfigurations();
68 }
69
70 void NetworkConfigurationUpdater::ApplyNetworkConfigurations() {
71 ApplyNetworkConfiguration(key::kDeviceOpenNetworkConfiguration,
72 chromeos::onc::ONC_SOURCE_DEVICE_POLICY);
73 if (user_policy_initialized_) {
74 ApplyNetworkConfiguration(key::kOpenNetworkConfiguration,
75 chromeos::onc::ONC_SOURCE_USER_POLICY);
76 }
77 }
78
79 void NetworkConfigurationUpdater::ApplyNetworkConfiguration(
80 const std::string& policy_key,
81 chromeos::onc::ONCSource onc_source) {
82 VLOG(1) << "Apply policy for ONC source "
83 << chromeos::onc::GetSourceAsString(onc_source);
84 const PolicyMap& policies = policy_service_->GetPolicies(
85 PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()));
86 const base::Value* policy_value = policies.GetValue(policy_key);
87
88 std::string new_network_config;
89 if (policy_value != NULL) {
90 // If the policy is not a string, we issue a warning, but still clear the
91 // network configuration.
92 if (!policy_value->GetAsString(&new_network_config)) {
93 LOG(WARNING) << "ONC policy for source "
94 << chromeos::onc::GetSourceAsString(onc_source)
95 << " is not a string value.";
96 }
97 }
98
99 // An empty string is not a valid ONC and generates warnings and
100 // errors. Replace by a valid empty configuration.
101 if (new_network_config.empty())
102 new_network_config = chromeos::onc::kEmptyUnencryptedConfiguration;
103
104 if (!network_library_->LoadOncNetworks(new_network_config, "", onc_source,
105 allow_web_trust_)) {
106 LOG(ERROR) << "Errors occurred during the ONC policy application.";
107 }
108 }
109
110 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/policy/network_configuration_updater.h ('k') | chrome/browser/policy/network_configuration_updater_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698