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

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

Issue 9960077: Modify the base::JSONReader interface to take a set of options rather than a boolean flag. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 8 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 | Annotate | Revision Log
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/json_host_config.h" 5 #include "remoting/host/json_host_config.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/file_util.h" 8 #include "base/file_util.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"
(...skipping 12 matching lines...) Expand all
23 bool JsonHostConfig::Read() { 23 bool JsonHostConfig::Read() {
24 DCHECK(CalledOnValidThread()); 24 DCHECK(CalledOnValidThread());
25 25
26 // TODO(sergeyu): Implement better error handling here. 26 // TODO(sergeyu): Implement better error handling here.
27 std::string file_content; 27 std::string file_content;
28 if (!file_util::ReadFileToString(filename_, &file_content)) { 28 if (!file_util::ReadFileToString(filename_, &file_content)) {
29 LOG(WARNING) << "Failed to read " << filename_.value(); 29 LOG(WARNING) << "Failed to read " << filename_.value();
30 return false; 30 return false;
31 } 31 }
32 32
33 scoped_ptr<Value> value(base::JSONReader::Read(file_content, true)); 33 scoped_ptr<Value> value(
34 base::JSONReader::Read(file_content, base::JSON_ALLOW_TRAILING_COMMAS));
34 if (value.get() == NULL || !value->IsType(Value::TYPE_DICTIONARY)) { 35 if (value.get() == NULL || !value->IsType(Value::TYPE_DICTIONARY)) {
35 LOG(WARNING) << "Failed to parse " << filename_.value(); 36 LOG(WARNING) << "Failed to parse " << filename_.value();
36 return false; 37 return false;
37 } 38 }
38 39
39 DictionaryValue* dictionary = static_cast<DictionaryValue*>(value.release()); 40 DictionaryValue* dictionary = static_cast<DictionaryValue*>(value.release());
40 values_.reset(dictionary); 41 values_.reset(dictionary);
41 return true; 42 return true;
42 } 43 }
43 44
44 bool JsonHostConfig::Save() { 45 bool JsonHostConfig::Save() {
45 DCHECK(CalledOnValidThread()); 46 DCHECK(CalledOnValidThread());
46 47
47 std::string file_content; 48 std::string file_content;
48 base::JSONWriter::WriteWithOptions(values_.get(), 49 base::JSONWriter::WriteWithOptions(values_.get(),
49 base::JSONWriter::OPTIONS_PRETTY_PRINT, 50 base::JSONWriter::OPTIONS_PRETTY_PRINT,
50 &file_content); 51 &file_content);
51 // TODO(sergeyu): Move ImportantFileWriter to base and use it here. 52 // TODO(sergeyu): Move ImportantFileWriter to base and use it here.
52 int result = file_util::WriteFile(filename_, file_content.c_str(), 53 int result = file_util::WriteFile(filename_, file_content.c_str(),
53 file_content.size()); 54 file_content.size());
54 return result == static_cast<int>(file_content.size()); 55 return result == static_cast<int>(file_content.size());
55 } 56 }
56 57
57 } // namespace remoting 58 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698