Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: chrome/browser/printing/cloud_print/privet_notifications.h

Issue 2446043002: Close privet printer notifications when clicked. (Closed)
Patch Set: Add test, fix potential UAF Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_PRINTING_CLOUD_PRINT_PRIVET_NOTIFICATIONS_H_ 5 #ifndef CHROME_BROWSER_PRINTING_CLOUD_PRINT_PRIVET_NOTIFICATIONS_H_
6 #define CHROME_BROWSER_PRINTING_CLOUD_PRINT_PRIVET_NOTIFICATIONS_H_ 6 #define CHROME_BROWSER_PRINTING_CLOUD_PRINT_PRIVET_NOTIFICATIONS_H_
7 7
8 #include <map> 8 #include <map>
9 #include <memory> 9 #include <memory>
10 #include <string> 10 #include <string>
11 11
12 #include "chrome/browser/notifications/notification_delegate.h" 12 #include "chrome/browser/notifications/notification_delegate.h"
13 #include "chrome/browser/printing/cloud_print/privet_device_lister.h" 13 #include "chrome/browser/printing/cloud_print/privet_device_lister.h"
14 #include "chrome/browser/printing/cloud_print/privet_http.h" 14 #include "chrome/browser/printing/cloud_print/privet_http.h"
15 #include "components/keyed_service/core/keyed_service.h" 15 #include "components/keyed_service/core/keyed_service.h"
16 #include "components/prefs/pref_member.h" 16 #include "components/prefs/pref_member.h"
17 17
18 class NotificationUIManager; 18 class NotificationUIManager;
19 class Profile;
19 20
20 namespace content { 21 namespace content {
21 class BrowserContext; 22 class BrowserContext;
22 } 23 }
23 24
24 namespace local_discovery { 25 namespace local_discovery {
25 class ServiceDiscoverySharedClient; 26 class ServiceDiscoverySharedClient;
26 } 27 }
27 28
28 namespace cloud_print { 29 namespace cloud_print {
29 30
30 class PrivetDeviceLister; 31 class PrivetDeviceLister;
31 class PrivetHTTPAsynchronousFactory; 32 class PrivetHTTPAsynchronousFactory;
32 class PrivetHTTPResolution; 33 class PrivetHTTPResolution;
34 class PrivetNotificationDelegate;
33 struct DeviceDescription; 35 struct DeviceDescription;
34 36
35 #if defined(ENABLE_MDNS) 37 #if defined(ENABLE_MDNS)
36 class PrivetTrafficDetector; 38 class PrivetTrafficDetector;
37 #endif // ENABLE_MDNS 39 #endif // ENABLE_MDNS
38 40
39 // Contains logic related to notifications not tied actually displaying them. 41 // Contains logic related to notifications not tied actually displaying them.
40 class PrivetNotificationsListener { 42 class PrivetNotificationsListener {
41 public: 43 public:
42 class Delegate { 44 class Delegate {
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 void PrivetRemoveNotification() override; 114 void PrivetRemoveNotification() override;
113 115
114 static bool IsEnabled(); 116 static bool IsEnabled();
115 static bool IsForced(); 117 static bool IsForced();
116 118
117 private: 119 private:
118 void Start(); 120 void Start();
119 void OnNotificationsEnabledChanged(); 121 void OnNotificationsEnabledChanged();
120 void StartLister(); 122 void StartLister();
121 123
124 // Virtual for testing. The returned delegate is refcounted.
125 virtual PrivetNotificationDelegate* CreateNotificationDelegate(
126 Profile* profile);
127
122 content::BrowserContext* const profile_; 128 content::BrowserContext* const profile_;
123 std::unique_ptr<PrivetDeviceLister> device_lister_; 129 std::unique_ptr<PrivetDeviceLister> device_lister_;
124 scoped_refptr<local_discovery::ServiceDiscoverySharedClient> 130 scoped_refptr<local_discovery::ServiceDiscoverySharedClient>
125 service_discovery_client_; 131 service_discovery_client_;
126 std::unique_ptr<PrivetNotificationsListener> privet_notifications_listener_; 132 std::unique_ptr<PrivetNotificationsListener> privet_notifications_listener_;
127 BooleanPrefMember enable_privet_notification_member_; 133 BooleanPrefMember enable_privet_notification_member_;
128 134
129 #if defined(ENABLE_MDNS) 135 #if defined(ENABLE_MDNS)
130 scoped_refptr<PrivetTrafficDetector> traffic_detector_; 136 scoped_refptr<PrivetTrafficDetector> traffic_detector_;
131 #endif // ENABLE_MDNS 137 #endif // ENABLE_MDNS
132 }; 138 };
133 139
134 class PrivetNotificationDelegate : public NotificationDelegate { 140 class PrivetNotificationDelegate : public NotificationDelegate {
135 public: 141 public:
136 explicit PrivetNotificationDelegate(content::BrowserContext* profile); 142 explicit PrivetNotificationDelegate(Profile* profile);
137 143
138 // NotificationDelegate implementation. 144 // NotificationDelegate implementation.
139 std::string id() const override; 145 std::string id() const override;
140 void ButtonClick(int button_index) override; 146 void ButtonClick(int button_index) override;
141 147
142 private: 148 protected:
143 // Refcounted. 149 // Refcounted.
144 ~PrivetNotificationDelegate() override; 150 ~PrivetNotificationDelegate() override;
145 151
146 void OpenTab(const GURL& url); 152 private:
147 void DisableNotifications(); 153 // ButtonClick() response handlers. Virtual for testing.
154 virtual void OpenTab(const GURL& url);
155 virtual void DisableNotifications();
148 156
149 content::BrowserContext* const profile_; 157 void CloseNotification();
158
159 Profile* const profile_;
150 }; 160 };
151 161
152 } // namespace cloud_print 162 } // namespace cloud_print
153 163
154 #endif // CHROME_BROWSER_PRINTING_CLOUD_PRINT_PRIVET_NOTIFICATIONS_H_ 164 #endif // CHROME_BROWSER_PRINTING_CLOUD_PRINT_PRIVET_NOTIFICATIONS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698