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

Side by Side Diff: remoting/host/host_config.cc

Issue 1864213002: Convert //remoting to use std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Mac IWYU 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 | « remoting/host/host_config.h ('k') | remoting/host/host_config_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 (c) 2012 The Chromium Authors. All rights reserved. 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 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 "remoting/host/host_config.h" 5 #include "remoting/host/host_config.h"
6 6
7 #include "base/files/file_util.h" 7 #include "base/files/file_util.h"
8 #include "base/files/important_file_writer.h" 8 #include "base/files/important_file_writer.h"
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/memory/ptr_util.h"
11 #include "base/values.h" 12 #include "base/values.h"
12 13
13 namespace remoting { 14 namespace remoting {
14 15
15 scoped_ptr<base::DictionaryValue> HostConfigFromJson( 16 std::unique_ptr<base::DictionaryValue> HostConfigFromJson(
16 const std::string& json) { 17 const std::string& json) {
17 scoped_ptr<base::Value> value = 18 std::unique_ptr<base::Value> value =
18 base::JSONReader::Read(json, base::JSON_ALLOW_TRAILING_COMMAS); 19 base::JSONReader::Read(json, base::JSON_ALLOW_TRAILING_COMMAS);
19 if (!value || !value->IsType(base::Value::TYPE_DICTIONARY)) { 20 if (!value || !value->IsType(base::Value::TYPE_DICTIONARY)) {
20 LOG(WARNING) << "Failed to parse host config from JSON"; 21 LOG(WARNING) << "Failed to parse host config from JSON";
21 return nullptr; 22 return nullptr;
22 } 23 }
23 24
24 return make_scoped_ptr(static_cast<base::DictionaryValue*>(value.release())); 25 return base::WrapUnique(static_cast<base::DictionaryValue*>(value.release()));
25 } 26 }
26 27
27 std::string HostConfigToJson(const base::DictionaryValue& host_config) { 28 std::string HostConfigToJson(const base::DictionaryValue& host_config) {
28 std::string data; 29 std::string data;
29 base::JSONWriter::Write(host_config, &data); 30 base::JSONWriter::Write(host_config, &data);
30 return data; 31 return data;
31 } 32 }
32 33
33 scoped_ptr<base::DictionaryValue> HostConfigFromJsonFile( 34 std::unique_ptr<base::DictionaryValue> HostConfigFromJsonFile(
34 const base::FilePath& config_file) { 35 const base::FilePath& config_file) {
35 // TODO(sergeyu): Implement better error handling here. 36 // TODO(sergeyu): Implement better error handling here.
36 std::string serialized; 37 std::string serialized;
37 if (!base::ReadFileToString(config_file, &serialized)) { 38 if (!base::ReadFileToString(config_file, &serialized)) {
38 LOG(WARNING) << "Failed to read " << config_file.value(); 39 LOG(WARNING) << "Failed to read " << config_file.value();
39 return nullptr; 40 return nullptr;
40 } 41 }
41 42
42 return HostConfigFromJson(serialized); 43 return HostConfigFromJson(serialized);
43 } 44 }
44 45
45 bool HostConfigToJsonFile(const base::DictionaryValue& host_config, 46 bool HostConfigToJsonFile(const base::DictionaryValue& host_config,
46 const base::FilePath& config_file) { 47 const base::FilePath& config_file) {
47 std::string serialized = HostConfigToJson(host_config); 48 std::string serialized = HostConfigToJson(host_config);
48 return base::ImportantFileWriter::WriteFileAtomically(config_file, 49 return base::ImportantFileWriter::WriteFileAtomically(config_file,
49 serialized); 50 serialized);
50 } 51 }
51 52
52 } // namespace remoting 53 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/host_config.h ('k') | remoting/host/host_config_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698