summaryrefslogtreecommitdiffstats
path: root/chrome/browser/notifications/notification_object_proxy.cc
blob: cef1b00a2a26fea89efa86168ddb8244508617b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/notifications/notification_object_proxy.h"

#include <utility>

#include "base/guid.h"
#include "base/logging.h"
#include "chrome/browser/notifications/platform_notification_service_impl.h"
#include "content/public/browser/desktop_notification_delegate.h"

NotificationObjectProxy::NotificationObjectProxy(
    content::BrowserContext* browser_context,
    scoped_ptr<content::DesktopNotificationDelegate> delegate)
    : browser_context_(browser_context),
      delegate_(std::move(delegate)),
      displayed_(false),
      id_(base::GenerateGUID()) {}

NotificationObjectProxy::~NotificationObjectProxy() {}

void NotificationObjectProxy::Display() {
  // This method is called each time the notification is shown to the user
  // but we only want to fire the event the first time.
  if (displayed_)
    return;
  displayed_ = true;

  delegate_->NotificationDisplayed();
}

void NotificationObjectProxy::Close(bool by_user) {
  delegate_->NotificationClosed();
}

void NotificationObjectProxy::Click() {
  delegate_->NotificationClick();
}

void NotificationObjectProxy::ButtonClick(int button_index) {
  // Notification buttons not are supported for non persistent notifications.
  DCHECK_EQ(button_index, 0);
  PlatformNotificationServiceImpl::GetInstance()->OpenNotificationSettings(
      browser_context_);
}

void NotificationObjectProxy::SettingsClick() {
  PlatformNotificationServiceImpl::GetInstance()->OpenNotificationSettings(
      browser_context_);
  return;
}

bool NotificationObjectProxy::ShouldDisplaySettingsButton() {
  return true;
}

std::string NotificationObjectProxy::id() const {
  return id_;
}