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

Side by Side Diff: content/shell/browser/layout_test/layout_test_notification_manager.cc

Issue 794633002: Remove ShowDesktopNotificationHostMsgParams in favor of PlatformNotificationData. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comments Created 6 years 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
« no previous file with comments | « content/shell/browser/layout_test/layout_test_notification_manager.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #include "content/shell/browser/layout_test/layout_test_notification_manager.h" 5 #include "content/shell/browser/layout_test/layout_test_notification_manager.h"
6 6
7 #include "base/guid.h" 7 #include "base/guid.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "content/public/browser/browser_thread.h" 9 #include "content/public/browser/browser_thread.h"
10 #include "content/public/browser/desktop_notification_delegate.h" 10 #include "content/public/browser/desktop_notification_delegate.h"
11 #include "content/public/browser/notification_event_dispatcher.h" 11 #include "content/public/browser/notification_event_dispatcher.h"
12 #include "content/public/common/persistent_notification_status.h" 12 #include "content/public/common/persistent_notification_status.h"
13 #include "content/public/common/show_desktop_notification_params.h" 13 #include "content/public/common/platform_notification_data.h"
14 14
15 namespace content { 15 namespace content {
16 namespace { 16 namespace {
17 17
18 // The Web Notification layout tests don't care about the lifetime of the 18 // The Web Notification layout tests don't care about the lifetime of the
19 // Service Worker when a notificationclick event has been dispatched. 19 // Service Worker when a notificationclick event has been dispatched.
20 void OnEventDispatchComplete(PersistentNotificationStatus status) {} 20 void OnEventDispatchComplete(PersistentNotificationStatus status) {}
21 21
22 } // namespace 22 } // namespace
23 23
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 permission_map_[origin] = permission; 55 permission_map_[origin] = permission;
56 } 56 }
57 57
58 void LayoutTestNotificationManager::ClearPermissions() { 58 void LayoutTestNotificationManager::ClearPermissions() {
59 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 59 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
60 permission_map_.clear(); 60 permission_map_.clear();
61 } 61 }
62 62
63 void LayoutTestNotificationManager::DisplayNotification( 63 void LayoutTestNotificationManager::DisplayNotification(
64 BrowserContext* browser_context, 64 BrowserContext* browser_context,
65 const ShowDesktopNotificationHostMsgParams& params, 65 const GURL& origin,
66 const SkBitmap& icon,
67 const PlatformNotificationData& notification_data,
66 scoped_ptr<DesktopNotificationDelegate> delegate, 68 scoped_ptr<DesktopNotificationDelegate> delegate,
67 int render_process_id, 69 int render_process_id,
68 base::Closure* cancel_callback) { 70 base::Closure* cancel_callback) {
69 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 71 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
70 std::string title = base::UTF16ToUTF8(params.title); 72 std::string title = base::UTF16ToUTF8(notification_data.title);
71 73
72 DCHECK(cancel_callback); 74 DCHECK(cancel_callback);
73 *cancel_callback = base::Bind(&LayoutTestNotificationManager::Close, 75 *cancel_callback = base::Bind(&LayoutTestNotificationManager::Close,
74 weak_factory_.GetWeakPtr(), 76 weak_factory_.GetWeakPtr(),
75 title); 77 title);
76 78
77 ReplaceNotificationIfNeeded(params); 79 ReplaceNotificationIfNeeded(notification_data);
78 80
79 page_notifications_[title] = delegate.release(); 81 page_notifications_[title] = delegate.release();
80 page_notifications_[title]->NotificationDisplayed(); 82 page_notifications_[title]->NotificationDisplayed();
81 } 83 }
82 84
83 void LayoutTestNotificationManager::DisplayPersistentNotification( 85 void LayoutTestNotificationManager::DisplayPersistentNotification(
84 BrowserContext* browser_context, 86 BrowserContext* browser_context,
85 int64 service_worker_registration_id, 87 int64 service_worker_registration_id,
86 const ShowDesktopNotificationHostMsgParams& params, 88 const GURL& origin,
89 const SkBitmap& icon,
90 const PlatformNotificationData& notification_data,
87 int render_process_id) { 91 int render_process_id) {
88 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 92 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
89 std::string title = base::UTF16ToUTF8(params.title); 93 std::string title = base::UTF16ToUTF8(notification_data.title);
90 94
91 ReplaceNotificationIfNeeded(params); 95 ReplaceNotificationIfNeeded(notification_data);
92 96
93 PersistentNotification notification; 97 PersistentNotification notification;
94 notification.browser_context = browser_context; 98 notification.browser_context = browser_context;
95 notification.notification_data = params; 99 notification.origin = origin;
100 notification.notification_data = notification_data;
96 notification.service_worker_registration_id = service_worker_registration_id; 101 notification.service_worker_registration_id = service_worker_registration_id;
97 notification.persistent_id = base::GenerateGUID(); 102 notification.persistent_id = base::GenerateGUID();
98 103
99 persistent_notifications_[title] = notification; 104 persistent_notifications_[title] = notification;
100 } 105 }
101 106
102 void LayoutTestNotificationManager::ClosePersistentNotification( 107 void LayoutTestNotificationManager::ClosePersistentNotification(
103 BrowserContext* browser_context, 108 BrowserContext* browser_context,
104 const std::string& persistent_notification_id) { 109 const std::string& persistent_notification_id) {
105 for (const auto& iter : persistent_notifications_) { 110 for (const auto& iter : persistent_notifications_) {
(...skipping 17 matching lines...) Expand all
123 128
124 // Then check for persistent notifications with the given title. 129 // Then check for persistent notifications with the given title.
125 const auto& persistent_iterator = persistent_notifications_.find(title); 130 const auto& persistent_iterator = persistent_notifications_.find(title);
126 if (persistent_iterator == persistent_notifications_.end()) 131 if (persistent_iterator == persistent_notifications_.end())
127 return; 132 return;
128 133
129 const PersistentNotification& notification = persistent_iterator->second; 134 const PersistentNotification& notification = persistent_iterator->second;
130 content::NotificationEventDispatcher::GetInstance() 135 content::NotificationEventDispatcher::GetInstance()
131 ->DispatchNotificationClickEvent( 136 ->DispatchNotificationClickEvent(
132 notification.browser_context, 137 notification.browser_context,
133 notification.notification_data.origin, 138 notification.origin,
134 notification.service_worker_registration_id, 139 notification.service_worker_registration_id,
135 notification.persistent_id, 140 notification.persistent_id,
136 notification.notification_data, 141 notification.notification_data,
137 base::Bind(&OnEventDispatchComplete)); 142 base::Bind(&OnEventDispatchComplete));
138 } 143 }
139 144
140 void LayoutTestNotificationManager::Close(const std::string& title) { 145 void LayoutTestNotificationManager::Close(const std::string& title) {
141 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 146 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
142 auto iterator = page_notifications_.find(title); 147 auto iterator = page_notifications_.find(title);
143 if (iterator == page_notifications_.end()) 148 if (iterator == page_notifications_.end())
144 return; 149 return;
145 150
146 iterator->second->NotificationClosed(false); 151 iterator->second->NotificationClosed(false);
147 } 152 }
148 153
149 void LayoutTestNotificationManager::ReplaceNotificationIfNeeded( 154 void LayoutTestNotificationManager::ReplaceNotificationIfNeeded(
150 const ShowDesktopNotificationHostMsgParams& params) { 155 const PlatformNotificationData& notification_data) {
151 if (!params.replace_id.length()) 156 if (!notification_data.tag.length())
152 return; 157 return;
153 158
154 std::string replace_id = base::UTF16ToUTF8(params.replace_id); 159 std::string replace_id = base::UTF16ToUTF8(notification_data.tag);
155 const auto& replace_iter = replacements_.find(replace_id); 160 const auto& replace_iter = replacements_.find(replace_id);
156 if (replace_iter != replacements_.end()) { 161 if (replace_iter != replacements_.end()) {
157 const std::string& previous_title = replace_iter->second; 162 const std::string& previous_title = replace_iter->second;
158 163
159 const auto& page_notification_iter = 164 const auto& page_notification_iter =
160 page_notifications_.find(previous_title); 165 page_notifications_.find(previous_title);
161 if (page_notification_iter != page_notifications_.end()) { 166 if (page_notification_iter != page_notifications_.end()) {
162 DesktopNotificationDelegate* previous_delegate = 167 DesktopNotificationDelegate* previous_delegate =
163 page_notification_iter->second; 168 page_notification_iter->second;
164 169
165 previous_delegate->NotificationClosed(false); 170 previous_delegate->NotificationClosed(false);
166 171
167 page_notifications_.erase(page_notification_iter); 172 page_notifications_.erase(page_notification_iter);
168 delete previous_delegate; 173 delete previous_delegate;
169 } 174 }
170 175
171 const auto& persistent_notification_iter = 176 const auto& persistent_notification_iter =
172 persistent_notifications_.find(previous_title); 177 persistent_notifications_.find(previous_title);
173 if (persistent_notification_iter != persistent_notifications_.end()) 178 if (persistent_notification_iter != persistent_notifications_.end())
174 persistent_notifications_.erase(persistent_notification_iter); 179 persistent_notifications_.erase(persistent_notification_iter);
175 } 180 }
176 181
177 replacements_[replace_id] = base::UTF16ToUTF8(params.title); 182 replacements_[replace_id] = base::UTF16ToUTF8(notification_data.title);
178 } 183 }
179 184
180 } // namespace content 185 } // namespace content
OLDNEW
« no previous file with comments | « content/shell/browser/layout_test/layout_test_notification_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698