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

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

Issue 10855249: [Chromoting] The daemon process now starts the networking process and passes the host configuration… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 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( 33 return SetSerializedData(file_content);
34 base::JSONReader::Read(file_content, base::JSON_ALLOW_TRAILING_COMMAS));
35 if (value.get() == NULL || !value->IsType(Value::TYPE_DICTIONARY)) {
36 LOG(WARNING) << "Failed to parse " << filename_.value();
37 return false;
38 }
39
40 DictionaryValue* dictionary = static_cast<DictionaryValue*>(value.release());
41 values_.reset(dictionary);
42 return true;
43 } 34 }
44 35
45 bool JsonHostConfig::Save() { 36 bool JsonHostConfig::Save() {
46 DCHECK(CalledOnValidThread()); 37 DCHECK(CalledOnValidThread());
47 38
48 std::string file_content = GetSerializedData(); 39 std::string file_content = GetSerializedData();
49 // TODO(sergeyu): Move ImportantFileWriter to base and use it here. 40 // TODO(sergeyu): Move ImportantFileWriter to base and use it here.
50 int result = file_util::WriteFile(filename_, file_content.data(), 41 int result = file_util::WriteFile(filename_, file_content.data(),
51 file_content.size()); 42 file_content.size());
52 return result == static_cast<int>(file_content.size()); 43 return result == static_cast<int>(file_content.size());
53 } 44 }
54 45
55 std::string JsonHostConfig::GetSerializedData() { 46 std::string JsonHostConfig::GetSerializedData() {
56 std::string data; 47 std::string data;
57 base::JSONWriter::Write(values_.get(), &data); 48 base::JSONWriter::Write(values_.get(), &data);
58 return data; 49 return data;
59 } 50 }
60 51
52 bool JsonHostConfig::SetSerializedData(const std::string& config) {
53 scoped_ptr<Value> value(
54 base::JSONReader::Read(config, base::JSON_ALLOW_TRAILING_COMMAS));
55 if (value.get() == NULL || !value->IsType(Value::TYPE_DICTIONARY)) {
56 LOG(WARNING) << "Failed to parse " << filename_.value();
57 return false;
58 }
59
60 DictionaryValue* dictionary = static_cast<DictionaryValue*>(value.release());
61 values_.reset(dictionary);
62 return true;
63 }
64
61 } // namespace remoting 65 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698