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

Side by Side 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 unified diff | Download patch
OLDNEW
(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 database, or the key associated with the operation, could not be
33 // found.
34 STATUS_ERROR_NOT_FOUND = 1,
35
36 // The database, or data in the database, could not be parsed as valid data.
37 STATUS_ERROR_CORRUPTED = 2,
38
39 // General failure code. More specific failures should be used if available.
40 STATUS_ERROR_FAILED = 3,
41 };
42
43 explicit NotificationDatabase(const base::FilePath& path);
44 ~NotificationDatabase();
45
46 // Opens the database. If |path| is non-empty, it will be created on the given
47 // directory on the filesystem. If |path| is empty, the database will be
48 // created in memory instead, and its lifetime will be tied to this instance.
49 // |create_if_missing| determines whether to create the database if necessary.
50 Status Open(bool create_if_missing);
51
52 // Completely destroys the contents of this database.
53 Status Destroy();
54
55 private:
56 friend class NotificationDatabaseTest;
57
58 // TODO(peter): Convert to an enum class when DCHECK_EQ supports this.
59 // See https://crbug.com/463869.
60 enum State {
61 STATE_UNINITIALIZED,
62 STATE_INITIALIZED,
63 STATE_DISABLED,
64 };
65
66 // Returns whether the database has been opened.
67 bool IsOpen() const { return db_ != nullptr; }
68
69 // Returns whether the database should only exist in memory.
70 bool IsInMemoryDatabase() const { return path_.empty(); }
71
72 base::FilePath path_;
73
74 // The declaration order for these members matters, as |db_| depends on |env_|
75 // and thus has to be destructed first.
76 scoped_ptr<leveldb::Env> env_;
77 scoped_ptr<leveldb::DB> db_;
78
79 State state_;
80
81 base::SequenceChecker sequence_checker_;
82
83 DISALLOW_COPY_AND_ASSIGN(NotificationDatabase);
84 };
85
86 } // namespace content
87
88 #endif // CONTENT_BROWSER_NOTIFICATIONS_NOTIFICATION_DATABASE_H_
OLDNEW
« 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