Chromium Code Reviews| Index: chrome/browser/extensions/api/storage/local_storage_backend.cc |
| diff --git a/chrome/browser/extensions/api/storage/local_storage_backend.cc b/chrome/browser/extensions/api/storage/local_storage_backend.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..c0241de6bdbe5e73e2ed89e27a279e5c91381fd6 |
| --- /dev/null |
| +++ b/chrome/browser/extensions/api/storage/local_storage_backend.cc |
| @@ -0,0 +1,55 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/extensions/api/storage/local_storage_backend.h" |
| + |
| +#include "base/file_util.h" |
| +#include "chrome/browser/extensions/api/storage/settings_storage_factory.h" |
| + |
| +namespace extensions { |
| + |
| +LocalStorageBackend::LocalStorageBackend( |
| + const scoped_refptr<SettingsStorageFactory>& storage_factory, |
| + const base::FilePath& base_path, |
| + const SettingsStorageQuotaEnforcer::Limits& quota) |
| + : SettingsBackend(storage_factory, base_path, quota) {} |
| + |
| +LocalStorageBackend::~LocalStorageBackend() {} |
| + |
| +ValueStore* LocalStorageBackend::GetStorage(const std::string& extension_id) { |
| + StorageMap::iterator iter = storage_map_.find(extension_id); |
| + if (iter != storage_map_.end()) |
| + return iter->second.get(); |
| + |
| + // Unlike SyncStorageBackend, we don't check for corruption at initialization. |
| + // This is because a) we don't need to, since we'll catch it when we try to |
| + // use it in an API call, and b) because local storage can be much larger |
| + // than sync storage, resulting in a much more significant overhead. |
| + linked_ptr<ValueStore> storage(new SettingsStorageQuotaEnforcer( |
| + quota(), storage_factory()->Create(base_path(), extension_id))); |
| + |
| + storage_map_[extension_id] = storage; |
| + return storage.get(); |
| +} |
| + |
| +void LocalStorageBackend::DeleteStorage(const std::string& extension_id) { |
| + // Clear settings when the extension is uninstalled. Leveldb implementations |
| + // will also delete the database from disk when the object is destroyed as a |
| + // result of being removed from |storage_map_|. |
| + StorageMap::iterator iter = storage_map_.find(extension_id); |
| + if (iter == storage_map_.end()) { |
| + // If the key isn't in |storage_map_|, it's possible that the extension |
| + // still has storage and that the storage area was just unloaded. Check if |
| + // the path exists, and, if it does, load it in order to delete it. |
| + if (base::PathExists( |
| + storage_factory()->GetDatabasePath(base_path(), extension_id))) { |
| + GetStorage(extension_id); |
|
not at google - send to devlin
2014/02/14 19:35:56
Creating a storage area here just to delete it str
Devlin
2014/02/18 23:55:22
Initially, I thought there was more cleanup involv
|
| + } else { |
| + return; |
| + } |
| + } |
| + storage_map_.erase(extension_id); |
| +} |
| + |
| +} // namespace extensions |