| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/extensions/api/notifications/notifications_api.h" | 5 #include "chrome/browser/extensions/api/notifications/notifications_api.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 714 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 725 params_ = api::notifications::Update::Params::Create(*args_); | 725 params_ = api::notifications::Update::Params::Create(*args_); |
| 726 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 726 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
| 727 | 727 |
| 728 // We are in update. If the ID doesn't exist, succeed but call the callback | 728 // We are in update. If the ID doesn't exist, succeed but call the callback |
| 729 // with "false". | 729 // with "false". |
| 730 const Notification* matched_notification = | 730 const Notification* matched_notification = |
| 731 g_browser_process->notification_ui_manager()->FindById( | 731 g_browser_process->notification_ui_manager()->FindById( |
| 732 CreateScopedIdentifier(extension_->id(), params_->notification_id), | 732 CreateScopedIdentifier(extension_->id(), params_->notification_id), |
| 733 NotificationUIManager::GetProfileID(GetProfile())); | 733 NotificationUIManager::GetProfileID(GetProfile())); |
| 734 if (!matched_notification) { | 734 if (!matched_notification) { |
| 735 SetResult(base::MakeUnique<base::FundamentalValue>(false)); | 735 SetResult(base::MakeUnique<base::Value>(false)); |
| 736 SendResponse(true); | 736 SendResponse(true); |
| 737 return true; | 737 return true; |
| 738 } | 738 } |
| 739 | 739 |
| 740 // Copy the existing notification to get a writable version of it. | 740 // Copy the existing notification to get a writable version of it. |
| 741 Notification notification = *matched_notification; | 741 Notification notification = *matched_notification; |
| 742 | 742 |
| 743 // If we have trouble updating the notification (could be improper use of API | 743 // If we have trouble updating the notification (could be improper use of API |
| 744 // or some other reason), mark the function as failed, calling the callback | 744 // or some other reason), mark the function as failed, calling the callback |
| 745 // with false. | 745 // with false. |
| 746 // TODO(dewittj): Add more human-readable error strings if this fails. | 746 // TODO(dewittj): Add more human-readable error strings if this fails. |
| 747 bool could_update_notification = UpdateNotification( | 747 bool could_update_notification = UpdateNotification( |
| 748 params_->notification_id, ¶ms_->options, ¬ification); | 748 params_->notification_id, ¶ms_->options, ¬ification); |
| 749 SetResult( | 749 SetResult(base::MakeUnique<base::Value>(could_update_notification)); |
| 750 base::MakeUnique<base::FundamentalValue>(could_update_notification)); | |
| 751 if (!could_update_notification) | 750 if (!could_update_notification) |
| 752 return false; | 751 return false; |
| 753 | 752 |
| 754 // No trouble, created the notification, send true to the callback and | 753 // No trouble, created the notification, send true to the callback and |
| 755 // succeed. | 754 // succeed. |
| 756 SendResponse(true); | 755 SendResponse(true); |
| 757 return true; | 756 return true; |
| 758 } | 757 } |
| 759 | 758 |
| 760 NotificationsClearFunction::NotificationsClearFunction() { | 759 NotificationsClearFunction::NotificationsClearFunction() { |
| 761 } | 760 } |
| 762 | 761 |
| 763 NotificationsClearFunction::~NotificationsClearFunction() { | 762 NotificationsClearFunction::~NotificationsClearFunction() { |
| 764 } | 763 } |
| 765 | 764 |
| 766 bool NotificationsClearFunction::RunNotificationsApi() { | 765 bool NotificationsClearFunction::RunNotificationsApi() { |
| 767 params_ = api::notifications::Clear::Params::Create(*args_); | 766 params_ = api::notifications::Clear::Params::Create(*args_); |
| 768 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 767 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
| 769 | 768 |
| 770 bool cancel_result = g_browser_process->notification_ui_manager()->CancelById( | 769 bool cancel_result = g_browser_process->notification_ui_manager()->CancelById( |
| 771 CreateScopedIdentifier(extension_->id(), params_->notification_id), | 770 CreateScopedIdentifier(extension_->id(), params_->notification_id), |
| 772 NotificationUIManager::GetProfileID(GetProfile())); | 771 NotificationUIManager::GetProfileID(GetProfile())); |
| 773 | 772 |
| 774 SetResult(base::MakeUnique<base::FundamentalValue>(cancel_result)); | 773 SetResult(base::MakeUnique<base::Value>(cancel_result)); |
| 775 SendResponse(true); | 774 SendResponse(true); |
| 776 | 775 |
| 777 return true; | 776 return true; |
| 778 } | 777 } |
| 779 | 778 |
| 780 NotificationsGetAllFunction::NotificationsGetAllFunction() {} | 779 NotificationsGetAllFunction::NotificationsGetAllFunction() {} |
| 781 | 780 |
| 782 NotificationsGetAllFunction::~NotificationsGetAllFunction() {} | 781 NotificationsGetAllFunction::~NotificationsGetAllFunction() {} |
| 783 | 782 |
| 784 bool NotificationsGetAllFunction::RunNotificationsApi() { | 783 bool NotificationsGetAllFunction::RunNotificationsApi() { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 819 : api::notifications::PERMISSION_LEVEL_DENIED; | 818 : api::notifications::PERMISSION_LEVEL_DENIED; |
| 820 | 819 |
| 821 SetResult(base::MakeUnique<base::StringValue>( | 820 SetResult(base::MakeUnique<base::StringValue>( |
| 822 api::notifications::ToString(result))); | 821 api::notifications::ToString(result))); |
| 823 SendResponse(true); | 822 SendResponse(true); |
| 824 | 823 |
| 825 return true; | 824 return true; |
| 826 } | 825 } |
| 827 | 826 |
| 828 } // namespace extensions | 827 } // namespace extensions |
| OLD | NEW |