summaryrefslogtreecommitdiffstats
path: root/chrome/browser/notifications/sync_notifier/chrome_notifier_delegate.h
blob: 4bf75fedf9f45c130c1946a40147b6c97065ba58 (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
// Copyright (c) 2013 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.

#ifndef CHROME_BROWSER_NOTIFICATIONS_SYNC_NOTIFIER_CHROME_NOTIFIER_DELEGATE_H_
#define CHROME_BROWSER_NOTIFICATIONS_SYNC_NOTIFIER_CHROME_NOTIFIER_DELEGATE_H_

#include <map>
#include <string>

#include "chrome/browser/notifications/notification_delegate.h"
#include "url/gurl.h"

namespace notifier {

enum SyncedNotificationActionType {
  SYNCED_NOTIFICATION_ACTION_UNKNOWN,
  SYNCED_NOTIFICATION_ACTION_CLICK,
  SYNCED_NOTIFICATION_ACTION_BUTTON_CLICK,
  SYNCED_NOTIFICATION_ACTION_CLOSE_BY_USER,
  SYNCED_NOTIFICATION_ACTION_CLOSE_BY_SYSTEM,
  SYNCED_NOTIFICATION_ACTION_TOAST_TIMEOUT,
  // NOTE: Add new action types only immediately above this line. Also,
  // make sure the enum list in tools/histogram/histograms.xml is
  // updated with any change in here.
  SYNCED_NOTIFICATION_ACTION_COUNT
};

class ChromeNotifierService;

// ChromeNotifierDelegate is a NotificationDelegate which catches
// responses from the NotificationUIManager when a notification
// has been closed.

class ChromeNotifierDelegate : public NotificationDelegate {
 public:
  // We use an id instead of a notification so we can check to see if the
  // notification still exists before acting on it instead of using a ref count.
  explicit ChromeNotifierDelegate(const std::string& notification_id,
                                  ChromeNotifierService* notifier);

  // NotificationDelegate interface.
  virtual void Display() OVERRIDE {}
  virtual void Error() OVERRIDE {}
  virtual void Close(bool by_user) OVERRIDE;
  virtual void Click() OVERRIDE;
  virtual void ButtonClick(int button_index) OVERRIDE;
  virtual std::string id() const OVERRIDE;

  virtual content::RenderViewHost* GetRenderViewHost() const OVERRIDE;

  void CollectAction(SyncedNotificationActionType type);

 private:
  virtual ~ChromeNotifierDelegate();
  void NavigateToUrl(const GURL& destination) const;

  const std::string notification_id_;
  ChromeNotifierService* const chrome_notifier_;

  DISALLOW_COPY_AND_ASSIGN(ChromeNotifierDelegate);
};

}  // namespace notifier

#endif  // CHROME_BROWSER_NOTIFICATIONS_SYNC_NOTIFIER_CHROME_NOTIFIER_DELEGATE_H_