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

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

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 #include "content/browser/notifications/platform_notification_context.h" 5 #include "content/browser/notifications/platform_notification_context.h"
6 6
7 #include "base/threading/sequenced_worker_pool.h" 7 #include "base/threading/sequenced_worker_pool.h"
8 #include "content/browser/notifications/notification_database.h" 8 #include "content/browser/notifications/notification_database.h"
9 #include "content/browser/notifications/notification_database_data.h" 9 #include "content/browser/notifications/notification_database_data.h"
10 #include "content/public/browser/browser_thread.h" 10 #include "content/public/browser/browser_thread.h"
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 107
108 // TODO(peter): Record UMA on |status| for reading from the database. 108 // TODO(peter): Record UMA on |status| for reading from the database.
109 // TODO(peter): Do the DeleteAndStartOver dance for STATUS_ERROR_CORRUPTED. 109 // TODO(peter): Do the DeleteAndStartOver dance for STATUS_ERROR_CORRUPTED.
110 110
111 BrowserThread::PostTask( 111 BrowserThread::PostTask(
112 BrowserThread::IO, 112 BrowserThread::IO,
113 FROM_HERE, 113 FROM_HERE,
114 base::Bind(callback, false /* success */, 0 /* notification_id */)); 114 base::Bind(callback, false /* success */, 0 /* notification_id */));
115 } 115 }
116 116
117 void PlatformNotificationContext::DeleteNotificationData(
118 int64_t notification_id,
119 const GURL& origin,
120 const DeleteResultCallback& callback) {
121 DCHECK_CURRENTLY_ON(BrowserThread::IO);
122 LazyInitialize(
123 base::Bind(&PlatformNotificationContext::DoDeleteNotificationData,
124 this, notification_id, origin, callback),
125 base::Bind(callback, false /* success */));
126 }
127
128 void PlatformNotificationContext::DoDeleteNotificationData(
129 int64_t notification_id,
130 const GURL& origin,
131 const DeleteResultCallback& callback) {
132 DCHECK(task_runner_->RunsTasksOnCurrentThread());
133
134 NotificationDatabase::Status status =
135 database_->DeleteNotificationData(notification_id, origin);
136
137 const bool success = status == NotificationDatabase::STATUS_OK;
138
139 // TODO(peter): Record UMA on |status| for reading from the database.
140 // TODO(peter): Do the DeleteAndStartOver dance for STATUS_ERROR_CORRUPTED.
141
142 BrowserThread::PostTask(BrowserThread::IO,
143 FROM_HERE,
144 base::Bind(callback, success));
145 }
146
117 void PlatformNotificationContext::LazyInitialize( 147 void PlatformNotificationContext::LazyInitialize(
118 const base::Closure& success_closure, 148 const base::Closure& success_closure,
119 const base::Closure& failure_closure) { 149 const base::Closure& failure_closure) {
120 DCHECK_CURRENTLY_ON(BrowserThread::IO); 150 DCHECK_CURRENTLY_ON(BrowserThread::IO);
121 151
122 if (!task_runner_) { 152 if (!task_runner_) {
123 base::SequencedWorkerPool* pool = BrowserThread::GetBlockingPool(); 153 base::SequencedWorkerPool* pool = BrowserThread::GetBlockingPool();
124 base::SequencedWorkerPool::SequenceToken token = pool->GetSequenceToken(); 154 base::SequencedWorkerPool::SequenceToken token = pool->GetSequenceToken();
125 155
126 task_runner_ = pool->GetSequencedTaskRunner(token); 156 task_runner_ = pool->GetSequencedTaskRunner(token);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 197
168 return path_.Append(kPlatformNotificationsDirectory); 198 return path_.Append(kPlatformNotificationsDirectory);
169 } 199 }
170 200
171 void PlatformNotificationContext::SetTaskRunnerForTesting( 201 void PlatformNotificationContext::SetTaskRunnerForTesting(
172 const scoped_refptr<base::SequencedTaskRunner>& task_runner) { 202 const scoped_refptr<base::SequencedTaskRunner>& task_runner) {
173 task_runner_ = task_runner; 203 task_runner_ = task_runner;
174 } 204 }
175 205
176 } // namespace content 206 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698