OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/cloud_devices/common/cloud_device_description.h" | 5 #include "components/cloud_devices/common/cloud_device_description.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/memory/ptr_util.h" |
12 #include "base/values.h" | 13 #include "base/values.h" |
13 #include "components/cloud_devices/common/cloud_device_description_consts.h" | 14 #include "components/cloud_devices/common/cloud_device_description_consts.h" |
14 | 15 |
15 namespace cloud_devices { | 16 namespace cloud_devices { |
16 | 17 |
17 CloudDeviceDescription::CloudDeviceDescription() { | 18 CloudDeviceDescription::CloudDeviceDescription() { |
18 Reset(); | 19 Reset(); |
19 } | 20 } |
20 | 21 |
21 CloudDeviceDescription::~CloudDeviceDescription() { | 22 CloudDeviceDescription::~CloudDeviceDescription() { |
22 } | 23 } |
23 | 24 |
24 void CloudDeviceDescription::Reset() { | 25 void CloudDeviceDescription::Reset() { |
25 root_.reset(new base::DictionaryValue); | 26 root_.reset(new base::DictionaryValue); |
26 root_->SetString(json::kVersion, json::kVersion10); | 27 root_->SetString(json::kVersion, json::kVersion10); |
27 } | 28 } |
28 | 29 |
29 bool CloudDeviceDescription::InitFromDictionary( | 30 bool CloudDeviceDescription::InitFromDictionary( |
30 scoped_ptr<base::DictionaryValue> root) { | 31 std::unique_ptr<base::DictionaryValue> root) { |
31 if (!root) | 32 if (!root) |
32 return false; | 33 return false; |
33 Reset(); | 34 Reset(); |
34 root_ = std::move(root); | 35 root_ = std::move(root); |
35 std::string version; | 36 std::string version; |
36 root_->GetString(json::kVersion, &version); | 37 root_->GetString(json::kVersion, &version); |
37 return version == json::kVersion10; | 38 return version == json::kVersion10; |
38 } | 39 } |
39 | 40 |
40 bool CloudDeviceDescription::InitFromString(const std::string& json) { | 41 bool CloudDeviceDescription::InitFromString(const std::string& json) { |
41 scoped_ptr<base::Value> parsed = base::JSONReader::Read(json); | 42 std::unique_ptr<base::Value> parsed = base::JSONReader::Read(json); |
42 base::DictionaryValue* description = NULL; | 43 base::DictionaryValue* description = NULL; |
43 if (!parsed || !parsed->GetAsDictionary(&description)) | 44 if (!parsed || !parsed->GetAsDictionary(&description)) |
44 return false; | 45 return false; |
45 ignore_result(parsed.release()); | 46 ignore_result(parsed.release()); |
46 return InitFromDictionary(make_scoped_ptr(description)); | 47 return InitFromDictionary(base::WrapUnique(description)); |
47 } | 48 } |
48 | 49 |
49 std::string CloudDeviceDescription::ToString() const { | 50 std::string CloudDeviceDescription::ToString() const { |
50 std::string json; | 51 std::string json; |
51 base::JSONWriter::WriteWithOptions( | 52 base::JSONWriter::WriteWithOptions( |
52 *root_, base::JSONWriter::OPTIONS_PRETTY_PRINT, &json); | 53 *root_, base::JSONWriter::OPTIONS_PRETTY_PRINT, &json); |
53 return json; | 54 return json; |
54 } | 55 } |
55 | 56 |
56 const base::DictionaryValue* CloudDeviceDescription::GetItem( | 57 const base::DictionaryValue* CloudDeviceDescription::GetItem( |
(...skipping 18 matching lines...) Expand all Loading... |
75 } | 76 } |
76 | 77 |
77 base::ListValue* CloudDeviceDescription::CreateListItem( | 78 base::ListValue* CloudDeviceDescription::CreateListItem( |
78 const std::string& path) { | 79 const std::string& path) { |
79 base::ListValue* value = new base::ListValue; | 80 base::ListValue* value = new base::ListValue; |
80 root_->Set(path, value); | 81 root_->Set(path, value); |
81 return value; | 82 return value; |
82 } | 83 } |
83 | 84 |
84 } // namespace cloud_devices | 85 } // namespace cloud_devices |
OLD | NEW |