network_property_ui_data.h revision 58537e28ecd584eab876aee8be7156509866d23a
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.
4
5#ifndef CHROME_BROWSER_CHROMEOS_OPTIONS_NETWORK_PROPERTY_UI_DATA_H_
6#define CHROME_BROWSER_CHROMEOS_OPTIONS_NETWORK_PROPERTY_UI_DATA_H_
7
8#include <string>
9
10#include "base/basictypes.h"
11#include "base/memory/scoped_ptr.h"
12#include "chromeos/network/onc/onc_constants.h"
13
14namespace base {
15class DictionaryValue;
16class Value;
17}
18
19namespace chromeos {
20
21// Holds meta information for a network property: Whether the property is under
22// policy control, if it is user-editable, and policy-provided default value, if
23// available.
24class NetworkPropertyUIData {
25 public:
26  // Initializes with ONC_SOURCE_NONE and no default value.
27  NetworkPropertyUIData();
28
29  // Initializes with the given |onc_source| and no default value.
30  explicit NetworkPropertyUIData(onc::ONCSource onc_source);
31
32  ~NetworkPropertyUIData();
33
34  // Update the property object from dictionary, reading the key given by
35  // |property_key|.
36  void ParseOncProperty(onc::ONCSource onc_source,
37                        const base::DictionaryValue* onc,
38                        const std::string& property_key);
39
40  const base::Value* default_value() const { return default_value_.get(); }
41  bool IsManaged() const {
42    return (onc_source_ == onc::ONC_SOURCE_DEVICE_POLICY ||
43            onc_source_ == onc::ONC_SOURCE_USER_POLICY);
44  }
45  bool IsEditable() const { return !IsManaged(); }
46
47 private:
48  onc::ONCSource onc_source_;
49  scoped_ptr<base::Value> default_value_;
50
51  DISALLOW_COPY_AND_ASSIGN(NetworkPropertyUIData);
52};
53
54}  // namespace chromeos
55
56#endif  // CHROME_BROWSER_CHROMEOS_OPTIONS_NETWORK_PROPERTY_UI_DATA_H_
57