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

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

Issue 11299236: This moves the ONC parsing code into chromeos/network/onc (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix unit tests Created 8 years 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/policy/configuration_policy_handler_chromeos.h" 5 #include "chrome/browser/policy/configuration_policy_handler_chromeos.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/json/json_reader.h" 9 #include "base/json/json_reader.h"
10 #include "base/json/json_writer.h" 10 #include "base/json/json_writer.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/prefs/pref_value_map.h" 12 #include "base/prefs/pref_value_map.h"
13 #include "base/string_util.h" 13 #include "base/string_util.h"
14 #include "base/values.h" 14 #include "base/values.h"
15 #include "chrome/browser/chromeos/cros/onc_constants.h"
16 #include "chrome/browser/chromeos/network_settings/onc_signature.h"
17 #include "chrome/browser/chromeos/network_settings/onc_utils.h"
18 #include "chrome/browser/chromeos/network_settings/onc_validator.h"
19 #include "chrome/browser/policy/policy_error_map.h" 15 #include "chrome/browser/policy/policy_error_map.h"
20 #include "chrome/browser/policy/policy_map.h" 16 #include "chrome/browser/policy/policy_map.h"
21 #include "chrome/browser/ui/ash/chrome_launcher_prefs.h" 17 #include "chrome/browser/ui/ash/chrome_launcher_prefs.h"
22 #include "chrome/common/pref_names.h" 18 #include "chrome/common/pref_names.h"
19 #include "chromeos/network/onc/onc_constants.h"
20 #include "chromeos/network/onc/onc_signature.h"
21 #include "chromeos/network/onc/onc_utils.h"
22 #include "chromeos/network/onc/onc_validator.h"
23 #include "grit/generated_resources.h" 23 #include "grit/generated_resources.h"
24 #include "policy/policy_constants.h" 24 #include "policy/policy_constants.h"
25 25
26 namespace onc = chromeos::onc; 26 namespace onc = chromeos::onc;
27 27
28 namespace { 28 namespace {
29 29
30 } // namespace 30 } // namespace
31 31
32 namespace policy { 32 namespace policy {
33 33
34 NetworkConfigurationPolicyHandler::NetworkConfigurationPolicyHandler( 34 NetworkConfigurationPolicyHandler::NetworkConfigurationPolicyHandler(
35 const char* policy_name, 35 const char* policy_name,
36 chromeos::NetworkUIData::ONCSource onc_source) 36 chromeos::onc::ONCSource onc_source)
37 : TypeCheckingPolicyHandler(policy_name, base::Value::TYPE_STRING), 37 : TypeCheckingPolicyHandler(policy_name, base::Value::TYPE_STRING),
38 onc_source_(onc_source) {} 38 onc_source_(onc_source) {}
39 39
40 NetworkConfigurationPolicyHandler::~NetworkConfigurationPolicyHandler() {} 40 NetworkConfigurationPolicyHandler::~NetworkConfigurationPolicyHandler() {}
41 41
42 bool NetworkConfigurationPolicyHandler::CheckPolicySettings( 42 bool NetworkConfigurationPolicyHandler::CheckPolicySettings(
43 const PolicyMap& policies, 43 const PolicyMap& policies,
44 PolicyErrorMap* errors) { 44 PolicyErrorMap* errors) {
45 const base::Value* value; 45 const base::Value* value;
46 if (!CheckAndGetValue(policies, errors, &value)) 46 if (!CheckAndGetValue(policies, errors, &value))
47 return false; 47 return false;
48 48
49 if (value) { 49 if (value) {
50 std::string onc_blob; 50 std::string onc_blob;
51 value->GetAsString(&onc_blob); 51 value->GetAsString(&onc_blob);
52 std::string json_error;
53 scoped_ptr<base::DictionaryValue> root_dict = 52 scoped_ptr<base::DictionaryValue> root_dict =
54 onc::ReadDictionaryFromJson(onc_blob, &json_error); 53 onc::ReadDictionaryFromJson(onc_blob);
55 if (root_dict.get() == NULL) { 54 if (root_dict.get() == NULL) {
56 errors->AddError(policy_name(), IDS_POLICY_NETWORK_CONFIG_PARSE_ERROR, 55 errors->AddError(policy_name(), IDS_POLICY_NETWORK_CONFIG_PARSE_ERROR);
57 json_error);
58 return false; 56 return false;
59 } 57 }
60 58
61 // Validate the ONC dictionary. We are liberal and ignore unknown field 59 // Validate the ONC dictionary. We are liberal and ignore unknown field
62 // names and ignore invalid field names in kRecommended arrays. 60 // names and ignore invalid field names in kRecommended arrays.
63 onc::Validator validator(false, // Ignore unknown fields. 61 onc::Validator validator(false, // Ignore unknown fields.
64 false, // Ignore invalid recommended field names. 62 false, // Ignore invalid recommended field names.
65 true, // Fail on missing fields. 63 true, // Fail on missing fields.
66 true); // Validate for managed ONC 64 true); // Validate for managed ONC
67 65
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 base::DictionaryValue* app_dict = new base::DictionaryValue(); 193 base::DictionaryValue* app_dict = new base::DictionaryValue();
196 app_dict->SetString(ash::kPinnedAppsPrefAppIDPath, id); 194 app_dict->SetString(ash::kPinnedAppsPrefAppIDPath, id);
197 pinned_apps_list->Append(app_dict); 195 pinned_apps_list->Append(app_dict);
198 } 196 }
199 } 197 }
200 prefs->SetValue(pref_path(), pinned_apps_list); 198 prefs->SetValue(pref_path(), pinned_apps_list);
201 } 199 }
202 } 200 }
203 201
204 } // namespace policy 202 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698