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/files/file_path.h" |
12 #include "base/json/json_file_value_serializer.h" | 13 #include "base/json/json_file_value_serializer.h" |
13 #include "base/json/json_string_value_serializer.h" | 14 #include "base/json/json_string_value_serializer.h" |
14 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
15 #include "base/message_loop/message_loop_proxy.h" | 16 #include "base/message_loop/message_loop_proxy.h" |
| 17 #include "base/metrics/histogram.h" |
16 #include "base/prefs/pref_filter.h" | 18 #include "base/prefs/pref_filter.h" |
17 #include "base/sequenced_task_runner.h" | 19 #include "base/sequenced_task_runner.h" |
| 20 #include "base/strings/string_util.h" |
18 #include "base/threading/sequenced_worker_pool.h" | 21 #include "base/threading/sequenced_worker_pool.h" |
19 #include "base/values.h" | 22 #include "base/values.h" |
20 | 23 |
21 namespace { | 24 namespace { |
22 | 25 |
23 // Some extensions we'll tack on to copies of the Preferences files. | 26 // Some extensions we'll tack on to copies of the Preferences files. |
24 const base::FilePath::CharType* kBadExtension = FILE_PATH_LITERAL("bad"); | 27 const base::FilePath::CharType* kBadExtension = FILE_PATH_LITERAL("bad"); |
25 | 28 |
26 // Differentiates file loading between origin thread and passed | 29 // Differentiates file loading between origin thread and passed |
27 // (aka file) thread. | 30 // (aka file) thread. |
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 JsonPrefStore::~JsonPrefStore() { | 384 JsonPrefStore::~JsonPrefStore() { |
382 CommitPendingWrite(); | 385 CommitPendingWrite(); |
383 } | 386 } |
384 | 387 |
385 bool JsonPrefStore::SerializeData(std::string* output) { | 388 bool JsonPrefStore::SerializeData(std::string* output) { |
386 if (pref_filter_) | 389 if (pref_filter_) |
387 pref_filter_->FilterSerializeData(prefs_.get()); | 390 pref_filter_->FilterSerializeData(prefs_.get()); |
388 | 391 |
389 JSONStringValueSerializer serializer(output); | 392 JSONStringValueSerializer serializer(output); |
390 serializer.set_pretty_print(true); | 393 serializer.set_pretty_print(true); |
391 return serializer.Serialize(*prefs_); | 394 bool result = serializer.Serialize(*prefs_); |
| 395 |
| 396 if (result) { |
| 397 std::string spaceless_basename; |
| 398 base::ReplaceChars(path_.BaseName().MaybeAsASCII(), " ", "_", |
| 399 &spaceless_basename); |
| 400 |
| 401 // The histogram below is an expansion of the UMA_HISTOGRAM_COUNTS_10000 |
| 402 // macro adapted to allow for a dynamically suffixed histogram name. |
| 403 // Note: The factory creates and owns the histogram. |
| 404 base::HistogramBase* histogram = |
| 405 base::LinearHistogram::FactoryGet( |
| 406 "Settings.JsonDataSizeKilobytes." + spaceless_basename, |
| 407 1, |
| 408 10000, |
| 409 50, |
| 410 base::HistogramBase::kUmaTargetedHistogramFlag); |
| 411 histogram->Add(static_cast<int>(output->size()) / 1024); |
| 412 } |
| 413 |
| 414 return result; |
392 } | 415 } |
393 | 416 |
394 void JsonPrefStore::FinalizeFileRead(bool initialization_successful, | 417 void JsonPrefStore::FinalizeFileRead(bool initialization_successful, |
395 scoped_ptr<base::DictionaryValue> prefs, | 418 scoped_ptr<base::DictionaryValue> prefs, |
396 bool schedule_write) { | 419 bool schedule_write) { |
397 filtering_in_progress_ = false; | 420 filtering_in_progress_ = false; |
398 | 421 |
399 if (!initialization_successful) { | 422 if (!initialization_successful) { |
400 FOR_EACH_OBSERVER(PrefStore::Observer, | 423 FOR_EACH_OBSERVER(PrefStore::Observer, |
401 observers_, | 424 observers_, |
(...skipping 10 matching lines...) Expand all Loading... |
412 | 435 |
413 if (error_delegate_ && read_error_ != PREF_READ_ERROR_NONE) | 436 if (error_delegate_ && read_error_ != PREF_READ_ERROR_NONE) |
414 error_delegate_->OnError(read_error_); | 437 error_delegate_->OnError(read_error_); |
415 | 438 |
416 FOR_EACH_OBSERVER(PrefStore::Observer, | 439 FOR_EACH_OBSERVER(PrefStore::Observer, |
417 observers_, | 440 observers_, |
418 OnInitializationCompleted(true)); | 441 OnInitializationCompleted(true)); |
419 | 442 |
420 return; | 443 return; |
421 } | 444 } |
OLD | NEW |