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

Unified Diff: content/browser/notifications/notification_database.h

Issue 988163003: Introduce the NotificationDatabase class. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/browser/notifications/DEPS ('k') | content/browser/notifications/notification_database.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..8fb9ce01bf736405d83828a5046f27a0ed5ca3a3
--- /dev/null
+++ b/content/browser/notifications/notification_database.h
@@ -0,0 +1,87 @@
+// 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 database, or the key associated with the operation, could not be
+ // found.
+ STATUS_ERROR_NOT_FOUND = 1,
+
+ // The database, or data in the database, could not be parsed as valid data.
+ STATUS_ERROR_CORRUPTED = 2,
+
+ // General failure code. More specific failures should be used if available.
+ STATUS_ERROR_FAILED = 3,
+ };
+
+ 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_;
+
+ // These members depend on the declaration order for destruction.
Bernhard Bauer 2015/03/11 21:35:11 I would actually be explicit about it: |db_| depen
Peter Beverloo 2015/03/11 22:11:53 Done.
+ 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_
« no previous file with comments | « content/browser/notifications/DEPS ('k') | content/browser/notifications/notification_database.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698