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

Side by Side Diff: chrome/browser/chromeos/policy/network_configuration_updater_impl.cc

Issue 12676017: Adding policy support to the new network configuration stack. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed remaining comments of Steven. Created 7 years, 8 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) 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.
4
5 #include "chrome/browser/chromeos/policy/network_configuration_updater_impl.h"
6
7 #include <string>
8
9 #include "base/bind.h"
10 #include "base/bind_helpers.h"
11 #include "base/debug/stack_trace.h"
12 #include "chrome/browser/policy/policy_map.h"
13 #include "chromeos/network/managed_network_configuration_handler.h"
14 #include "chromeos/network/onc/onc_utils.h"
15 #include "policy/policy_constants.h"
16
17 namespace policy {
18
19 NetworkConfigurationUpdaterImpl::NetworkConfigurationUpdaterImpl(
20 PolicyService* policy_service)
21 : user_policy_initialized_(false),
22 policy_change_registrar_(
23 policy_service, PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())),
24 policy_service_(policy_service) {
25 policy_change_registrar_.Observe(
26 key::kDeviceOpenNetworkConfiguration,
27 base::Bind(&NetworkConfigurationUpdaterImpl::OnPolicyChanged,
28 base::Unretained(this),
29 chromeos::onc::ONC_SOURCE_DEVICE_POLICY));
30 policy_change_registrar_.Observe(
31 key::kOpenNetworkConfiguration,
32 base::Bind(&NetworkConfigurationUpdaterImpl::OnPolicyChanged,
33 base::Unretained(this),
34 chromeos::onc::ONC_SOURCE_USER_POLICY));
35 }
36
37 NetworkConfigurationUpdaterImpl::~NetworkConfigurationUpdaterImpl() {
38 }
39
40 void NetworkConfigurationUpdaterImpl::OnUserPolicyInitialized() {
41 VLOG(1) << "User policy initialized.";
42 user_policy_initialized_ = true;
43 ApplyNetworkConfiguration(chromeos::onc::ONC_SOURCE_USER_POLICY);
44 }
45
46 void NetworkConfigurationUpdaterImpl::OnPolicyChanged(
47 chromeos::onc::ONCSource onc_source,
48 const base::Value* previous,
49 const base::Value* current) {
50 VLOG(1) << "Policy for ONC source "
51 << chromeos::onc::GetSourceAsString(onc_source) << " changed.";
52 VLOG(2) << "User policy is " << (user_policy_initialized_ ? "" : "not ")
53 << "initialized.";
54 ApplyNetworkConfiguration(onc_source);
55 }
56
57 void NetworkConfigurationUpdaterImpl::ApplyNetworkConfiguration(
58 chromeos::onc::ONCSource onc_source) {
59 VLOG(1) << "Apply policy for ONC source "
60 << chromeos::onc::GetSourceAsString(onc_source);
61
62 std::string policy_key;
63 if (onc_source == chromeos::onc::ONC_SOURCE_USER_POLICY)
64 policy_key = key::kOpenNetworkConfiguration;
65 else
66 policy_key = key::kDeviceOpenNetworkConfiguration;
67
68 const PolicyMap& policies = policy_service_->GetPolicies(
69 PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()));
70 const base::Value* policy_value = policies.GetValue(policy_key);
71
72 if (!policy_value) {
73 VLOG(1) << "The policy value is NULL. Aborting.";
74 return;
75 }
76
77 std::string onc_blob;
78 if (!policy_value->GetAsString(&onc_blob)) {
79 LOG(ERROR) << "ONC policy " << policy_key << " is not a string value.";
80 return;
81 }
82 VLOG(2) << "The policy contains this ONC: " << onc_blob;
83
84 if (onc_blob.empty())
85 onc_blob = chromeos::onc::kEmptyUnencryptedConfiguration;
86
87 scoped_ptr<base::DictionaryValue> onc_dict =
88 chromeos::onc::ReadDictionaryFromJson(onc_blob);
89 if (!onc_dict) {
90 LOG(ERROR) << "ONC loaded from policy " << policy_key
91 << " is not a valid JSON dictionary.";
92 return;
93 }
94
95 chromeos::ManagedNetworkConfigurationHandler::Get()->SetPolicy(onc_source,
96 *onc_dict);
97 }
98
99 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698