summaryrefslogtreecommitdiffstats
path: root/chrome/browser/download/notification/download_notification.cc
blob: e82ea5771de9042870d1de1ab7d142b0da100b10 (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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Copyright 2015 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/download/notification/download_notification.h"

#include "base/macros.h"
#include "chrome/browser/download/notification/download_notification_manager.h"

namespace {

///////////////////////////////////////////////////////////////////////////////
// NotificationWatcher class:
///////////////////////////////////////////////////////////////////////////////

class NotificationWatcher : public NotificationDelegate {
 public:
  explicit NotificationWatcher(DownloadNotification* item) : item_(item) {}

  // NotificationDelegate overrides:
  void Close(bool by_user) override {
    item_->OnNotificationClose();
  }

  void Click() override {
    item_->OnNotificationClick();
  }

  bool HasClickedListener() override {
    return item_->HasNotificationClickedListener();
  }

  void ButtonClick(int button_index) override {
    item_->OnNotificationButtonClick(button_index);
  }

  std::string id() const override {
    return item_->GetNotificationId();
  }

 private:
  ~NotificationWatcher() override {}

  DownloadNotification* item_;

  DISALLOW_COPY_AND_ASSIGN(NotificationWatcher);
};

}  // anonymous namespace

///////////////////////////////////////////////////////////////////////////////
// DownloadNotification implementation:
///////////////////////////////////////////////////////////////////////////////

// static
const char DownloadNotification::kDownloadNotificationOrigin[] =
    "chrome://downloads";

DownloadNotification::DownloadNotification()
    : watcher_(new NotificationWatcher(this)) {}

DownloadNotification::~DownloadNotification() {}

bool DownloadNotification::HasNotificationClickedListener() {
  // True by default.
  return true;
}

NotificationDelegate* DownloadNotification::watcher() const {
  return watcher_.get();
}

void DownloadNotification::InvokeUnsafeForceNotificationFlush(
    message_center::MessageCenter* message_center, const std::string& id) {
  DCHECK(message_center);
  message_center->ForceNotificationFlush(id);
}