• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2013 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.
4 
5 #ifndef CHROME_BROWSER_NOTIFICATIONS_SYNC_NOTIFIER_CHROME_NOTIFIER_DELEGATE_H_
6 #define CHROME_BROWSER_NOTIFICATIONS_SYNC_NOTIFIER_CHROME_NOTIFIER_DELEGATE_H_
7 
8 #include <map>
9 #include <string>
10 
11 #include "chrome/browser/notifications/notification_delegate.h"
12 #include "url/gurl.h"
13 
14 namespace notifier {
15 
16 enum SyncedNotificationActionType {
17   SYNCED_NOTIFICATION_ACTION_UNKNOWN,
18   SYNCED_NOTIFICATION_ACTION_CLICK,
19   SYNCED_NOTIFICATION_ACTION_BUTTON_CLICK,
20   SYNCED_NOTIFICATION_ACTION_CLOSE_BY_USER,
21   SYNCED_NOTIFICATION_ACTION_CLOSE_BY_SYSTEM,
22   SYNCED_NOTIFICATION_ACTION_TOAST_TIMEOUT,
23   // NOTE: Add new action types only immediately above this line. Also,
24   // make sure the enum list in tools/histogram/histograms.xml is
25   // updated with any change in here.
26   SYNCED_NOTIFICATION_ACTION_COUNT
27 };
28 
29 class ChromeNotifierService;
30 
31 // ChromeNotifierDelegate is a NotificationDelegate which catches
32 // responses from the NotificationUIManager when a notification
33 // has been closed.
34 
35 class ChromeNotifierDelegate : public NotificationDelegate {
36  public:
37   // We use an id instead of a notification so we can check to see if the
38   // notification still exists before acting on it instead of using a ref count.
39   explicit ChromeNotifierDelegate(const std::string& notification_id,
40                                   ChromeNotifierService* notifier);
41 
42   // NotificationDelegate interface.
Display()43   virtual void Display() OVERRIDE {}
Error()44   virtual void Error() OVERRIDE {}
45   virtual void Close(bool by_user) OVERRIDE;
46   virtual bool HasClickedListener() OVERRIDE;
47   virtual void Click() OVERRIDE;
48   virtual void ButtonClick(int button_index) OVERRIDE;
49   virtual std::string id() const OVERRIDE;
50 
51   virtual content::WebContents* GetWebContents() const OVERRIDE;
52 
53   void CollectAction(SyncedNotificationActionType type);
54 
55  private:
56   virtual ~ChromeNotifierDelegate();
57   void NavigateToUrl(const GURL& destination) const;
58   const GURL GetClickDestination() const;
59 
60   const std::string notification_id_;
61   ChromeNotifierService* const chrome_notifier_;
62 
63   DISALLOW_COPY_AND_ASSIGN(ChromeNotifierDelegate);
64 };
65 
66 }  // namespace notifier
67 
68 #endif  // CHROME_BROWSER_NOTIFICATIONS_SYNC_NOTIFIER_CHROME_NOTIFIER_DELEGATE_H_
69