summaryrefslogtreecommitdiffstats
path: root/components/cloud_devices/cloud_device_description.h
blob: d4ce081b32ae0a2e4fc6adb7b9724f43432aa701 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_CLOUD_DEVICES_CLOUD_DEVICE_DESCRIPTION_H_
#define COMPONENTS_CLOUD_DEVICES_CLOUD_DEVICE_DESCRIPTION_H_

#include <string>

#include "base/callback.h"

namespace base {
class DictionaryValue;
class ListValue;
}

namespace cloud_devices {

// Provides parsing, serialization and validation Cloud Device Description or
// Cloud Job Ticket.
// https://developers.google.com/cloud-print/docs/cdd
class CloudDeviceDescription {
 public:
  CloudDeviceDescription();
  ~CloudDeviceDescription();

  void Reset();

  bool InitFromDictionary(scoped_ptr<base::DictionaryValue> root);
  bool InitFromString(const std::string& json);

  std::string ToString() const;

  // Returns dictionary with capability/option.
  // Returns NULL if missing.
  const base::DictionaryValue* GetItem(const std::string& path) const;

  // Create dictionary for capability/option.
  // Never returns NULL.
  base::DictionaryValue* CreateItem(const std::string& path);

  // Returns list with capability/option.
  // Returns NULL if missing.
  const base::ListValue* GetListItem(const std::string& path) const;

  // Create list for capability/option.
  // Never returns NULL.
  base::ListValue* CreateListItem(const std::string& path);

 private:
  scoped_ptr<base::DictionaryValue> root_;

  DISALLOW_COPY_AND_ASSIGN(CloudDeviceDescription);
};

}  // namespace cloud_devices

#endif  // COMPONENTS_CLOUD_DEVICES_CLOUD_DEVICE_DESCRIPTION_H_