Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: chrome/browser/extensions/api/storage/local_storage_backend.cc

Issue 165223003: Add a Restore() method to ValueStore and make StorageAPI use it (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/extensions/api/storage/local_storage_backend.h"
6
7 #include "base/file_util.h"
8 #include "chrome/browser/extensions/api/storage/settings_storage_factory.h"
9
10 namespace extensions {
11
12 LocalStorageBackend::LocalStorageBackend(
13 const scoped_refptr<SettingsStorageFactory>& storage_factory,
14 const base::FilePath& base_path,
15 const SettingsStorageQuotaEnforcer::Limits& quota)
16 : SettingsBackend(storage_factory, base_path, quota) {}
17
18 LocalStorageBackend::~LocalStorageBackend() {}
19
20 ValueStore* LocalStorageBackend::GetStorage(const std::string& extension_id) {
21 StorageMap::iterator iter = storage_map_.find(extension_id);
22 if (iter != storage_map_.end())
23 return iter->second.get();
24
25 // Unlike SyncStorageBackend, we don't check for corruption at initialization.
26 // This is because a) we don't need to, since we'll catch it when we try to
27 // use it in an API call, and b) because local storage can be much larger
28 // than sync storage, resulting in a much more significant overhead.
29 linked_ptr<ValueStore> storage(new SettingsStorageQuotaEnforcer(
30 quota(), storage_factory()->Create(base_path(), extension_id)));
31
32 storage_map_[extension_id] = storage;
33 return storage.get();
34 }
35
36 void LocalStorageBackend::DeleteStorage(const std::string& extension_id) {
37 // Clear settings when the extension is uninstalled. Leveldb implementations
38 // will also delete the database from disk when the object is destroyed as a
39 // result of being removed from |storage_map_|.
40 StorageMap::iterator iter = storage_map_.find(extension_id);
41 if (iter == storage_map_.end()) {
42 // If the key isn't in |storage_map_|, it's possible that the extension
43 // still has storage and that the storage area was just unloaded. Check if
44 // the path exists, and, if it does, load it in order to delete it.
45 if (base::PathExists(
46 storage_factory()->GetDatabasePath(base_path(), extension_id))) {
47 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
48 } else {
49 return;
50 }
51 }
52 storage_map_.erase(extension_id);
53 }
54
55 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698