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

Side by Side Diff: content/browser/notifications/platform_notification_context.h

Issue 1008003003: Teach the PlatformNotificationContext how to delete notifications. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@n-db-PlatformNotificationContext
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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 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 #ifndef CONTENT_BROWSER_NOTIFICATIONS_PLATFORM_NOTIFICATION_CONTEXT_H_ 5 #ifndef CONTENT_BROWSER_NOTIFICATIONS_PLATFORM_NOTIFICATION_CONTEXT_H_
6 #define CONTENT_BROWSER_NOTIFICATIONS_PLATFORM_NOTIFICATION_CONTEXT_H_ 6 #define CONTENT_BROWSER_NOTIFICATIONS_PLATFORM_NOTIFICATION_CONTEXT_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 25 matching lines...) Expand all
36 explicit PlatformNotificationContext(const base::FilePath& path); 36 explicit PlatformNotificationContext(const base::FilePath& path);
37 37
38 using ReadResultCallback = 38 using ReadResultCallback =
39 base::Callback<void(bool /* success */, 39 base::Callback<void(bool /* success */,
40 const NotificationDatabaseData&)>; 40 const NotificationDatabaseData&)>;
41 41
42 using WriteResultCallback = 42 using WriteResultCallback =
43 base::Callback<void(bool /* success */, 43 base::Callback<void(bool /* success */,
44 int64_t /* notification_id */)>; 44 int64_t /* notification_id */)>;
45 45
46 using DeleteResultCallback = base::Callback<void(bool /* success */)>;
47
46 // Reads the data associated with |notification_id| belonging to |origin| 48 // Reads the data associated with |notification_id| belonging to |origin|
47 // from the database. |callback| will be invoked with the success status 49 // from the database. |callback| will be invoked with the success status
48 // and a reference to the notification database data when completed. 50 // and a reference to the notification database data when completed.
49 void ReadNotificationData(int64_t notification_id, 51 void ReadNotificationData(int64_t notification_id,
50 const GURL& origin, 52 const GURL& origin,
51 const ReadResultCallback& callback); 53 const ReadResultCallback& callback);
52 54
53 // Writes the data associated with a notification to a database. When this 55 // Writes the data associated with a notification to a database. When this
54 // action completed, |callback| will be invoked with the success status and 56 // action completed, |callback| will be invoked with the success status and
55 // the persistent notification id when written successfully. 57 // the persistent notification id when written successfully.
56 void WriteNotificationData(const GURL& origin, 58 void WriteNotificationData(const GURL& origin,
57 const NotificationDatabaseData& database_data, 59 const NotificationDatabaseData& database_data,
58 const WriteResultCallback& callback); 60 const WriteResultCallback& callback);
59 61
62 // Deletes all data associated with |notification_id| belonging to |origin|
63 // from the database. |callback| will be invoked with the success status
64 // when the operation has completed.
65 void DeleteNotificationData(int64_t notification_id,
66 const GURL& origin,
67 const DeleteResultCallback& callback);
68
60 private: 69 private:
61 friend class base::RefCountedThreadSafe<PlatformNotificationContext>; 70 friend class base::RefCountedThreadSafe<PlatformNotificationContext>;
62 friend class PlatformNotificationContextTest; 71 friend class PlatformNotificationContextTest;
63 72
64 virtual ~PlatformNotificationContext(); 73 virtual ~PlatformNotificationContext();
65 74
66 // Initializes the database if neccesary. Must be called on the IO thread. 75 // Initializes the database if neccesary. Must be called on the IO thread.
67 // |success_closure| will be invoked on a the |task_runner_| thread when 76 // |success_closure| will be invoked on a the |task_runner_| thread when
68 // everything is available, or |failure_closure_| will be invoked on the 77 // everything is available, or |failure_closure_| will be invoked on the
69 // IO thread when initialization fails. 78 // IO thread when initialization fails.
70 void LazyInitialize(const base::Closure& success_closure, 79 void LazyInitialize(const base::Closure& success_closure,
71 const base::Closure& failure_closure); 80 const base::Closure& failure_closure);
72 81
73 // Opens the database. Must be called on the |task_runner_| thread. When the 82 // Opens the database. Must be called on the |task_runner_| thread. When the
74 // database has been opened, |success_closure| will be invoked on the task 83 // database has been opened, |success_closure| will be invoked on the task
75 // thread, otherwise |failure_closure_ will be invoked on the IO thread. 84 // thread, otherwise |failure_closure_ will be invoked on the IO thread.
76 void OpenDatabase(const base::Closure& success_closure, 85 void OpenDatabase(const base::Closure& success_closure,
77 const base::Closure& failure_closure); 86 const base::Closure& failure_closure);
78 87
79 // Actually reads the notification data from the database. Must only be 88 // Actually reads the notification data from the database. Must only be
80 // called on the |task_runner_| thread. Will post a task to |callback| on 89 // called on the |task_runner_| thread. Will post a task to the IO thread
81 // the IO thread when the operation has completed. 90 // for invoking |callback| on when the operation has completed.
johnme 2015/03/16 16:55:18 Nit: While you're re-wording this, why not just "W
Peter Beverloo 2015/03/16 18:16:51 Because it won't invoke, it'll post a task to invo
johnme 2015/03/16 19:34:46 Fair. Maybe say "|callback| will be invoked on the
82 void DoReadNotificationData(int64_t notification_id, 91 void DoReadNotificationData(int64_t notification_id,
83 const GURL& origin, 92 const GURL& origin,
84 const ReadResultCallback& callback); 93 const ReadResultCallback& callback);
85 94
86 // Actually writes the notification database to the database. Must only be 95 // Actually writes the notification database to the database. Must only be
87 // called on the |task_runner_| thread. Will post a task to |callback| on 96 // called on the |task_runner_| thread. Will post a task to the IO thread
88 // the IO thread when the operation has completed. 97 // for invoking |callback| on when the operation has completed.
89 void DoWriteNotificationData(const GURL& origin, 98 void DoWriteNotificationData(const GURL& origin,
90 const NotificationDatabaseData& database_data, 99 const NotificationDatabaseData& database_data,
91 const WriteResultCallback& callback); 100 const WriteResultCallback& callback);
92 101
102 // Actually deletes the notification information from the database. Must only
103 // be called on the |task_runner_| thread. Will post a task to the IO thread
104 // for invoking |callback| on when the operation has completed.
105 void DoDeleteNotificationData(int64_t notification_id,
106 const GURL& origin,
107 const DeleteResultCallback& callback);
108
93 // Returns the path in which the database should be initialized. May be empty. 109 // Returns the path in which the database should be initialized. May be empty.
94 base::FilePath GetDatabasePath() const; 110 base::FilePath GetDatabasePath() const;
95 111
96 // Sets the task runner to use for testing purposes. 112 // Sets the task runner to use for testing purposes.
97 void SetTaskRunnerForTesting( 113 void SetTaskRunnerForTesting(
98 const scoped_refptr<base::SequencedTaskRunner>& task_runner); 114 const scoped_refptr<base::SequencedTaskRunner>& task_runner);
99 115
100 base::FilePath path_; 116 base::FilePath path_;
101 117
102 scoped_refptr<base::SequencedTaskRunner> task_runner_; 118 scoped_refptr<base::SequencedTaskRunner> task_runner_;
103 scoped_ptr<NotificationDatabase> database_; 119 scoped_ptr<NotificationDatabase> database_;
104 120
105 DISALLOW_COPY_AND_ASSIGN(PlatformNotificationContext); 121 DISALLOW_COPY_AND_ASSIGN(PlatformNotificationContext);
106 }; 122 };
107 123
108 } // namespace content 124 } // namespace content
109 125
110 #endif // CONTENT_BROWSER_NOTIFICATIONS_PLATFORM_NOTIFICATION_CONTEXT_H_ 126 #endif // CONTENT_BROWSER_NOTIFICATIONS_PLATFORM_NOTIFICATION_CONTEXT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698