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

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

Issue 925783002: Split ValueSerializer into separate Serializer and Deserializer classes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed cpplint warnings. Created 5 years, 9 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 | « google_apis/drive/test_util.cc ('k') | remoting/host/pairing_registry_delegate_win.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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/pairing_registry_delegate_linux.h" 5 #include "remoting/host/pairing_registry_delegate_linux.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/files/file_enumerator.h" 8 #include "base/files/file_enumerator.h"
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/files/important_file_writer.h" 10 #include "base/files/important_file_writer.h"
(...skipping 28 matching lines...) Expand all
39 scoped_ptr<base::ListValue> pairings(new base::ListValue()); 39 scoped_ptr<base::ListValue> pairings(new base::ListValue());
40 40
41 // Enumerate all pairing files in the pairing registry. 41 // Enumerate all pairing files in the pairing registry.
42 base::FilePath registry_path = GetRegistryPath(); 42 base::FilePath registry_path = GetRegistryPath();
43 base::FileEnumerator enumerator(registry_path, false, 43 base::FileEnumerator enumerator(registry_path, false,
44 base::FileEnumerator::FILES, 44 base::FileEnumerator::FILES,
45 kPairingFilenamePattern); 45 kPairingFilenamePattern);
46 for (base::FilePath pairing_file = enumerator.Next(); !pairing_file.empty(); 46 for (base::FilePath pairing_file = enumerator.Next(); !pairing_file.empty();
47 pairing_file = enumerator.Next()) { 47 pairing_file = enumerator.Next()) {
48 // Read the JSON containing pairing data. 48 // Read the JSON containing pairing data.
49 JSONFileValueSerializer serializer(pairing_file); 49 JSONFileValueDeserializer deserializer(pairing_file);
50 int error_code; 50 int error_code;
51 std::string error_message; 51 std::string error_message;
52 scoped_ptr<base::Value> pairing_json( 52 scoped_ptr<base::Value> pairing_json(
53 serializer.Deserialize(&error_code, &error_message)); 53 deserializer.Deserialize(&error_code, &error_message));
54 if (!pairing_json) { 54 if (!pairing_json) {
55 LOG(WARNING) << "Failed to load '" << pairing_file.value() << "' (" 55 LOG(WARNING) << "Failed to load '" << pairing_file.value() << "' ("
56 << error_code << ")."; 56 << error_code << ").";
57 continue; 57 continue;
58 } 58 }
59 59
60 pairings->Append(pairing_json.release()); 60 pairings->Append(pairing_json.release());
61 } 61 }
62 62
63 return pairings.Pass(); 63 return pairings.Pass();
(...skipping 14 matching lines...) Expand all
78 78
79 return success; 79 return success;
80 } 80 }
81 81
82 PairingRegistry::Pairing PairingRegistryDelegateLinux::Load( 82 PairingRegistry::Pairing PairingRegistryDelegateLinux::Load(
83 const std::string& client_id) { 83 const std::string& client_id) {
84 base::FilePath registry_path = GetRegistryPath(); 84 base::FilePath registry_path = GetRegistryPath();
85 base::FilePath pairing_file = registry_path.Append( 85 base::FilePath pairing_file = registry_path.Append(
86 base::StringPrintf(kPairingFilenameFormat, client_id.c_str())); 86 base::StringPrintf(kPairingFilenameFormat, client_id.c_str()));
87 87
88 JSONFileValueSerializer serializer(pairing_file); 88 JSONFileValueDeserializer deserializer(pairing_file);
89 int error_code; 89 int error_code;
90 std::string error_message; 90 std::string error_message;
91 scoped_ptr<base::Value> pairing( 91 scoped_ptr<base::Value> pairing(
92 serializer.Deserialize(&error_code, &error_message)); 92 deserializer.Deserialize(&error_code, &error_message));
93 if (!pairing) { 93 if (!pairing) {
94 LOG(WARNING) << "Failed to load pairing information: " << error_message 94 LOG(WARNING) << "Failed to load pairing information: " << error_message
95 << " (" << error_code << ")."; 95 << " (" << error_code << ").";
96 return PairingRegistry::Pairing(); 96 return PairingRegistry::Pairing();
97 } 97 }
98 98
99 base::DictionaryValue* pairing_dictionary; 99 base::DictionaryValue* pairing_dictionary;
100 if (!pairing->GetAsDictionary(&pairing_dictionary)) { 100 if (!pairing->GetAsDictionary(&pairing_dictionary)) {
101 LOG(WARNING) << "Failed to parse pairing information: not a dictionary."; 101 LOG(WARNING) << "Failed to parse pairing information: not a dictionary.";
102 return PairingRegistry::Pairing(); 102 return PairingRegistry::Pairing();
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 const base::FilePath& registry_path) { 154 const base::FilePath& registry_path) {
155 registry_path_for_testing_ = registry_path; 155 registry_path_for_testing_ = registry_path;
156 } 156 }
157 157
158 158
159 scoped_ptr<PairingRegistry::Delegate> CreatePairingRegistryDelegate() { 159 scoped_ptr<PairingRegistry::Delegate> CreatePairingRegistryDelegate() {
160 return make_scoped_ptr(new PairingRegistryDelegateLinux()); 160 return make_scoped_ptr(new PairingRegistryDelegateLinux());
161 } 161 }
162 162
163 } // namespace remoting 163 } // namespace remoting
OLDNEW
« no previous file with comments | « google_apis/drive/test_util.cc ('k') | remoting/host/pairing_registry_delegate_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698