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

Side by Side Diff: chrome/browser/prefs/pref_model_associator.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
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/browser/prefs/pref_model_associator.h" 5 #include "chrome/browser/prefs/pref_model_associator.h"
6 6
7 #include "base/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "base/json/json_reader.h" 8 #include "base/json/json_reader.h"
9 #include "base/json/json_string_value_serializer.h" 9 #include "base/json/json_string_value_serializer.h"
10 #include "base/location.h" 10 #include "base/location.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 VLOG(1) << "Associating preference " << pref_name; 42 VLOG(1) << "Associating preference " << pref_name;
43 43
44 base::JSONReader reader; 44 base::JSONReader reader;
45 if (sync_pref.IsValid()) { 45 if (sync_pref.IsValid()) {
46 // The server has a value for the preference, we have to reconcile it with 46 // The server has a value for the preference, we have to reconcile it with
47 // ours. 47 // ours.
48 const sync_pb::PreferenceSpecifics& preference = 48 const sync_pb::PreferenceSpecifics& preference =
49 sync_pref.GetSpecifics().preference(); 49 sync_pref.GetSpecifics().preference();
50 DCHECK_EQ(pref->name(), preference.name()); 50 DCHECK_EQ(pref->name(), preference.name());
51 51
52 scoped_ptr<Value> value( 52 scoped_ptr<Value> value(reader.ReadToValue(preference.value()));
53 reader.JsonToValue(preference.value(), false, false));
54 if (!value.get()) { 53 if (!value.get()) {
55 LOG(ERROR) << "Failed to deserialize preference value: " 54 LOG(ERROR) << "Failed to deserialize preference value: "
56 << reader.GetErrorMessage(); 55 << reader.GetErrorMessage();
57 return; 56 return;
58 } 57 }
59 58
60 // Merge the server value of this preference with the local value. 59 // Merge the server value of this preference with the local value.
61 scoped_ptr<Value> new_value(MergePreference(*pref, *value)); 60 scoped_ptr<Value> new_value(MergePreference(*pref, *value));
62 61
63 // Update the local preference based on what we got from the 62 // Update the local preference based on what we got from the
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 synced_preferences_.insert(name); 347 synced_preferences_.insert(name);
349 } 348 }
350 } 349 }
351 return SyncError(); 350 return SyncError();
352 } 351 }
353 352
354 Value* PrefModelAssociator::ReadPreferenceSpecifics( 353 Value* PrefModelAssociator::ReadPreferenceSpecifics(
355 const sync_pb::PreferenceSpecifics& preference, 354 const sync_pb::PreferenceSpecifics& preference,
356 std::string* name) { 355 std::string* name) {
357 base::JSONReader reader; 356 base::JSONReader reader;
358 scoped_ptr<Value> value(reader.JsonToValue(preference.value(), false, false)); 357 scoped_ptr<Value> value(reader.ReadToValue(preference.value()));
359 if (!value.get()) { 358 if (!value.get()) {
360 std::string err = "Failed to deserialize preference value: " + 359 std::string err = "Failed to deserialize preference value: " +
361 reader.GetErrorMessage(); 360 reader.GetErrorMessage();
362 LOG(ERROR) << err; 361 LOG(ERROR) << err;
363 return NULL; 362 return NULL;
364 } 363 }
365 *name = preference.name(); 364 *name = preference.name();
366 return value.release(); 365 return value.release();
367 } 366 }
368 367
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 } 427 }
429 428
430 SyncError error = 429 SyncError error =
431 sync_processor_->ProcessSyncChanges(FROM_HERE, changes); 430 sync_processor_->ProcessSyncChanges(FROM_HERE, changes);
432 } 431 }
433 432
434 void PrefModelAssociator::SetPrefService(PrefService* pref_service) { 433 void PrefModelAssociator::SetPrefService(PrefService* pref_service) {
435 DCHECK(pref_service_ == NULL); 434 DCHECK(pref_service_ == NULL);
436 pref_service_ = pref_service; 435 pref_service_ = pref_service;
437 } 436 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698