| 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/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 this, origin, database_data, callback), | 232 this, origin, database_data, callback), |
| 233 base::Bind(callback, false /* success */, 0 /* notification_id */)); | 233 base::Bind(callback, false /* success */, 0 /* notification_id */)); |
| 234 } | 234 } |
| 235 | 235 |
| 236 void PlatformNotificationContextImpl::DoWriteNotificationData( | 236 void PlatformNotificationContextImpl::DoWriteNotificationData( |
| 237 const GURL& origin, | 237 const GURL& origin, |
| 238 const NotificationDatabaseData& database_data, | 238 const NotificationDatabaseData& database_data, |
| 239 const WriteResultCallback& callback) { | 239 const WriteResultCallback& callback) { |
| 240 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 240 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 241 | 241 |
| 242 // Eagerly delete data for replaced notifications from the database. |
| 243 if (!database_data.notification_data.tag.empty()) { |
| 244 std::set<int64_t> deleted_notification_set; |
| 245 NotificationDatabase::Status delete_status = |
| 246 database_->DeleteAllNotificationDataForOrigin( |
| 247 origin, database_data.notification_data.tag, |
| 248 &deleted_notification_set); |
| 249 |
| 250 UMA_HISTOGRAM_ENUMERATION("Notifications.Database.DeleteBeforeWriteResult", |
| 251 delete_status, |
| 252 NotificationDatabase::STATUS_COUNT); |
| 253 |
| 254 // Unless the database was corrupted following this change, there is no |
| 255 // reason to bail out here in event of failure because the notification |
| 256 // display logic will handle notification replacement for the user. |
| 257 if (delete_status == NotificationDatabase::STATUS_ERROR_CORRUPTED) { |
| 258 DestroyDatabase(); |
| 259 |
| 260 BrowserThread::PostTask( |
| 261 BrowserThread::IO, FROM_HERE, |
| 262 base::Bind(callback, false /* success */, 0 /* notification_id */)); |
| 263 return; |
| 264 } |
| 265 } |
| 266 |
| 242 int64_t notification_id = 0; | 267 int64_t notification_id = 0; |
| 243 NotificationDatabase::Status status = | 268 NotificationDatabase::Status status = |
| 244 database_->WriteNotificationData(origin, database_data, ¬ification_id); | 269 database_->WriteNotificationData(origin, database_data, ¬ification_id); |
| 245 | 270 |
| 246 UMA_HISTOGRAM_ENUMERATION("Notifications.Database.WriteResult", status, | 271 UMA_HISTOGRAM_ENUMERATION("Notifications.Database.WriteResult", status, |
| 247 NotificationDatabase::STATUS_COUNT); | 272 NotificationDatabase::STATUS_COUNT); |
| 248 | 273 |
| 249 if (status == NotificationDatabase::STATUS_OK) { | 274 if (status == NotificationDatabase::STATUS_OK) { |
| 250 DCHECK_GT(notification_id, 0); | 275 DCHECK_GT(notification_id, 0); |
| 251 BrowserThread::PostTask( | 276 BrowserThread::PostTask( |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 439 | 464 |
| 440 return path_.Append(kPlatformNotificationsDirectory); | 465 return path_.Append(kPlatformNotificationsDirectory); |
| 441 } | 466 } |
| 442 | 467 |
| 443 void PlatformNotificationContextImpl::SetTaskRunnerForTesting( | 468 void PlatformNotificationContextImpl::SetTaskRunnerForTesting( |
| 444 const scoped_refptr<base::SequencedTaskRunner>& task_runner) { | 469 const scoped_refptr<base::SequencedTaskRunner>& task_runner) { |
| 445 task_runner_ = task_runner; | 470 task_runner_ = task_runner; |
| 446 } | 471 } |
| 447 | 472 |
| 448 } // namespace content | 473 } // namespace content |
| OLD | NEW |