Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(317)

Side by Side Diff: chromecast/base/serializers.cc

Issue 1875623002: Convert //chromecast from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chromecast/base/serializers.h ('k') | chromecast/base/serializers_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "chromecast/base/serializers.h" 5 #include "chromecast/base/serializers.h"
6 6
7 #include "base/json/json_file_value_serializer.h" 7 #include "base/json/json_file_value_serializer.h"
8 #include "base/json/json_string_value_serializer.h" 8 #include "base/json/json_string_value_serializer.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 10
11 namespace chromecast { 11 namespace chromecast {
12 12
13 scoped_ptr<base::Value> DeserializeFromJson(const std::string& text) { 13 std::unique_ptr<base::Value> DeserializeFromJson(const std::string& text) {
14 JSONStringValueDeserializer deserializer(text); 14 JSONStringValueDeserializer deserializer(text);
15 15
16 int error_code = -1; 16 int error_code = -1;
17 std::string error_msg; 17 std::string error_msg;
18 scoped_ptr<base::Value> value = 18 std::unique_ptr<base::Value> value =
19 deserializer.Deserialize(&error_code, &error_msg); 19 deserializer.Deserialize(&error_code, &error_msg);
20 DLOG_IF(ERROR, !value) << "JSON error " << error_code << ":" << error_msg; 20 DLOG_IF(ERROR, !value) << "JSON error " << error_code << ":" << error_msg;
21 21
22 // Value will hold the nullptr in case of an error. 22 // Value will hold the nullptr in case of an error.
23 return value; 23 return value;
24 } 24 }
25 25
26 scoped_ptr<std::string> SerializeToJson(const base::Value& value) { 26 std::unique_ptr<std::string> SerializeToJson(const base::Value& value) {
27 scoped_ptr<std::string> json_str(new std::string()); 27 std::unique_ptr<std::string> json_str(new std::string());
28 JSONStringValueSerializer serializer(json_str.get()); 28 JSONStringValueSerializer serializer(json_str.get());
29 if (!serializer.Serialize(value)) 29 if (!serializer.Serialize(value))
30 json_str.reset(nullptr); 30 json_str.reset(nullptr);
31 return json_str; 31 return json_str;
32 } 32 }
33 33
34 scoped_ptr<base::Value> DeserializeJsonFromFile(const base::FilePath& path) { 34 std::unique_ptr<base::Value> DeserializeJsonFromFile(
35 const base::FilePath& path) {
35 JSONFileValueDeserializer deserializer(path); 36 JSONFileValueDeserializer deserializer(path);
36 37
37 int error_code = -1; 38 int error_code = -1;
38 std::string error_msg; 39 std::string error_msg;
39 scoped_ptr<base::Value> value = 40 std::unique_ptr<base::Value> value =
40 deserializer.Deserialize(&error_code, &error_msg); 41 deserializer.Deserialize(&error_code, &error_msg);
41 DLOG_IF(ERROR, !value) << "JSON error " << error_code << ":" << error_msg; 42 DLOG_IF(ERROR, !value) << "JSON error " << error_code << ":" << error_msg;
42 43
43 // Value will hold the nullptr in case of an error. 44 // Value will hold the nullptr in case of an error.
44 return value; 45 return value;
45 } 46 }
46 47
47 bool SerializeJsonToFile(const base::FilePath& path, const base::Value& value) { 48 bool SerializeJsonToFile(const base::FilePath& path, const base::Value& value) {
48 JSONFileValueSerializer serializer(path); 49 JSONFileValueSerializer serializer(path);
49 return serializer.Serialize(value); 50 return serializer.Serialize(value);
50 } 51 }
51 52
52 } // namespace chromecast 53 } // namespace chromecast
OLDNEW
« no previous file with comments | « chromecast/base/serializers.h ('k') | chromecast/base/serializers_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698