Roll src/third_party/WebKit eac3800:0237a66 (svn 202606:202607)
[chromium-blink-merge.git] / chrome / browser / notifications / notification_object_proxy.cc
blob91063b4484921bccf3d29fa39ff7f3d0d1f59c12
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
3 // found in the LICENSE file.
5 #include "chrome/browser/notifications/notification_object_proxy.h"
7 #include "base/guid.h"
8 #include "base/logging.h"
9 #include "chrome/browser/notifications/platform_notification_service_impl.h"
10 #include "content/public/browser/desktop_notification_delegate.h"
12 NotificationObjectProxy::NotificationObjectProxy(
13 content::BrowserContext* browser_context,
14 scoped_ptr<content::DesktopNotificationDelegate> delegate)
15 : browser_context_(browser_context),
16 delegate_(delegate.Pass()),
17 displayed_(false),
18 id_(base::GenerateGUID()) {}
20 NotificationObjectProxy::~NotificationObjectProxy() {}
22 void NotificationObjectProxy::Display() {
23 // This method is called each time the notification is shown to the user
24 // but we only want to fire the event the first time.
25 if (displayed_)
26 return;
27 displayed_ = true;
29 delegate_->NotificationDisplayed();
32 void NotificationObjectProxy::Close(bool by_user) {
33 delegate_->NotificationClosed();
36 void NotificationObjectProxy::Click() {
37 delegate_->NotificationClick();
40 void NotificationObjectProxy::ButtonClick(int button_index) {
41 // Notification buttons not are supported for non persistent notifications.
42 DCHECK_EQ(button_index, 0);
43 PlatformNotificationServiceImpl::GetInstance()->OpenNotificationSettings(
44 browser_context_);
47 std::string NotificationObjectProxy::id() const {
48 return id_;