| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/value_store/legacy_value_store_factory.h" | 5 #include "extensions/browser/value_store/legacy_value_store_factory.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/files/file_enumerator.h" | 9 #include "base/files/file_enumerator.h" |
| 10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| 11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "content/public/browser/browser_thread.h" | 12 #include "base/threading/thread_restrictions.h" |
| 13 #include "extensions/browser/value_store/leveldb_value_store.h" | 13 #include "extensions/browser/value_store/leveldb_value_store.h" |
| 14 #include "extensions/common/constants.h" | 14 #include "extensions/common/constants.h" |
| 15 | 15 |
| 16 using base::AutoLock; | 16 using base::AutoLock; |
| 17 using content::BrowserThread; | |
| 18 | 17 |
| 19 namespace { | 18 namespace { |
| 20 | 19 |
| 21 // Statistics are logged to UMA with these strings as part of histogram name. | 20 // Statistics are logged to UMA with these strings as part of histogram name. |
| 22 // They can all be found under Extensions.Database.Open.<client>. Changing this | 21 // They can all be found under Extensions.Database.Open.<client>. Changing this |
| 23 // needs to synchronize with histograms.xml, AND will also become incompatible | 22 // needs to synchronize with histograms.xml, AND will also become incompatible |
| 24 // with older browsers still reporting the previous values. | 23 // with older browsers still reporting the previous values. |
| 25 const char kSettingsDatabaseUMAClientName[] = "Settings"; | 24 const char kSettingsDatabaseUMAClientName[] = "Settings"; |
| 26 const char kRulesDatabaseUMAClientName[] = "Rules"; | 25 const char kRulesDatabaseUMAClientName[] = "Rules"; |
| 27 const char kStateDatabaseUMAClientName[] = "State"; | 26 const char kStateDatabaseUMAClientName[] = "State"; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 52 return base::DeleteFile(GetDBPath(extension_id), true /* recursive */); | 51 return base::DeleteFile(GetDBPath(extension_id), true /* recursive */); |
| 53 } | 52 } |
| 54 | 53 |
| 55 bool LegacyValueStoreFactory::ModelSettings::DataExists( | 54 bool LegacyValueStoreFactory::ModelSettings::DataExists( |
| 56 const ExtensionId& extension_id) const { | 55 const ExtensionId& extension_id) const { |
| 57 return ValidDBExists(GetDBPath(extension_id)); | 56 return ValidDBExists(GetDBPath(extension_id)); |
| 58 } | 57 } |
| 59 | 58 |
| 60 std::set<ExtensionId> | 59 std::set<ExtensionId> |
| 61 LegacyValueStoreFactory::ModelSettings::GetKnownExtensionIDs() const { | 60 LegacyValueStoreFactory::ModelSettings::GetKnownExtensionIDs() const { |
| 62 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 61 base::ThreadRestrictions::AssertIOAllowed(); |
| 63 std::set<ExtensionId> result; | 62 std::set<ExtensionId> result; |
| 64 | 63 |
| 65 // Leveldb databases are directories inside |base_path_|. | 64 // Leveldb databases are directories inside |base_path_|. |
| 66 base::FileEnumerator extension_dirs(data_path_, false, | 65 base::FileEnumerator extension_dirs(data_path_, false, |
| 67 base::FileEnumerator::DIRECTORIES); | 66 base::FileEnumerator::DIRECTORIES); |
| 68 while (!extension_dirs.Next().empty()) { | 67 while (!extension_dirs.Next().empty()) { |
| 69 base::FilePath extension_dir = extension_dirs.GetInfo().GetName(); | 68 base::FilePath extension_dir = extension_dirs.GetInfo().GetName(); |
| 70 DCHECK(!extension_dir.IsAbsolute()); | 69 DCHECK(!extension_dir.IsAbsolute()); |
| 71 // Extension ID's are 'a'..'p', so any directory within this folder will | 70 // Extension ID's are 'a'..'p', so any directory within this folder will |
| 72 // either be ASCII, or created by some other application and safe to ignore. | 71 // either be ASCII, or created by some other application and safe to ignore. |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 DCHECK(extensions_ != nullptr); | 120 DCHECK(extensions_ != nullptr); |
| 122 return extensions_.get(); | 121 return extensions_.get(); |
| 123 } | 122 } |
| 124 NOTREACHED(); | 123 NOTREACHED(); |
| 125 return nullptr; | 124 return nullptr; |
| 126 } | 125 } |
| 127 | 126 |
| 128 std::set<ExtensionId> | 127 std::set<ExtensionId> |
| 129 LegacyValueStoreFactory::SettingsRoot::GetKnownExtensionIDs( | 128 LegacyValueStoreFactory::SettingsRoot::GetKnownExtensionIDs( |
| 130 ModelType model_type) const { | 129 ModelType model_type) const { |
| 131 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 130 base::ThreadRestrictions::AssertIOAllowed(); |
| 132 switch (model_type) { | 131 switch (model_type) { |
| 133 case ValueStoreFactory::ModelType::APP: | 132 case ValueStoreFactory::ModelType::APP: |
| 134 DCHECK(apps_ != nullptr); | 133 DCHECK(apps_ != nullptr); |
| 135 return apps_->GetKnownExtensionIDs(); | 134 return apps_->GetKnownExtensionIDs(); |
| 136 case ValueStoreFactory::ModelType::EXTENSION: | 135 case ValueStoreFactory::ModelType::EXTENSION: |
| 137 DCHECK(extensions_ != nullptr); | 136 DCHECK(extensions_ != nullptr); |
| 138 return extensions_->GetKnownExtensionIDs(); | 137 return extensions_->GetKnownExtensionIDs(); |
| 139 } | 138 } |
| 140 NOTREACHED(); | 139 NOTREACHED(); |
| 141 return std::set<ExtensionId>(); | 140 return std::set<ExtensionId>(); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 GetSettingsRoot(settings_namespace).GetModel(model_type); | 184 GetSettingsRoot(settings_namespace).GetModel(model_type); |
| 186 DCHECK(settings_root != nullptr); | 185 DCHECK(settings_root != nullptr); |
| 187 return base::MakeUnique<LeveldbValueStore>( | 186 return base::MakeUnique<LeveldbValueStore>( |
| 188 kSettingsDatabaseUMAClientName, settings_root->GetDBPath(extension_id)); | 187 kSettingsDatabaseUMAClientName, settings_root->GetDBPath(extension_id)); |
| 189 } | 188 } |
| 190 | 189 |
| 191 void LegacyValueStoreFactory::DeleteSettings( | 190 void LegacyValueStoreFactory::DeleteSettings( |
| 192 settings_namespace::Namespace settings_namespace, | 191 settings_namespace::Namespace settings_namespace, |
| 193 ModelType model_type, | 192 ModelType model_type, |
| 194 const ExtensionId& extension_id) { | 193 const ExtensionId& extension_id) { |
| 195 // TODO(cmumford): Verify that we always need to be called on FILE thread. | 194 base::ThreadRestrictions::AssertIOAllowed(); |
| 196 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | |
| 197 ModelSettings* model_settings = | 195 ModelSettings* model_settings = |
| 198 GetSettingsRoot(settings_namespace).GetModel(model_type); | 196 GetSettingsRoot(settings_namespace).GetModel(model_type); |
| 199 if (model_settings == nullptr) { | 197 if (model_settings == nullptr) { |
| 200 NOTREACHED(); | 198 NOTREACHED(); |
| 201 return; | 199 return; |
| 202 } | 200 } |
| 203 model_settings->DeleteData(extension_id); | 201 model_settings->DeleteData(extension_id); |
| 204 } | 202 } |
| 205 | 203 |
| 206 bool LegacyValueStoreFactory::HasSettings( | 204 bool LegacyValueStoreFactory::HasSettings( |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 | 253 |
| 256 base::FilePath LegacyValueStoreFactory::GetRulesDBPath() const { | 254 base::FilePath LegacyValueStoreFactory::GetRulesDBPath() const { |
| 257 return profile_path_.AppendASCII(kRulesStoreName); | 255 return profile_path_.AppendASCII(kRulesStoreName); |
| 258 } | 256 } |
| 259 | 257 |
| 260 base::FilePath LegacyValueStoreFactory::GetStateDBPath() const { | 258 base::FilePath LegacyValueStoreFactory::GetStateDBPath() const { |
| 261 return profile_path_.AppendASCII(kStateStoreName); | 259 return profile_path_.AppendASCII(kStateStoreName); |
| 262 } | 260 } |
| 263 | 261 |
| 264 } // namespace extensions | 262 } // namespace extensions |
| OLD | NEW |