Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "base/prefs/json_pref_store.h" | 5 #include "base/prefs/json_pref_store.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
| 12 #include "base/json/json_file_value_serializer.h" | 12 #include "base/json/json_file_value_serializer.h" |
| 13 #include "base/json/json_string_value_serializer.h" | 13 #include "base/json/json_string_value_serializer.h" |
| 14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 15 #include "base/message_loop/message_loop_proxy.h" | 15 #include "base/message_loop/message_loop_proxy.h" |
| 16 #include "base/metrics/histogram.h" | |
| 16 #include "base/prefs/pref_filter.h" | 17 #include "base/prefs/pref_filter.h" |
| 17 #include "base/sequenced_task_runner.h" | 18 #include "base/sequenced_task_runner.h" |
| 18 #include "base/threading/sequenced_worker_pool.h" | 19 #include "base/threading/sequenced_worker_pool.h" |
| 20 #include "base/time/time.h" | |
| 19 #include "base/values.h" | 21 #include "base/values.h" |
| 20 | 22 |
| 21 namespace { | 23 namespace { |
| 22 | 24 |
| 23 // Some extensions we'll tack on to copies of the Preferences files. | 25 // Some extensions we'll tack on to copies of the Preferences files. |
| 24 const base::FilePath::CharType* kBadExtension = FILE_PATH_LITERAL("bad"); | 26 const base::FilePath::CharType* kBadExtension = FILE_PATH_LITERAL("bad"); |
| 25 | 27 |
| 26 // Differentiates file loading between origin thread and passed | 28 // Differentiates file loading between origin thread and passed |
| 27 // (aka file) thread. | 29 // (aka file) thread. |
| 28 class FileThreadDeserializer | 30 class FileThreadDeserializer |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 307 // If the file just doesn't exist, maybe this is first run. In any case | 309 // If the file just doesn't exist, maybe this is first run. In any case |
| 308 // there's no harm in writing out default prefs in this case. | 310 // there's no harm in writing out default prefs in this case. |
| 309 break; | 311 break; |
| 310 case PREF_READ_ERROR_JSON_PARSE: | 312 case PREF_READ_ERROR_JSON_PARSE: |
| 311 case PREF_READ_ERROR_JSON_REPEAT: | 313 case PREF_READ_ERROR_JSON_REPEAT: |
| 312 break; | 314 break; |
| 313 default: | 315 default: |
| 314 NOTREACHED() << "Unknown error: " << error; | 316 NOTREACHED() << "Unknown error: " << error; |
| 315 } | 317 } |
| 316 | 318 |
| 317 if (pref_filter_) | 319 if (pref_filter_) { |
| 320 // TODO(gab): Remove this histogram after sufficient timing data has been | |
| 321 // gathered from the wild to be confident this doesn't significantly affect | |
| 322 // startup. | |
|
Nico
2014/01/29 17:58:13
Put a date on this ("remove by Feb 14" or similar)
gab
2014/01/29 19:15:56
Done, used Feb 21, might be before if the data app
| |
| 323 base::TimeTicks checkpoint = base::TimeTicks::Now(); | |
| 318 pref_filter_->FilterOnLoad(prefs_.get()); | 324 pref_filter_->FilterOnLoad(prefs_.get()); |
| 325 UMA_HISTOGRAM_TIMES("Settings.FilterOnLoadTime", | |
| 326 base::TimeTicks::Now() - checkpoint); | |
| 327 } | |
| 319 | 328 |
| 320 if (error_delegate_.get() && error != PREF_READ_ERROR_NONE) | 329 if (error_delegate_.get() && error != PREF_READ_ERROR_NONE) |
| 321 error_delegate_->OnError(error); | 330 error_delegate_->OnError(error); |
| 322 | 331 |
| 323 FOR_EACH_OBSERVER(PrefStore::Observer, | 332 FOR_EACH_OBSERVER(PrefStore::Observer, |
| 324 observers_, | 333 observers_, |
| 325 OnInitializationCompleted(true)); | 334 OnInitializationCompleted(true)); |
| 326 } | 335 } |
| 327 | 336 |
| 328 JsonPrefStore::~JsonPrefStore() { | 337 JsonPrefStore::~JsonPrefStore() { |
| 329 CommitPendingWrite(); | 338 CommitPendingWrite(); |
| 330 } | 339 } |
| 331 | 340 |
| 332 bool JsonPrefStore::SerializeData(std::string* output) { | 341 bool JsonPrefStore::SerializeData(std::string* output) { |
| 333 if (pref_filter_) | 342 if (pref_filter_) { |
| 343 // TODO(gab): Remove this histogram after sufficient timing data has been | |
| 344 // gathered from the wild to be confident this doesn't significantly affect | |
| 345 // performance on the UI thread. | |
| 346 base::TimeTicks checkpoint = base::TimeTicks::Now(); | |
| 334 pref_filter_->FilterSerializeData(prefs_.get()); | 347 pref_filter_->FilterSerializeData(prefs_.get()); |
| 348 UMA_HISTOGRAM_TIMES("Settings.FilterSerializeDataTime", | |
| 349 base::TimeTicks::Now() - checkpoint); | |
| 350 } | |
| 335 | 351 |
| 336 JSONStringValueSerializer serializer(output); | 352 JSONStringValueSerializer serializer(output); |
| 337 serializer.set_pretty_print(true); | 353 serializer.set_pretty_print(true); |
| 338 return serializer.Serialize(*prefs_); | 354 return serializer.Serialize(*prefs_); |
| 339 } | 355 } |
| OLD | NEW |