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/metrics/histogram_macros.h" | 9 #include "base/metrics/histogram_macros.h" |
10 #include "base/threading/sequenced_worker_pool.h" | 10 #include "base/threading/sequenced_worker_pool.h" |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 // Blow away the database if reading data failed due to corruption. | 111 // Blow away the database if reading data failed due to corruption. |
112 if (status == NotificationDatabase::STATUS_ERROR_CORRUPTED) | 112 if (status == NotificationDatabase::STATUS_ERROR_CORRUPTED) |
113 DestroyDatabase(); | 113 DestroyDatabase(); |
114 | 114 |
115 BrowserThread::PostTask( | 115 BrowserThread::PostTask( |
116 BrowserThread::IO, | 116 BrowserThread::IO, |
117 FROM_HERE, | 117 FROM_HERE, |
118 base::Bind(callback, false /* success */, NotificationDatabaseData())); | 118 base::Bind(callback, false /* success */, NotificationDatabaseData())); |
119 } | 119 } |
120 | 120 |
| 121 void PlatformNotificationContextImpl:: |
| 122 ReadAllNotificationDataForServiceWorkerRegistration( |
| 123 const GURL& origin, |
| 124 int64_t service_worker_registration_id, |
| 125 const ReadAllResultCallback& callback) { |
| 126 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 127 LazyInitialize( |
| 128 base::Bind(&PlatformNotificationContextImpl:: |
| 129 DoReadAllNotificationDataForServiceWorkerRegistration, |
| 130 this, origin, service_worker_registration_id, callback), |
| 131 base::Bind(callback, |
| 132 false /* success */, |
| 133 std::vector<NotificationDatabaseData>())); |
| 134 } |
| 135 |
| 136 void PlatformNotificationContextImpl:: |
| 137 DoReadAllNotificationDataForServiceWorkerRegistration( |
| 138 const GURL& origin, |
| 139 int64_t service_worker_registration_id, |
| 140 const ReadAllResultCallback& callback) { |
| 141 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 142 |
| 143 std::vector<NotificationDatabaseData> notification_datas; |
| 144 |
| 145 NotificationDatabase::Status status = |
| 146 database_->ReadAllNotificationDataForServiceWorkerRegistration( |
| 147 origin, service_worker_registration_id, ¬ification_datas); |
| 148 |
| 149 UMA_HISTOGRAM_ENUMERATION("Notifications.Database.ReadForServiceWorkerResult", |
| 150 status, NotificationDatabase::STATUS_COUNT); |
| 151 |
| 152 if (status == NotificationDatabase::STATUS_OK) { |
| 153 BrowserThread::PostTask(BrowserThread::IO, |
| 154 FROM_HERE, |
| 155 base::Bind(callback, |
| 156 true /* success */, |
| 157 notification_datas)); |
| 158 return; |
| 159 } |
| 160 |
| 161 // Blow away the database if reading data failed due to corruption. |
| 162 if (status == NotificationDatabase::STATUS_ERROR_CORRUPTED) |
| 163 DestroyDatabase(); |
| 164 |
| 165 BrowserThread::PostTask( |
| 166 BrowserThread::IO, |
| 167 FROM_HERE, |
| 168 base::Bind(callback, |
| 169 false /* success */, |
| 170 std::vector<NotificationDatabaseData>())); |
| 171 } |
| 172 |
121 void PlatformNotificationContextImpl::WriteNotificationData( | 173 void PlatformNotificationContextImpl::WriteNotificationData( |
122 const GURL& origin, | 174 const GURL& origin, |
123 const NotificationDatabaseData& database_data, | 175 const NotificationDatabaseData& database_data, |
124 const WriteResultCallback& callback) { | 176 const WriteResultCallback& callback) { |
125 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 177 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
126 LazyInitialize( | 178 LazyInitialize( |
127 base::Bind(&PlatformNotificationContextImpl::DoWriteNotificationData, | 179 base::Bind(&PlatformNotificationContextImpl::DoWriteNotificationData, |
128 this, origin, database_data, callback), | 180 this, origin, database_data, callback), |
129 base::Bind(callback, false /* success */, 0 /* notification_id */)); | 181 base::Bind(callback, false /* success */, 0 /* notification_id */)); |
130 } | 182 } |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 | 329 |
278 UMA_HISTOGRAM_ENUMERATION("Notifications.Database.OpenResult", | 330 UMA_HISTOGRAM_ENUMERATION("Notifications.Database.OpenResult", |
279 status, NotificationDatabase::STATUS_COUNT); | 331 status, NotificationDatabase::STATUS_COUNT); |
280 | 332 |
281 // When the database could not be opened due to corruption, destroy it, blow | 333 // When the database could not be opened due to corruption, destroy it, blow |
282 // away the contents of the directory and try re-opening the database. | 334 // away the contents of the directory and try re-opening the database. |
283 if (status == NotificationDatabase::STATUS_ERROR_CORRUPTED) { | 335 if (status == NotificationDatabase::STATUS_ERROR_CORRUPTED) { |
284 if (DestroyDatabase()) { | 336 if (DestroyDatabase()) { |
285 status = database_->Open(true /* create_if_missing */); | 337 status = database_->Open(true /* create_if_missing */); |
286 | 338 |
287 // TODO(peter): Record UMA on |status| for re-opening the database after | 339 UMA_HISTOGRAM_ENUMERATION( |
288 // corruption was detected. | 340 "Notifications.Database.OpenAfterCorruptionResult", |
| 341 status, NotificationDatabase::STATUS_COUNT); |
289 } | 342 } |
290 } | 343 } |
291 | 344 |
292 if (status == NotificationDatabase::STATUS_OK) { | 345 if (status == NotificationDatabase::STATUS_OK) { |
293 success_closure.Run(); | 346 success_closure.Run(); |
294 return; | 347 return; |
295 } | 348 } |
296 | 349 |
297 database_.reset(); | 350 database_.reset(); |
298 | 351 |
(...skipping 27 matching lines...) Expand all Loading... |
326 | 379 |
327 return path_.Append(kPlatformNotificationsDirectory); | 380 return path_.Append(kPlatformNotificationsDirectory); |
328 } | 381 } |
329 | 382 |
330 void PlatformNotificationContextImpl::SetTaskRunnerForTesting( | 383 void PlatformNotificationContextImpl::SetTaskRunnerForTesting( |
331 const scoped_refptr<base::SequencedTaskRunner>& task_runner) { | 384 const scoped_refptr<base::SequencedTaskRunner>& task_runner) { |
332 task_runner_ = task_runner; | 385 task_runner_ = task_runner; |
333 } | 386 } |
334 | 387 |
335 } // namespace content | 388 } // namespace content |
OLD | NEW |