Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/prefs/incognito_user_pref_store.h" | |
| 6 | |
| 7 #include "base/memory/scoped_ptr.h" | |
| 8 #include "base/values.h" | |
| 9 #include "chrome/common/pref_names.h" | |
| 10 | |
| 11 IncognitoUserPrefStore::IncognitoUserPrefStore( | |
| 12 PersistentPrefStore* underlay) | |
| 13 : underlay_(underlay) { | |
| 14 underlay_->AddObserver(this); | |
| 15 } | |
| 16 | |
| 17 IncognitoUserPrefStore::~IncognitoUserPrefStore() { | |
| 18 underlay_->RemoveObserver(this); | |
| 19 } | |
| 20 | |
| 21 bool IncognitoUserPrefStore::IsSetInOverlay(const std::string& key) const { | |
| 22 return overlay_.GetValue(key, NULL); | |
| 23 } | |
| 24 | |
| 25 void IncognitoUserPrefStore::AddObserver(PrefStore::Observer* observer) { | |
| 26 observers_.AddObserver(observer); | |
| 27 } | |
| 28 | |
| 29 void IncognitoUserPrefStore::RemoveObserver(PrefStore::Observer* observer) { | |
| 30 observers_.RemoveObserver(observer); | |
| 31 } | |
| 32 | |
| 33 bool IncognitoUserPrefStore::IsInitializationComplete() const { | |
| 34 return underlay_->IsInitializationComplete(); | |
| 35 } | |
| 36 | |
| 37 PrefStore::ReadResult IncognitoUserPrefStore::GetValue( | |
| 38 const std::string& key, | |
| 39 const Value** result) const { | |
| 40 if (!StoreInOverlay(key)) | |
|
Mattias Nissler (ping if slow)
2011/07/13 12:15:32
This shouldn't be necessary, since we should not p
battre
2011/07/14 12:31:56
Done.
| |
| 41 return underlay_->GetValue(key, result); | |
| 42 | |
| 43 if (overlay_.GetValue(key, result)) | |
| 44 return READ_OK; | |
| 45 return underlay_->GetValue(key, result); | |
| 46 } | |
| 47 | |
| 48 PrefStore::ReadResult IncognitoUserPrefStore::GetMutableValue( | |
| 49 const std::string& key, | |
| 50 Value** result) { | |
| 51 if (!StoreInOverlay(key)) | |
| 52 return underlay_->GetMutableValue(key, result); | |
| 53 | |
| 54 if (overlay_.GetValue(key, result)) | |
| 55 return READ_OK; | |
| 56 | |
| 57 // Try to create copy of underlay if the overlay does not contain a value. | |
| 58 Value* underlay_value = NULL; | |
| 59 PrefStore::ReadResult read_result = | |
| 60 underlay_->GetMutableValue(key, &underlay_value); | |
| 61 if (read_result == READ_OK) { | |
|
Peter Kasting
2011/07/13 22:02:06
Nit: Shorter:
if (read_result != READ_OK)
retur
battre
2011/07/14 12:31:56
Done.
| |
| 62 *result = underlay_value->DeepCopy(); | |
| 63 overlay_.SetValue(key, *result); | |
| 64 return READ_OK; | |
| 65 } | |
| 66 // Return read failure if underlay stores no value for |key|. | |
|
Peter Kasting
2011/07/13 22:02:06
Nit: This comment doesn't really add much to the c
battre
2011/07/14 12:31:56
Done.
| |
| 67 return read_result; | |
| 68 } | |
| 69 | |
| 70 void IncognitoUserPrefStore::SetValue(const std::string& key, | |
| 71 Value* value) { | |
| 72 if (!StoreInOverlay(key)) { | |
| 73 underlay_->SetValue(key, value); | |
| 74 return; | |
| 75 } | |
| 76 | |
| 77 if (overlay_.SetValue(key, value)) | |
| 78 ReportValueChanged(key); | |
| 79 } | |
| 80 | |
| 81 void IncognitoUserPrefStore::SetValueSilently(const std::string& key, | |
| 82 Value* value) { | |
| 83 if (!StoreInOverlay(key)) { | |
|
Peter Kasting
2011/07/13 22:02:06
Nit: Shorter:
if (StoreInOverlay(key))
overlay_
battre
2011/07/13 22:28:32
Hm, do you prefer brevity over common patterns? Al
| |
| 84 underlay_->SetValueSilently(key, value); | |
| 85 return; | |
| 86 } | |
| 87 | |
| 88 overlay_.SetValue(key, value); | |
| 89 } | |
| 90 | |
| 91 void IncognitoUserPrefStore::RemoveValue(const std::string& key) { | |
| 92 if (!StoreInOverlay(key)) { | |
| 93 underlay_->RemoveValue(key); | |
| 94 return; | |
| 95 } | |
| 96 | |
| 97 if (overlay_.RemoveValue(key)) | |
| 98 ReportValueChanged(key); | |
| 99 } | |
| 100 | |
| 101 bool IncognitoUserPrefStore::ReadOnly() const { | |
| 102 return false; | |
| 103 } | |
| 104 | |
| 105 PersistentPrefStore::PrefReadError IncognitoUserPrefStore::ReadPrefs() { | |
| 106 // We do not read intentionally. | |
| 107 OnInitializationCompleted(true); | |
| 108 return PersistentPrefStore::PREF_READ_ERROR_NONE; | |
| 109 } | |
| 110 | |
| 111 void IncognitoUserPrefStore::ReadPrefsAsync( | |
| 112 ReadErrorDelegate* error_delegate_raw) { | |
| 113 scoped_ptr<ReadErrorDelegate> error_delegate(error_delegate_raw); | |
| 114 // We do not read intentionally. | |
| 115 OnInitializationCompleted(true); | |
| 116 } | |
| 117 | |
| 118 bool IncognitoUserPrefStore::WritePrefs() { | |
| 119 // We do not write our content intentionally. | |
| 120 return true; | |
| 121 } | |
| 122 | |
| 123 void IncognitoUserPrefStore::ScheduleWritePrefs() { | |
| 124 underlay_->ScheduleWritePrefs(); | |
| 125 // We do not write our content intentionally. | |
| 126 } | |
| 127 | |
| 128 void IncognitoUserPrefStore::CommitPendingWrite() { | |
| 129 underlay_->CommitPendingWrite(); | |
| 130 // We do not write our content intentionally. | |
| 131 } | |
| 132 | |
| 133 void IncognitoUserPrefStore::ReportValueChanged(const std::string& key) { | |
| 134 FOR_EACH_OBSERVER(PrefStore::Observer, observers_, OnPrefValueChanged(key)); | |
| 135 } | |
| 136 | |
| 137 void IncognitoUserPrefStore::OnPrefValueChanged(const std::string& key) { | |
| 138 if (!overlay_.GetValue(key, NULL)) | |
| 139 ReportValueChanged(key); | |
| 140 } | |
| 141 | |
| 142 void IncognitoUserPrefStore::OnInitializationCompleted(bool succeeded) { | |
| 143 FOR_EACH_OBSERVER(PrefStore::Observer, observers_, | |
| 144 OnInitializationCompleted(succeeded)); | |
| 145 } | |
| 146 | |
| 147 bool IncognitoUserPrefStore::StoreInOverlay(const std::string& key) const { | |
| 148 // We exclude some preferences from being stored in a non-persisted | |
| 149 // incognito user pref store. These settings are stored in the regular | |
| 150 // user pref store on disk even if they are modified from within an | |
| 151 // incognito profile. | |
| 152 if (key == prefs::kCheckDefaultBrowser) | |
|
Peter Kasting
2011/07/13 22:02:06
Nit: Seems just as good, and shorter:
return (key
battre
2011/07/14 12:31:56
Done.
| |
| 153 return false; | |
| 154 if (key == prefs::kShowBookmarkBar) | |
| 155 return false; | |
| 156 | |
| 157 return true; | |
| 158 } | |
| OLD | NEW |