Split onc::IsRecommendedValue into onc_utils.cc
[chromium-blink-merge.git] / chrome / browser / chromeos / options / network_property_ui_data.cc
blob1371eace38d490be7c80c243aa144fb1ed1ab3e5
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/options/network_property_ui_data.h"
7 #include "base/logging.h"
8 #include "base/values.h"
9 #include "chromeos/network/onc/onc_utils.h"
11 namespace chromeos {
13 NetworkPropertyUIData::NetworkPropertyUIData()
14 : onc_source_(::onc::ONC_SOURCE_NONE) {
17 NetworkPropertyUIData::NetworkPropertyUIData(::onc::ONCSource onc_source)
18 : onc_source_(onc_source) {
21 NetworkPropertyUIData::~NetworkPropertyUIData() {
24 void NetworkPropertyUIData::ParseOncProperty(::onc::ONCSource onc_source,
25 const base::DictionaryValue* onc,
26 const std::string& property_key) {
27 default_value_.reset();
28 onc_source_ = onc_source;
30 if (!onc || !IsManaged())
31 return;
33 if (!onc::IsRecommendedValue(onc, property_key))
34 return;
36 // Set onc_source_ to NONE to indicate that the value is not enforced.
37 onc_source_ = ::onc::ONC_SOURCE_NONE;
39 const base::Value* default_value = NULL;
40 if (!onc->Get(property_key, &default_value)) {
41 // No default entry indicates that the property can be modified by the user,
42 // but has no default value, e.g. Username or Passphrase. (The default
43 // behavior for a property with no entry is non user modifiable).
44 return;
47 // Set the recommended (default) value.
48 default_value_.reset(default_value->DeepCopy());
51 } // namespace chromeos