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
3// found in the LICENSE file.
4
5#ifndef CHROMEOS_NETWORK_NETWORK_UI_DATA_H_
6#define CHROMEOS_NETWORK_NETWORK_UI_DATA_H_
7
8#include <string>
9
10#include "base/basictypes.h"
11#include "base/memory/scoped_ptr.h"
12#include "chromeos/chromeos_export.h"
13#include "components/onc/onc_constants.h"
14
15namespace base {
16class DictionaryValue;
17}
18
19namespace chromeos {
20
21// Helper for accessing and setting values in the network's UI data dictionary.
22// Accessing values is done via static members that take the network as an
23// argument. In order to fill a UI data dictionary, construct an instance, set
24// up your data members, and call FillDictionary(). For example, if you have a
25// |network|:
26//
27//      NetworkUIData ui_data;
28//      ui_data.FillDictionary(network->ui_data());
29class CHROMEOS_EXPORT NetworkUIData {
30 public:
31  NetworkUIData();
32  NetworkUIData(const NetworkUIData& other);
33  NetworkUIData& operator=(const NetworkUIData& other);
34  explicit NetworkUIData(const base::DictionaryValue& dict);
35  ~NetworkUIData();
36
37  ::onc::ONCSource onc_source() const { return onc_source_; }
38
39  const base::DictionaryValue* user_settings() const {
40    return user_settings_.get();
41  }
42  void set_user_settings(scoped_ptr<base::DictionaryValue> dict);
43
44  // Returns |onc_source_| as a string, one of kONCSource*.
45  std::string GetONCSourceAsString() const;
46
47  // Fills in |dict| with the currently configured values. This will write the
48  // keys appropriate for Network::ui_data() as defined below (kKeyXXX).
49  void FillDictionary(base::DictionaryValue* dict) const;
50
51  // Creates a NetworkUIData object from |onc_source|. This function is used to
52  // create the "UIData" property of the Shill configuration.
53  static scoped_ptr<NetworkUIData> CreateFromONC(::onc::ONCSource onc_source);
54
55  // Key for storing source of the ONC network.
56  static const char kKeyONCSource[];
57
58  // Key for storing the user settings.
59  static const char kKeyUserSettings[];
60
61  // Values for kKeyONCSource
62  static const char kONCSourceUserImport[];
63  static const char kONCSourceDevicePolicy[];
64  static const char kONCSourceUserPolicy[];
65
66 private:
67  ::onc::ONCSource onc_source_;
68  scoped_ptr<base::DictionaryValue> user_settings_;
69};
70
71}  // namespace chromeos
72
73#endif  // CHROMEOS_NETWORK_NETWORK_UI_DATA_H_
74