Chromium Code Reviews| 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_impl.h" | 5 #include "content/browser/notifications/platform_notification_context_impl.h" |
| 6 | 6 |
| 7 #include "base/bind_helpers.h" | 7 #include "base/bind_helpers.h" |
| 8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
| 9 #include "base/threading/sequenced_worker_pool.h" | 9 #include "base/threading/sequenced_worker_pool.h" |
| 10 #include "content/browser/notifications/notification_database.h" | 10 #include "content/browser/notifications/notification_database.h" |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 109 // Blow away the database if reading data failed due to corruption. | 109 // Blow away the database if reading data failed due to corruption. |
| 110 if (status == NotificationDatabase::STATUS_ERROR_CORRUPTED) | 110 if (status == NotificationDatabase::STATUS_ERROR_CORRUPTED) |
| 111 DestroyDatabase(); | 111 DestroyDatabase(); |
| 112 | 112 |
| 113 BrowserThread::PostTask( | 113 BrowserThread::PostTask( |
| 114 BrowserThread::IO, | 114 BrowserThread::IO, |
| 115 FROM_HERE, | 115 FROM_HERE, |
| 116 base::Bind(callback, false /* success */, NotificationDatabaseData())); | 116 base::Bind(callback, false /* success */, NotificationDatabaseData())); |
| 117 } | 117 } |
| 118 | 118 |
| 119 void PlatformNotificationContextImpl:: | |
| 120 ReadAllNotificationDataForServiceWorkerRegistration( | |
| 121 const GURL& origin, | |
| 122 int64_t service_worker_registration_id, | |
| 123 const ReadAllResultCallback& callback) { | |
| 124 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 125 LazyInitialize( | |
| 126 base::Bind(&PlatformNotificationContextImpl:: | |
| 127 DoReadAllNotificationDataForServiceWorkerRegistration, | |
| 128 this, origin, service_worker_registration_id, callback), | |
| 129 base::Bind(callback, | |
| 130 false /* success */, | |
| 131 std::vector<NotificationDatabaseData>())); | |
| 132 } | |
| 133 | |
| 134 void PlatformNotificationContextImpl:: | |
| 135 DoReadAllNotificationDataForServiceWorkerRegistration( | |
| 136 const GURL& origin, | |
| 137 int64_t service_worker_registration_id, | |
| 138 const ReadAllResultCallback& callback) { | |
| 139 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | |
| 140 | |
| 141 std::vector<NotificationDatabaseData> notification_datas; | |
| 142 | |
| 143 NotificationDatabase::Status status = | |
| 144 database_->ReadAllNotificationDataForServiceWorkerRegistration( | |
| 145 origin, service_worker_registration_id, ¬ification_datas); | |
| 146 | |
| 147 // TODO(peter): Record UMA on |status| for reading from the database. | |
|
johnme
2015/04/08 18:12:41
Since you wrote this patch, the other methods now
Peter Beverloo
2015/04/14 18:01:27
Done.
| |
| 148 | |
| 149 if (status == NotificationDatabase::STATUS_OK) { | |
| 150 BrowserThread::PostTask(BrowserThread::IO, | |
| 151 FROM_HERE, | |
| 152 base::Bind(callback, | |
| 153 true /* success */, | |
| 154 notification_datas)); | |
| 155 return; | |
| 156 } | |
| 157 | |
| 158 // Blow away the database if reading data failed due to corruption. | |
| 159 if (status == NotificationDatabase::STATUS_ERROR_CORRUPTED) | |
| 160 DestroyDatabase(); | |
| 161 | |
| 162 BrowserThread::PostTask( | |
| 163 BrowserThread::IO, | |
| 164 FROM_HERE, | |
| 165 base::Bind(callback, | |
| 166 false /* success */, | |
| 167 std::vector<NotificationDatabaseData>())); | |
| 168 } | |
| 169 | |
| 119 void PlatformNotificationContextImpl::WriteNotificationData( | 170 void PlatformNotificationContextImpl::WriteNotificationData( |
| 120 const GURL& origin, | 171 const GURL& origin, |
| 121 const NotificationDatabaseData& database_data, | 172 const NotificationDatabaseData& database_data, |
| 122 const WriteResultCallback& callback) { | 173 const WriteResultCallback& callback) { |
| 123 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 174 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 124 LazyInitialize( | 175 LazyInitialize( |
| 125 base::Bind(&PlatformNotificationContextImpl::DoWriteNotificationData, | 176 base::Bind(&PlatformNotificationContextImpl::DoWriteNotificationData, |
| 126 this, origin, database_data, callback), | 177 this, origin, database_data, callback), |
| 127 base::Bind(callback, false /* success */, 0 /* notification_id */)); | 178 base::Bind(callback, false /* success */, 0 /* notification_id */)); |
| 128 } | 179 } |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 317 | 368 |
| 318 return path_.Append(kPlatformNotificationsDirectory); | 369 return path_.Append(kPlatformNotificationsDirectory); |
| 319 } | 370 } |
| 320 | 371 |
| 321 void PlatformNotificationContextImpl::SetTaskRunnerForTesting( | 372 void PlatformNotificationContextImpl::SetTaskRunnerForTesting( |
| 322 const scoped_refptr<base::SequencedTaskRunner>& task_runner) { | 373 const scoped_refptr<base::SequencedTaskRunner>& task_runner) { |
| 323 task_runner_ = task_runner; | 374 task_runner_ = task_runner; |
| 324 } | 375 } |
| 325 | 376 |
| 326 } // namespace content | 377 } // namespace content |
| OLD | NEW |