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/pref_service.h" | 5 #include "base/prefs/pref_service.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 // TODO(battre): Delete this. See crbug.com/373435. |
| 11 #include "base/debug/stack_trace.h" |
10 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
11 #include "base/logging.h" | 13 #include "base/logging.h" |
12 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
13 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
14 #include "base/prefs/default_pref_store.h" | 16 #include "base/prefs/default_pref_store.h" |
15 #include "base/prefs/pref_notifier_impl.h" | 17 #include "base/prefs/pref_notifier_impl.h" |
16 #include "base/prefs/pref_registry.h" | 18 #include "base/prefs/pref_registry.h" |
17 #include "base/prefs/pref_value_store.h" | 19 #include "base/prefs/pref_value_store.h" |
18 #include "base/stl_util.h" | 20 #include "base/stl_util.h" |
19 #include "base/strings/string_number_conversions.h" | 21 #include "base/strings/string_number_conversions.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 user_pref_store_(user_prefs), | 54 user_pref_store_(user_prefs), |
53 read_error_callback_(read_error_callback) { | 55 read_error_callback_(read_error_callback) { |
54 pref_notifier_->SetPrefService(this); | 56 pref_notifier_->SetPrefService(this); |
55 | 57 |
56 InitFromStorage(async); | 58 InitFromStorage(async); |
57 } | 59 } |
58 | 60 |
59 PrefService::~PrefService() { | 61 PrefService::~PrefService() { |
60 DCHECK(CalledOnValidThread()); | 62 DCHECK(CalledOnValidThread()); |
61 | 63 |
| 64 // TODO(battre): Remove the following code. It's purpose is to understand |
| 65 // whether a crash in PrefChangeRegistrar::~PrefChangeRegistrar() is caused |
| 66 // by a PrefService already being dead. See crbug.com/373435. |
| 67 std::string stack_trace = base::debug::StackTrace().ToString(); |
| 68 static_cast<PrefNotifier*>(pref_notifier_.get()) |
| 69 ->BroadcastPrefServiceDestructionTrace(stack_trace); |
| 70 |
62 // Reset pointers so accesses after destruction reliably crash. | 71 // Reset pointers so accesses after destruction reliably crash. |
63 pref_value_store_.reset(); | 72 pref_value_store_.reset(); |
64 pref_registry_ = NULL; | 73 pref_registry_ = NULL; |
65 user_pref_store_ = NULL; | 74 user_pref_store_ = NULL; |
66 pref_notifier_.reset(); | 75 pref_notifier_.reset(); |
67 } | 76 } |
68 | 77 |
69 void PrefService::InitFromStorage(bool async) { | 78 void PrefService::InitFromStorage(bool async) { |
70 if (user_pref_store_->IsInitializationComplete()) { | 79 if (user_pref_store_->IsInitializationComplete()) { |
71 read_error_callback_.Run(user_pref_store_->GetReadError()); | 80 read_error_callback_.Run(user_pref_store_->GetReadError()); |
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
546 DCHECK(found_value->IsType(default_type)); | 555 DCHECK(found_value->IsType(default_type)); |
547 return found_value; | 556 return found_value; |
548 } else { | 557 } else { |
549 // Every registered preference has at least a default value. | 558 // Every registered preference has at least a default value. |
550 NOTREACHED() << "no valid value found for registered pref " << path; | 559 NOTREACHED() << "no valid value found for registered pref " << path; |
551 } | 560 } |
552 } | 561 } |
553 | 562 |
554 return NULL; | 563 return NULL; |
555 } | 564 } |
OLD | NEW |