| OLD | NEW |
| 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/chromeos/cros/network_property_ui_data.h" | 5 #include "chrome/browser/chromeos/cros/network_property_ui_data.h" |
| 6 | 6 |
| 7 #include "base/values.h" | 7 #include "base/values.h" |
| 8 #include "chromeos/network/network_ui_data.h" | |
| 9 | 8 |
| 10 namespace chromeos { | 9 namespace chromeos { |
| 11 | 10 |
| 12 // Property names for the per-property dictionary. | |
| 13 const char NetworkPropertyUIData::kKeyController[] = "controller"; | |
| 14 const char NetworkPropertyUIData::kKeyDefaultValue[] = "default_value"; | |
| 15 | |
| 16 NetworkPropertyUIData::NetworkPropertyUIData() | 11 NetworkPropertyUIData::NetworkPropertyUIData() |
| 17 : controller_(CONTROLLER_USER) { | 12 : onc_source_(onc::ONC_SOURCE_NONE) { |
| 18 } | 13 } |
| 19 | 14 |
| 20 NetworkPropertyUIData::~NetworkPropertyUIData() { | 15 NetworkPropertyUIData::~NetworkPropertyUIData() { |
| 21 } | 16 } |
| 22 | 17 |
| 23 NetworkPropertyUIData::NetworkPropertyUIData( | 18 NetworkPropertyUIData::NetworkPropertyUIData( |
| 24 const NetworkUIData& ui_data) { | 19 onc::ONCSource onc_source) { |
| 25 Reset(ui_data); | 20 Reset(onc_source); |
| 26 } | 21 } |
| 27 | 22 |
| 28 void NetworkPropertyUIData::Reset(const NetworkUIData& ui_data) { | 23 void NetworkPropertyUIData::Reset(onc::ONCSource onc_source) { |
| 29 default_value_.reset(); | 24 default_value_.reset(); |
| 30 controller_ = ui_data.is_managed() ? CONTROLLER_POLICY : CONTROLLER_USER; | 25 onc_source_ = onc_source; |
| 31 } | 26 } |
| 32 | 27 |
| 33 void NetworkPropertyUIData::ParseOncProperty( | 28 void NetworkPropertyUIData::ParseOncProperty( |
| 34 const NetworkUIData& ui_data, | 29 onc::ONCSource onc_source, |
| 35 const base::DictionaryValue* onc, | 30 const base::DictionaryValue* onc, |
| 36 const std::string& property_key) { | 31 const std::string& property_key) { |
| 37 Reset(ui_data); | 32 Reset(onc_source); |
| 38 if (!onc || controller_ == CONTROLLER_USER) | 33 |
| 34 if (!onc || !managed()) |
| 39 return; | 35 return; |
| 40 | 36 |
| 41 size_t pos = property_key.find_last_of('.'); | 37 size_t pos = property_key.find_last_of('.'); |
| 42 std::string recommended_property_key; | 38 std::string recommended_property_key; |
| 43 std::string property_basename(property_key); | 39 std::string property_basename(property_key); |
| 44 if (pos != std::string::npos) { | 40 if (pos != std::string::npos) { |
| 45 recommended_property_key = property_key.substr(0, pos + 1); | 41 recommended_property_key = property_key.substr(0, pos + 1); |
| 46 property_basename = property_key.substr(pos + 1); | 42 property_basename = property_key.substr(pos + 1); |
| 47 } | 43 } |
| 48 recommended_property_key += "Recommended"; | 44 recommended_property_key += "Recommended"; |
| 49 | 45 |
| 50 const base::ListValue* recommended_keys = NULL; | 46 const base::ListValue* recommended_keys = NULL; |
| 51 if (onc->GetList(recommended_property_key, &recommended_keys)) { | 47 if (onc->GetList(recommended_property_key, &recommended_keys)) { |
| 52 base::StringValue basename_value(property_basename); | 48 base::StringValue basename_value(property_basename); |
| 53 if (recommended_keys->Find(basename_value) != recommended_keys->end()) { | 49 if (recommended_keys->Find(basename_value) != recommended_keys->end()) { |
| 54 controller_ = CONTROLLER_USER; | 50 onc_source_ = onc::ONC_SOURCE_NONE; |
| 55 const base::Value* default_value = NULL; | 51 const base::Value* default_value = NULL; |
| 56 if (onc->Get(property_key, &default_value)) | 52 if (onc->Get(property_key, &default_value)) |
| 57 default_value_.reset(default_value->DeepCopy()); | 53 default_value_.reset(default_value->DeepCopy()); |
| 58 } | 54 } |
| 59 } | 55 } |
| 60 } | 56 } |
| 61 | 57 |
| 62 } // namespace chromeos | 58 } // namespace chromeos |
| OLD | NEW |