| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/browser/extension_pref_value_map.h" | 5 #include "extensions/browser/extension_pref_value_map.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" |
| 7 #include "base/values.h" | 8 #include "base/values.h" |
| 8 #include "components/prefs/pref_value_map.h" | 9 #include "components/prefs/pref_value_map.h" |
| 9 | 10 |
| 10 using extensions::ExtensionPrefsScope; | 11 using extensions::ExtensionPrefsScope; |
| 11 | 12 |
| 12 struct ExtensionPrefValueMap::ExtensionEntry { | 13 struct ExtensionPrefValueMap::ExtensionEntry { |
| 13 // Installation time of the extension. | 14 // Installation time of the extension. |
| 14 base::Time install_time; | 15 base::Time install_time; |
| 15 // Whether extension is enabled in the profile. | 16 // Whether extension is enabled in the profile. |
| 16 bool enabled; | 17 bool enabled; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 43 NotifyOfDestruction(); | 44 NotifyOfDestruction(); |
| 44 destroyed_ = true; | 45 destroyed_ = true; |
| 45 } | 46 } |
| 46 | 47 |
| 47 void ExtensionPrefValueMap::SetExtensionPref(const std::string& ext_id, | 48 void ExtensionPrefValueMap::SetExtensionPref(const std::string& ext_id, |
| 48 const std::string& key, | 49 const std::string& key, |
| 49 ExtensionPrefsScope scope, | 50 ExtensionPrefsScope scope, |
| 50 base::Value* value) { | 51 base::Value* value) { |
| 51 PrefValueMap* prefs = GetExtensionPrefValueMap(ext_id, scope); | 52 PrefValueMap* prefs = GetExtensionPrefValueMap(ext_id, scope); |
| 52 | 53 |
| 53 if (prefs->SetValue(key, make_scoped_ptr(value))) | 54 if (prefs->SetValue(key, base::WrapUnique(value))) |
| 54 NotifyPrefValueChanged(key); | 55 NotifyPrefValueChanged(key); |
| 55 } | 56 } |
| 56 | 57 |
| 57 void ExtensionPrefValueMap::RemoveExtensionPref( | 58 void ExtensionPrefValueMap::RemoveExtensionPref( |
| 58 const std::string& ext_id, | 59 const std::string& ext_id, |
| 59 const std::string& key, | 60 const std::string& key, |
| 60 ExtensionPrefsScope scope) { | 61 ExtensionPrefsScope scope) { |
| 61 PrefValueMap* prefs = GetExtensionPrefValueMap(ext_id, scope); | 62 PrefValueMap* prefs = GetExtensionPrefValueMap(ext_id, scope); |
| 62 if (prefs->RemoveValue(key)) | 63 if (prefs->RemoveValue(key)) |
| 63 NotifyPrefValueChanged(key); | 64 NotifyPrefValueChanged(key); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 if (winner == entries_.end()) | 114 if (winner == entries_.end()) |
| 114 return false; | 115 return false; |
| 115 return winner->first == extension_id; | 116 return winner->first == extension_id; |
| 116 } | 117 } |
| 117 | 118 |
| 118 void ExtensionPrefValueMap::RegisterExtension(const std::string& ext_id, | 119 void ExtensionPrefValueMap::RegisterExtension(const std::string& ext_id, |
| 119 const base::Time& install_time, | 120 const base::Time& install_time, |
| 120 bool is_enabled, | 121 bool is_enabled, |
| 121 bool is_incognito_enabled) { | 122 bool is_incognito_enabled) { |
| 122 if (entries_.find(ext_id) == entries_.end()) { | 123 if (entries_.find(ext_id) == entries_.end()) { |
| 123 entries_[ext_id] = make_scoped_ptr(new ExtensionEntry); | 124 entries_[ext_id] = base::WrapUnique(new ExtensionEntry); |
| 124 | 125 |
| 125 // Only update the install time if the extension is newly installed. | 126 // Only update the install time if the extension is newly installed. |
| 126 entries_[ext_id]->install_time = install_time; | 127 entries_[ext_id]->install_time = install_time; |
| 127 } | 128 } |
| 128 | 129 |
| 129 entries_[ext_id]->enabled = is_enabled; | 130 entries_[ext_id]->enabled = is_enabled; |
| 130 entries_[ext_id]->incognito_enabled = is_incognito_enabled; | 131 entries_[ext_id]->incognito_enabled = is_incognito_enabled; |
| 131 } | 132 } |
| 132 | 133 |
| 133 void ExtensionPrefValueMap::UnregisterExtension(const std::string& ext_id) { | 134 void ExtensionPrefValueMap::UnregisterExtension(const std::string& ext_id) { |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 | 390 |
| 390 void ExtensionPrefValueMap::NotifyPrefValueChanged(const std::string& key) { | 391 void ExtensionPrefValueMap::NotifyPrefValueChanged(const std::string& key) { |
| 391 FOR_EACH_OBSERVER(ExtensionPrefValueMap::Observer, observers_, | 392 FOR_EACH_OBSERVER(ExtensionPrefValueMap::Observer, observers_, |
| 392 OnPrefValueChanged(key)); | 393 OnPrefValueChanged(key)); |
| 393 } | 394 } |
| 394 | 395 |
| 395 void ExtensionPrefValueMap::NotifyOfDestruction() { | 396 void ExtensionPrefValueMap::NotifyOfDestruction() { |
| 396 FOR_EACH_OBSERVER(ExtensionPrefValueMap::Observer, observers_, | 397 FOR_EACH_OBSERVER(ExtensionPrefValueMap::Observer, observers_, |
| 397 OnExtensionPrefValueMapDestruction()); | 398 OnExtensionPrefValueMapDestruction()); |
| 398 } | 399 } |
| OLD | NEW |