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

Side by Side Diff: chrome/test/base/ui_test_utils.cc

Issue 10035042: Rewrite base::JSONReader to be 35-40% faster, depending on the input string. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Really fix Windows, address comments Created 8 years, 7 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 | « chrome/installer/util/master_preferences_unittest.cc ('k') | net/test/base_test_server.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 "chrome/test/base/ui_test_utils.h" 5 #include "chrome/test/base/ui_test_utils.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <windows.h> 8 #include <windows.h>
9 #endif 9 #endif
10 10
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 std::string json; 242 std::string json;
243 if (!dom_op_observer.GetResponse(&json)) { 243 if (!dom_op_observer.GetResponse(&json)) {
244 DLOG(ERROR) << "Cannot communicate with DOMOperationObserver."; 244 DLOG(ERROR) << "Cannot communicate with DOMOperationObserver.";
245 return false; 245 return false;
246 } 246 }
247 247
248 // Nothing more to do for callers that ignore the returned JS value. 248 // Nothing more to do for callers that ignore the returned JS value.
249 if (!result) 249 if (!result)
250 return true; 250 return true;
251 251
252 // Wrap |json| in an array before deserializing because valid JSON has an 252 base::JSONReader reader(base::JSON_ALLOW_TRAILING_COMMAS);
253 // array or an object as the root. 253 result->reset(reader.ReadToValue(json));
254 json.insert(0, "["); 254 if (!result->get()) {
255 json.append("]"); 255 DLOG(ERROR) << reader.GetErrorMessage();
256
257 scoped_ptr<Value> root_val(
258 base::JSONReader::Read(json, base::JSON_ALLOW_TRAILING_COMMAS));
259 if (!root_val->IsType(Value::TYPE_LIST)) {
260 DLOG(ERROR) << "JSON result is not a list.";
261 return false; 256 return false;
262 } 257 }
263 258
264 ListValue* list = static_cast<ListValue*>(root_val.get());
265 Value* result_val;
266 if (!list || !list->GetSize() ||
267 // Remove gives us ownership of the value.
268 !list->Remove(0, &result_val)) {
269 DLOG(ERROR) << "JSON result list is empty.";
270 return false;
271 }
272
273 result->reset(result_val);
274 return true; 259 return true;
275 } 260 }
276 261
277 void RunAllPendingMessageAndSendQuit(content::BrowserThread::ID thread_id) { 262 void RunAllPendingMessageAndSendQuit(content::BrowserThread::ID thread_id) {
278 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); 263 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure());
279 RunMessageLoop(); 264 RunMessageLoop();
280 content::BrowserThread::PostTask(thread_id, FROM_HERE, 265 content::BrowserThread::PostTask(thread_id, FROM_HERE,
281 MessageLoop::QuitClosure()); 266 MessageLoop::QuitClosure());
282 } 267 }
283 268
(...skipping 983 matching lines...) Expand 10 before | Expand all | Expand 10 after
1267 int state, 1252 int state,
1268 const base::Closure& followup) { 1253 const base::Closure& followup) {
1269 if (!followup.is_null()) 1254 if (!followup.is_null())
1270 ui_controls::SendMouseEventsNotifyWhenDone(button, state, followup); 1255 ui_controls::SendMouseEventsNotifyWhenDone(button, state, followup);
1271 else 1256 else
1272 ui_controls::SendMouseEvents(button, state); 1257 ui_controls::SendMouseEvents(button, state);
1273 } 1258 }
1274 1259
1275 } // namespace internal 1260 } // namespace internal
1276 } // namespace ui_test_utils 1261 } // namespace ui_test_utils
OLDNEW
« no previous file with comments | « chrome/installer/util/master_preferences_unittest.cc ('k') | net/test/base_test_server.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698