OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/extensions/app_notification_storage.h" | 5 #include "chrome/browser/extensions/app_notification_storage.h" |
6 | 6 |
7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
11 #include "base/location.h" | 11 #include "base/location.h" |
12 #include "base/sys_string_conversions.h" | 12 #include "base/sys_string_conversions.h" |
13 #include "base/values.h" | 13 #include "base/values.h" |
14 #include "base/version.h" | 14 #include "base/version.h" |
15 #include "chrome/common/extensions/extension.h" | 15 #include "chrome/common/extensions/extension.h" |
16 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
17 #include "third_party/leveldatabase/src/include/leveldb/db.h" | 17 #include "third_party/leveldatabase/src/include/leveldb/db.h" |
18 | 18 |
19 using base::JSONReader; | 19 using base::JSONReader; |
20 using base::JSONWriter; | 20 using base::JSONWriter; |
21 using content::BrowserThread; | 21 using content::BrowserThread; |
22 | 22 |
| 23 namespace extensions { |
| 24 |
23 // A concrete implementation of the AppNotificationStorage interface, using | 25 // A concrete implementation of the AppNotificationStorage interface, using |
24 // LevelDb for backing storage. | 26 // LevelDb for backing storage. |
25 class LevelDbAppNotificationStorage : public AppNotificationStorage { | 27 class LevelDbAppNotificationStorage : public AppNotificationStorage { |
26 public: | 28 public: |
27 explicit LevelDbAppNotificationStorage(const FilePath& path); | 29 explicit LevelDbAppNotificationStorage(const FilePath& path); |
28 virtual ~LevelDbAppNotificationStorage(); | 30 virtual ~LevelDbAppNotificationStorage(); |
29 | 31 |
30 // Implementing the AppNotificationStorage interface. | 32 // Implementing the AppNotificationStorage interface. |
31 virtual bool GetExtensionIds(std::set<std::string>* result) OVERRIDE; | 33 virtual bool GetExtensionIds(std::set<std::string>* result) OVERRIDE; |
32 virtual bool Get(const std::string& extension_id, | 34 virtual bool Get(const std::string& extension_id, |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 126 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
125 CHECK(result); | 127 CHECK(result); |
126 if (!OpenDbIfNeeded(false)) | 128 if (!OpenDbIfNeeded(false)) |
127 return false; | 129 return false; |
128 if (!db_.get()) | 130 if (!db_.get()) |
129 return true; | 131 return true; |
130 | 132 |
131 scoped_ptr<leveldb::Iterator> iter(db_->NewIterator(read_options_)); | 133 scoped_ptr<leveldb::Iterator> iter(db_->NewIterator(read_options_)); |
132 for (iter->SeekToFirst(); iter->Valid(); iter->Next()) { | 134 for (iter->SeekToFirst(); iter->Valid(); iter->Next()) { |
133 std::string key = iter->key().ToString(); | 135 std::string key = iter->key().ToString(); |
134 if (extensions::Extension::IdIsValid(key)) | 136 if (Extension::IdIsValid(key)) |
135 result->insert(key); | 137 result->insert(key); |
136 } | 138 } |
137 | 139 |
138 return true; | 140 return true; |
139 } | 141 } |
140 | 142 |
141 bool LevelDbAppNotificationStorage::Get(const std::string& extension_id, | 143 bool LevelDbAppNotificationStorage::Get(const std::string& extension_id, |
142 AppNotificationList* result) { | 144 AppNotificationList* result) { |
143 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 145 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
144 CHECK(result); | 146 CHECK(result); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 options.create_if_missing = true; | 221 options.create_if_missing = true; |
220 leveldb::DB* db = NULL; | 222 leveldb::DB* db = NULL; |
221 leveldb::Status status = leveldb::DB::Open(options, os_path, &db); | 223 leveldb::Status status = leveldb::DB::Open(options, os_path, &db); |
222 if (!status.ok()) { | 224 if (!status.ok()) { |
223 LogLevelDbError(FROM_HERE, status); | 225 LogLevelDbError(FROM_HERE, status); |
224 return false; | 226 return false; |
225 } | 227 } |
226 db_.reset(db); | 228 db_.reset(db); |
227 return true; | 229 return true; |
228 } | 230 } |
| 231 |
| 232 } // namespace extensions |
OLD | NEW |