OLD | NEW |
---|---|
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 Loading... | |
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; | |
johnme
2015/03/16 16:55:18
It doesn't seem ideal to treat STATUS_ERROR_NOT_FO
johnme
2015/03/16 16:55:18
It doesn't seem ideal to treat STATUS_ERROR_NOT_FO
Peter Beverloo
2015/03/16 18:16:51
This is not the case anymore per new semantics in
| |
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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
164 | 194 |
165 return path_.Append(kPlatformNotificationsDirectory); | 195 return path_.Append(kPlatformNotificationsDirectory); |
166 } | 196 } |
167 | 197 |
168 void PlatformNotificationContext::SetTaskRunnerForTesting( | 198 void PlatformNotificationContext::SetTaskRunnerForTesting( |
169 const scoped_refptr<base::SequencedTaskRunner>& task_runner) { | 199 const scoped_refptr<base::SequencedTaskRunner>& task_runner) { |
170 task_runner_ = task_runner; | 200 task_runner_ = task_runner; |
171 } | 201 } |
172 | 202 |
173 } // namespace content | 203 } // namespace content |
OLD | NEW |