| 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/notifications/notification_object_proxy.h" | 5 #include "chrome/browser/notifications/notification_object_proxy.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/guid.h" | |
| 10 #include "base/logging.h" | 9 #include "base/logging.h" |
| 11 #include "chrome/browser/notifications/notification_common.h" | |
| 12 #include "chrome/browser/notifications/platform_notification_service_impl.h" | 10 #include "chrome/browser/notifications/platform_notification_service_impl.h" |
| 13 #include "content/public/browser/desktop_notification_delegate.h" | 11 #include "content/public/browser/desktop_notification_delegate.h" |
| 14 | 12 |
| 15 NotificationObjectProxy::NotificationObjectProxy( | 13 NotificationObjectProxy::NotificationObjectProxy( |
| 16 content::BrowserContext* browser_context, | 14 content::BrowserContext* browser_context, |
| 15 const std::string& notification_id, |
| 17 std::unique_ptr<content::DesktopNotificationDelegate> delegate) | 16 std::unique_ptr<content::DesktopNotificationDelegate> delegate) |
| 18 : browser_context_(browser_context), | 17 : browser_context_(browser_context), |
| 19 delegate_(std::move(delegate)), | 18 delegate_(std::move(delegate)), |
| 20 displayed_(false), | 19 displayed_(false), |
| 21 id_(base::GenerateGUID()) {} | 20 notification_id_(notification_id) {} |
| 22 | 21 |
| 23 NotificationObjectProxy::~NotificationObjectProxy() {} | 22 NotificationObjectProxy::~NotificationObjectProxy() {} |
| 24 | 23 |
| 25 void NotificationObjectProxy::Display() { | 24 void NotificationObjectProxy::Display() { |
| 26 // This method is called each time the notification is shown to the user | 25 // This method is called each time the notification is shown to the user |
| 27 // but we only want to fire the event the first time. | 26 // but we only want to fire the event the first time. |
| 28 if (displayed_) | 27 if (displayed_) |
| 29 return; | 28 return; |
| 29 |
| 30 displayed_ = true; | 30 displayed_ = true; |
| 31 | 31 |
| 32 delegate_->NotificationDisplayed(); | 32 delegate_->NotificationDisplayed(); |
| 33 } | 33 } |
| 34 | 34 |
| 35 void NotificationObjectProxy::Close(bool by_user) { | 35 void NotificationObjectProxy::Close(bool by_user) { |
| 36 delegate_->NotificationClosed(); | 36 delegate_->NotificationClosed(); |
| 37 } | 37 } |
| 38 | 38 |
| 39 void NotificationObjectProxy::Click() { | 39 void NotificationObjectProxy::Click() { |
| 40 delegate_->NotificationClick(); | 40 delegate_->NotificationClick(); |
| 41 } | 41 } |
| 42 | 42 |
| 43 void NotificationObjectProxy::ButtonClick(int button_index) { | 43 void NotificationObjectProxy::ButtonClick(int button_index) { |
| 44 // Notification buttons not are supported for non persistent notifications. | 44 // Notification buttons not are supported for non persistent notifications. |
| 45 DCHECK_EQ(button_index, 0); | 45 DCHECK_EQ(button_index, 0); |
| 46 |
| 46 NotificationCommon::OpenNotificationSettings(browser_context_); | 47 NotificationCommon::OpenNotificationSettings(browser_context_); |
| 47 } | 48 } |
| 48 | 49 |
| 49 void NotificationObjectProxy::SettingsClick() { | 50 void NotificationObjectProxy::SettingsClick() { |
| 50 NotificationCommon::OpenNotificationSettings(browser_context_); | 51 NotificationCommon::OpenNotificationSettings(browser_context_); |
| 51 return; | |
| 52 } | 52 } |
| 53 | 53 |
| 54 bool NotificationObjectProxy::ShouldDisplaySettingsButton() { | 54 bool NotificationObjectProxy::ShouldDisplaySettingsButton() { |
| 55 return true; | 55 return true; |
| 56 } | 56 } |
| 57 | 57 |
| 58 std::string NotificationObjectProxy::id() const { | 58 std::string NotificationObjectProxy::id() const { |
| 59 return id_; | 59 return notification_id_; |
| 60 } | 60 } |
| OLD | NEW |