Chromium Code Reviews| Index: content/browser/notifications/notification_database.h |
| diff --git a/content/browser/notifications/notification_database.h b/content/browser/notifications/notification_database.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ea9497557294cbb3a63feb377b2428840087db31 |
| --- /dev/null |
| +++ b/content/browser/notifications/notification_database.h |
| @@ -0,0 +1,81 @@ |
| +// Copyright 2015 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. |
| + |
| +#ifndef CONTENT_BROWSER_NOTIFICATIONS_NOTIFICATION_DATABASE_H_ |
| +#define CONTENT_BROWSER_NOTIFICATIONS_NOTIFICATION_DATABASE_H_ |
| + |
| +#include "base/callback.h" |
| +#include "base/files/file_path.h" |
| +#include "base/sequence_checker.h" |
| +#include "content/common/content_export.h" |
| + |
| +namespace leveldb { |
| +class DB; |
| +class Env; |
| +} |
| + |
| +namespace content { |
| + |
| +// Implementation of the persistent notification database. |
| +// |
| +// This class can be constructed on any thread, but method calls must only be |
| +// made on a thread or sequenced task runner that allows file I/O. The same |
| +// thread or task runner must be used for all method calls. |
| +class CONTENT_EXPORT NotificationDatabase { |
| + public: |
| + // Result status codes for interations with the database. Will be used for |
| + // UMA, so the assigned ids must remain stable. |
| + enum Status { |
| + STATUS_OK = 0, |
| + |
| + // 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.
|
| + STATUS_ERROR_NOT_FOUND = 1, |
| + |
| + // General failure code. More specific failures should be used if available. |
| + 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.
|
| + }; |
| + |
| + explicit NotificationDatabase(const base::FilePath& path); |
| + ~NotificationDatabase(); |
| + |
| + // Opens the database. If |path| is non-empty, it will be created on the given |
| + // directory on the filesystem. If |path| is empty, the database will be |
| + // created in memory instead, and its lifetime will be tied to this instance. |
| + // |create_if_missing| determines whether to create the database if necessary. |
| + Status Open(bool create_if_missing); |
| + |
| + // Completely destroys the contents of this database. |
| + Status Destroy(); |
| + |
| + private: |
| + friend class NotificationDatabaseTest; |
| + |
| + // TODO(peter): Convert to an enum class when DCHECK_EQ supports this. |
| + // See https://crbug.com/463869. |
| + enum State { |
| + STATE_UNINITIALIZED, |
| + STATE_INITIALIZED, |
| + STATE_DISABLED, |
| + }; |
| + |
| + // Returns whether the database has been opened. |
| + bool IsOpen() const { return db_ != nullptr; } |
| + |
| + // Returns whether the database should only exist in memory. |
| + bool IsInMemoryDatabase() const { return path_.empty(); } |
| + |
| + base::FilePath path_; |
| + scoped_ptr<leveldb::Env> env_; |
| + scoped_ptr<leveldb::DB> db_; |
| + |
| + State state_; |
| + |
| + base::SequenceChecker sequence_checker_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(NotificationDatabase); |
| +}; |
| + |
| +} // namespace content |
| + |
| +#endif // CONTENT_BROWSER_NOTIFICATIONS_NOTIFICATION_DATABASE_H_ |