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

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

Issue 121123002: Update uses of UTF conversions in ppapi/, printing/, remoting/, rlz/, sandbox/, skia/, sql/, sync/,… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 12 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
« no previous file with comments | « remoting/host/ipc_util_win.cc ('k') | remoting/host/pairing_registry_delegate_win_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 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_win.h" 5 #include "remoting/host/pairing_registry_delegate_win.h"
6 6
7 #include "base/json/json_string_value_serializer.h" 7 #include "base/json/json_string_value_serializer.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "base/values.h" 10 #include "base/values.h"
(...skipping 30 matching lines...) Expand all
41 // presubmit: allow wstring 41 // presubmit: allow wstring
42 std::wstring value_json; 42 std::wstring value_json;
43 LONG result = key.ReadValue(value_name, &value_json); 43 LONG result = key.ReadValue(value_name, &value_json);
44 if (result != ERROR_SUCCESS) { 44 if (result != ERROR_SUCCESS) {
45 SetLastError(result); 45 SetLastError(result);
46 PLOG(ERROR) << "Cannot read value '" << value_name << "'"; 46 PLOG(ERROR) << "Cannot read value '" << value_name << "'";
47 return scoped_ptr<base::DictionaryValue>(); 47 return scoped_ptr<base::DictionaryValue>();
48 } 48 }
49 49
50 // Parse the value. 50 // Parse the value.
51 std::string value_json_utf8 = WideToUTF8(value_json); 51 std::string value_json_utf8 = base::WideToUTF8(value_json);
52 JSONStringValueSerializer serializer(&value_json_utf8); 52 JSONStringValueSerializer serializer(&value_json_utf8);
53 int error_code; 53 int error_code;
54 std::string error_message; 54 std::string error_message;
55 scoped_ptr<base::Value> value(serializer.Deserialize(&error_code, 55 scoped_ptr<base::Value> value(serializer.Deserialize(&error_code,
56 &error_message)); 56 &error_message));
57 if (!value) { 57 if (!value) {
58 LOG(ERROR) << "Failed to parse '" << value_name << "': " << error_message 58 LOG(ERROR) << "Failed to parse '" << value_name << "': " << error_message
59 << " (" << error_code << ")."; 59 << " (" << error_code << ").";
60 return scoped_ptr<base::DictionaryValue>(); 60 return scoped_ptr<base::DictionaryValue>();
61 } 61 }
(...skipping 13 matching lines...) Expand all
75 const wchar_t* value_name, 75 const wchar_t* value_name,
76 scoped_ptr<base::DictionaryValue> value) { 76 scoped_ptr<base::DictionaryValue> value) {
77 std::string value_json_utf8; 77 std::string value_json_utf8;
78 JSONStringValueSerializer serializer(&value_json_utf8); 78 JSONStringValueSerializer serializer(&value_json_utf8);
79 if (!serializer.Serialize(*value)) { 79 if (!serializer.Serialize(*value)) {
80 LOG(ERROR) << "Failed to serialize '" << value_name << "'"; 80 LOG(ERROR) << "Failed to serialize '" << value_name << "'";
81 return false; 81 return false;
82 } 82 }
83 83
84 // presubmit: allow wstring 84 // presubmit: allow wstring
85 std::wstring value_json = UTF8ToWide(value_json_utf8); 85 std::wstring value_json = base::UTF8ToWide(value_json_utf8);
86 LONG result = key.WriteValue(value_name, value_json.c_str()); 86 LONG result = key.WriteValue(value_name, value_json.c_str());
87 if (result != ERROR_SUCCESS) { 87 if (result != ERROR_SUCCESS) {
88 SetLastError(result); 88 SetLastError(result);
89 PLOG(ERROR) << "Cannot write value '" << value_name << "'"; 89 PLOG(ERROR) << "Cannot write value '" << value_name << "'";
90 return false; 90 return false;
91 } 91 }
92 92
93 return true; 93 return true;
94 } 94 }
95 95
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 for (DWORD index = 0; index < count; ++index) { 128 for (DWORD index = 0; index < count; ++index) {
129 // presubmit: allow wstring 129 // presubmit: allow wstring
130 std::wstring value_name; 130 std::wstring value_name;
131 LONG result = unprivileged_.GetValueNameAt(index, &value_name); 131 LONG result = unprivileged_.GetValueNameAt(index, &value_name);
132 if (result != ERROR_SUCCESS) { 132 if (result != ERROR_SUCCESS) {
133 SetLastError(result); 133 SetLastError(result);
134 PLOG(ERROR) << "Cannot get the name of value " << index; 134 PLOG(ERROR) << "Cannot get the name of value " << index;
135 continue; 135 continue;
136 } 136 }
137 137
138 PairingRegistry::Pairing pairing = Load(WideToUTF8(value_name)); 138 PairingRegistry::Pairing pairing = Load(base::WideToUTF8(value_name));
139 if (pairing.is_valid()) 139 if (pairing.is_valid())
140 pairings->Append(pairing.ToValue().release()); 140 pairings->Append(pairing.ToValue().release());
141 } 141 }
142 142
143 return pairings.Pass(); 143 return pairings.Pass();
144 } 144 }
145 145
146 bool PairingRegistryDelegateWin::DeleteAll() { 146 bool PairingRegistryDelegateWin::DeleteAll() {
147 if (!privileged_.Valid()) { 147 if (!privileged_.Valid()) {
148 LOG(ERROR) << "Cannot delete pairings: the delegate is read-only."; 148 LOG(ERROR) << "Cannot delete pairings: the delegate is read-only.";
(...skipping 12 matching lines...) Expand all
161 success = success && (result == ERROR_SUCCESS); 161 success = success && (result == ERROR_SUCCESS);
162 count = unprivileged_.GetValueCount(); 162 count = unprivileged_.GetValueCount();
163 } 163 }
164 164
165 return success; 165 return success;
166 } 166 }
167 167
168 PairingRegistry::Pairing PairingRegistryDelegateWin::Load( 168 PairingRegistry::Pairing PairingRegistryDelegateWin::Load(
169 const std::string& client_id) { 169 const std::string& client_id) {
170 // presubmit: allow wstring 170 // presubmit: allow wstring
171 std::wstring value_name = UTF8ToWide(client_id); 171 std::wstring value_name = base::UTF8ToWide(client_id);
172 172
173 // Read unprivileged fields first. 173 // Read unprivileged fields first.
174 scoped_ptr<base::DictionaryValue> pairing = ReadValue(unprivileged_, 174 scoped_ptr<base::DictionaryValue> pairing = ReadValue(unprivileged_,
175 value_name.c_str()); 175 value_name.c_str());
176 if (!pairing) 176 if (!pairing)
177 return PairingRegistry::Pairing(); 177 return PairingRegistry::Pairing();
178 178
179 // Read the shared secret. 179 // Read the shared secret.
180 if (privileged_.Valid()) { 180 if (privileged_.Valid()) {
181 scoped_ptr<base::DictionaryValue> secret = ReadValue(privileged_, 181 scoped_ptr<base::DictionaryValue> secret = ReadValue(privileged_,
(...skipping 18 matching lines...) Expand all
200 // Convert pairing to JSON. 200 // Convert pairing to JSON.
201 scoped_ptr<base::DictionaryValue> pairing_json = pairing.ToValue(); 201 scoped_ptr<base::DictionaryValue> pairing_json = pairing.ToValue();
202 202
203 // Extract the shared secret to a separate dictionary. 203 // Extract the shared secret to a separate dictionary.
204 scoped_ptr<base::Value> secret_key; 204 scoped_ptr<base::Value> secret_key;
205 CHECK(pairing_json->Remove(PairingRegistry::kSharedSecretKey, &secret_key)); 205 CHECK(pairing_json->Remove(PairingRegistry::kSharedSecretKey, &secret_key));
206 scoped_ptr<base::DictionaryValue> secret_json(new base::DictionaryValue()); 206 scoped_ptr<base::DictionaryValue> secret_json(new base::DictionaryValue());
207 secret_json->Set(PairingRegistry::kSharedSecretKey, secret_key.release()); 207 secret_json->Set(PairingRegistry::kSharedSecretKey, secret_key.release());
208 208
209 // presubmit: allow wstring 209 // presubmit: allow wstring
210 std::wstring value_name = UTF8ToWide(pairing.client_id()); 210 std::wstring value_name = base::UTF8ToWide(pairing.client_id());
211 211
212 // Write pairing to the registry. 212 // Write pairing to the registry.
213 if (!WriteValue(privileged_, value_name.c_str(), secret_json.Pass()) || 213 if (!WriteValue(privileged_, value_name.c_str(), secret_json.Pass()) ||
214 !WriteValue(unprivileged_, value_name.c_str(), pairing_json.Pass())) { 214 !WriteValue(unprivileged_, value_name.c_str(), pairing_json.Pass())) {
215 return false; 215 return false;
216 } 216 }
217 217
218 return true; 218 return true;
219 } 219 }
220 220
221 bool PairingRegistryDelegateWin::Delete(const std::string& client_id) { 221 bool PairingRegistryDelegateWin::Delete(const std::string& client_id) {
222 if (!privileged_.Valid()) { 222 if (!privileged_.Valid()) {
223 LOG(ERROR) << "Cannot delete pairing entry '" << client_id 223 LOG(ERROR) << "Cannot delete pairing entry '" << client_id
224 << "': the delegate is read-only."; 224 << "': the delegate is read-only.";
225 return false; 225 return false;
226 } 226 }
227 227
228 // presubmit: allow wstring 228 // presubmit: allow wstring
229 std::wstring value_name = UTF8ToWide(client_id); 229 std::wstring value_name = base::UTF8ToWide(client_id);
230 LONG result = privileged_.DeleteValue(value_name.c_str()); 230 LONG result = privileged_.DeleteValue(value_name.c_str());
231 if (result != ERROR_SUCCESS && 231 if (result != ERROR_SUCCESS &&
232 result != ERROR_FILE_NOT_FOUND && 232 result != ERROR_FILE_NOT_FOUND &&
233 result != ERROR_PATH_NOT_FOUND) { 233 result != ERROR_PATH_NOT_FOUND) {
234 SetLastError(result); 234 SetLastError(result);
235 PLOG(ERROR) << "Cannot delete pairing entry '" << client_id << "'"; 235 PLOG(ERROR) << "Cannot delete pairing entry '" << client_id << "'";
236 return false; 236 return false;
237 } 237 }
238 238
239 result = unprivileged_.DeleteValue(value_name.c_str()); 239 result = unprivileged_.DeleteValue(value_name.c_str());
240 if (result != ERROR_SUCCESS && 240 if (result != ERROR_SUCCESS &&
241 result != ERROR_FILE_NOT_FOUND && 241 result != ERROR_FILE_NOT_FOUND &&
242 result != ERROR_PATH_NOT_FOUND) { 242 result != ERROR_PATH_NOT_FOUND) {
243 SetLastError(result); 243 SetLastError(result);
244 PLOG(ERROR) << "Cannot delete pairing entry '" << client_id << "'"; 244 PLOG(ERROR) << "Cannot delete pairing entry '" << client_id << "'";
245 return false; 245 return false;
246 } 246 }
247 247
248 return true; 248 return true;
249 } 249 }
250 250
251 scoped_ptr<PairingRegistry::Delegate> CreatePairingRegistryDelegate() { 251 scoped_ptr<PairingRegistry::Delegate> CreatePairingRegistryDelegate() {
252 return scoped_ptr<PairingRegistry::Delegate>(); 252 return scoped_ptr<PairingRegistry::Delegate>();
253 } 253 }
254 254
255 } // namespace remoting 255 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/ipc_util_win.cc ('k') | remoting/host/pairing_registry_delegate_win_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698