Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 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 #ifndef CONTENT_BROWSER_NOTIFICATIONS_NOTIFICATION_DATABASE_H_ | |
| 6 #define CONTENT_BROWSER_NOTIFICATIONS_NOTIFICATION_DATABASE_H_ | |
| 7 | |
| 8 #include "base/callback.h" | |
| 9 #include "base/files/file_path.h" | |
| 10 #include "base/sequence_checker.h" | |
| 11 #include "content/common/content_export.h" | |
| 12 | |
| 13 namespace leveldb { | |
| 14 class DB; | |
| 15 class Env; | |
| 16 } | |
| 17 | |
| 18 namespace content { | |
| 19 | |
| 20 // Implementation of the persistent notification database. | |
| 21 // | |
| 22 // This class can be constructed on any thread, but method calls must only be | |
| 23 // made on a thread or sequenced task runner that allows file I/O. The same | |
| 24 // thread or task runner must be used for all method calls. | |
| 25 class CONTENT_EXPORT NotificationDatabase { | |
| 26 public: | |
| 27 // Result status codes for interations with the database. Will be used for | |
| 28 // UMA, so the assigned ids must remain stable. | |
| 29 enum Status { | |
| 30 STATUS_OK = 0, | |
| 31 | |
| 32 // The key associated with the operation could not be found. | |
|
Bernhard Bauer
2015/03/11 18:20:01
This error code is also used if the file is not fo
Peter Beverloo
2015/03/11 19:32:25
Done.
| |
| 33 STATUS_ERROR_NOT_FOUND = 1, | |
| 34 | |
| 35 // General failure code. More specific failures should be used if available. | |
| 36 STATUS_ERROR_FAILED = 2, | |
|
cmumford
2015/03/11 18:24:33
I would suggest adding STATUS_CORRUPTED as well. l
Peter Beverloo
2015/03/11 19:32:25
Done.
| |
| 37 }; | |
| 38 | |
| 39 explicit NotificationDatabase(const base::FilePath& path); | |
| 40 ~NotificationDatabase(); | |
| 41 | |
| 42 // Opens the database. If |path| is non-empty, it will be created on the given | |
| 43 // directory on the filesystem. If |path| is empty, the database will be | |
| 44 // created in memory instead, and its lifetime will be tied to this instance. | |
| 45 // |create_if_missing| determines whether to create the database if necessary. | |
| 46 Status Open(bool create_if_missing); | |
| 47 | |
| 48 // Completely destroys the contents of this database. | |
| 49 Status Destroy(); | |
| 50 | |
| 51 private: | |
| 52 friend class NotificationDatabaseTest; | |
| 53 | |
| 54 // TODO(peter): Convert to an enum class when DCHECK_EQ supports this. | |
| 55 // See https://crbug.com/463869. | |
| 56 enum State { | |
| 57 STATE_UNINITIALIZED, | |
| 58 STATE_INITIALIZED, | |
| 59 STATE_DISABLED, | |
| 60 }; | |
| 61 | |
| 62 // Returns whether the database has been opened. | |
| 63 bool IsOpen() const { return db_ != nullptr; } | |
| 64 | |
| 65 // Returns whether the database should only exist in memory. | |
| 66 bool IsInMemoryDatabase() const { return path_.empty(); } | |
| 67 | |
| 68 base::FilePath path_; | |
| 69 scoped_ptr<leveldb::Env> env_; | |
| 70 scoped_ptr<leveldb::DB> db_; | |
| 71 | |
| 72 State state_; | |
| 73 | |
| 74 base::SequenceChecker sequence_checker_; | |
| 75 | |
| 76 DISALLOW_COPY_AND_ASSIGN(NotificationDatabase); | |
| 77 }; | |
| 78 | |
| 79 } // namespace content | |
| 80 | |
| 81 #endif // CONTENT_BROWSER_NOTIFICATIONS_NOTIFICATION_DATABASE_H_ | |
| OLD | NEW |