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

Side by Side Diff: chrome/browser/notifications/notification_ui_manager_android.cc

Issue 826883003: Android Notifications should be closable without a delegate. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@a-serialize-pickle
Patch Set: Created 5 years, 11 months 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 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 "chrome/browser/notifications/notification_ui_manager_android.h" 5 #include "chrome/browser/notifications/notification_ui_manager_android.h"
6 6
7 #include "base/android/jni_array.h" 7 #include "base/android/jni_array.h"
8 #include "base/android/jni_string.h" 8 #include "base/android/jni_string.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/pickle.h" 10 #include "base/pickle.h"
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 137
138 NotificationUIManagerAndroid::~NotificationUIManagerAndroid() { 138 NotificationUIManagerAndroid::~NotificationUIManagerAndroid() {
139 Java_NotificationUIManager_destroy(AttachCurrentThread(), 139 Java_NotificationUIManager_destroy(AttachCurrentThread(),
140 java_object_.obj()); 140 java_object_.obj());
141 } 141 }
142 142
143 bool NotificationUIManagerAndroid::OnNotificationClicked( 143 bool NotificationUIManagerAndroid::OnNotificationClicked(
144 JNIEnv* env, 144 JNIEnv* env,
145 jobject java_object, 145 jobject java_object,
146 jstring notification_id, 146 jstring notification_id,
147 jint platform_id,
147 jbyteArray serialized_notification_data) { 148 jbyteArray serialized_notification_data) {
148 std::string id = ConvertJavaStringToUTF8(env, notification_id); 149 std::string id = ConvertJavaStringToUTF8(env, notification_id);
149 150
150 auto iter = profile_notifications_.find(id); 151 auto iter = profile_notifications_.find(id);
151 if (iter != profile_notifications_.end()) { 152 if (iter != profile_notifications_.end()) {
152 const Notification& notification = iter->second->notification(); 153 const Notification& notification = iter->second->notification();
153 notification.delegate()->Click(); 154 notification.delegate()->Click();
154 155
155 return true; 156 return true;
156 } 157 }
(...skipping 12 matching lines...) Expand all
169 content::PlatformNotificationData notification_data; 170 content::PlatformNotificationData notification_data;
170 GURL origin; 171 GURL origin;
171 int64 service_worker_registration_id; 172 int64 service_worker_registration_id;
172 173
173 Pickle pickle(reinterpret_cast<const char*>(&bytes[0]), bytes.size()); 174 Pickle pickle(reinterpret_cast<const char*>(&bytes[0]), bytes.size());
174 if (!UnserializePersistentNotification(pickle, &notification_data, &origin, 175 if (!UnserializePersistentNotification(pickle, &notification_data, &origin,
175 &service_worker_registration_id)) { 176 &service_worker_registration_id)) {
176 return false; 177 return false;
177 } 178 }
178 179
180 // Store the platform Id of this notification so that it can be closed.
181 platform_notifications_[id] = platform_id;
182
179 PlatformNotificationServiceImpl* service = 183 PlatformNotificationServiceImpl* service =
180 PlatformNotificationServiceImpl::GetInstance(); 184 PlatformNotificationServiceImpl::GetInstance();
181 185
182 // TODO(peter): Rather than assuming that the last used profile is the 186 // TODO(peter): Rather than assuming that the last used profile is the
183 // appropriate one for this notification, the used profile should be 187 // appropriate one for this notification, the used profile should be
184 // stored as part of the notification's data. See https://crbug.com/437574. 188 // stored as part of the notification's data. See https://crbug.com/437574.
185 service->OnPersistentNotificationClick( 189 service->OnPersistentNotificationClick(
186 ProfileManager::GetLastUsedProfile(), 190 ProfileManager::GetLastUsedProfile(),
187 service_worker_registration_id, 191 service_worker_registration_id,
188 id, 192 id,
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 301
298 return &profile_notification->notification(); 302 return &profile_notification->notification();
299 } 303 }
300 304
301 bool NotificationUIManagerAndroid::CancelById(const std::string& delegate_id, 305 bool NotificationUIManagerAndroid::CancelById(const std::string& delegate_id,
302 ProfileID profile_id) { 306 ProfileID profile_id) {
303 std::string profile_notification_id = 307 std::string profile_notification_id =
304 ProfileNotification::GetProfileNotificationId(delegate_id, profile_id); 308 ProfileNotification::GetProfileNotificationId(delegate_id, profile_id);
305 ProfileNotification* profile_notification = 309 ProfileNotification* profile_notification =
306 FindProfileNotification(profile_notification_id); 310 FindProfileNotification(profile_notification_id);
307 if (!profile_notification) 311 if (profile_notification) {
312 RemoveProfileNotification(profile_notification);
313 return true;
314 }
315
316 // On Android, it's still possible that the notification can be closed in case
317 // the platform Id is known, even if no delegate exists. This happens when the
318 // browser process is started because of interaction with a Notification.
319 auto platform_id_iter = platform_notifications_.find(delegate_id);
320 if (platform_id_iter == platform_notifications_.end())
dewittj 2015/01/08 01:06:17 Can this code be consolidated with the common code
Peter Beverloo 2015/01/08 19:28:19 Oops, missed that! Thanks and done :-)
308 return false; 321 return false;
309 322
310 RemoveProfileNotification(profile_notification); 323 Java_NotificationUIManager_closeNotification(AttachCurrentThread(),
324 java_object_.obj(),
325 platform_id_iter->second);
326
327 platform_notifications_.erase(platform_id_iter);
328
311 return true; 329 return true;
312 } 330 }
313 331
314 std::set<std::string> 332 std::set<std::string>
315 NotificationUIManagerAndroid::GetAllIdsByProfileAndSourceOrigin( 333 NotificationUIManagerAndroid::GetAllIdsByProfileAndSourceOrigin(
316 Profile* profile, 334 Profile* profile,
317 const GURL& source) { 335 const GURL& source) {
318 // |profile| may be invalid, so no calls must be made based on the instance. 336 // |profile| may be invalid, so no calls must be made based on the instance.
319 std::set<std::string> delegate_ids; 337 std::set<std::string> delegate_ids;
320 338
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 435
418 ProfileNotification* NotificationUIManagerAndroid::FindProfileNotification( 436 ProfileNotification* NotificationUIManagerAndroid::FindProfileNotification(
419 const std::string& id) const { 437 const std::string& id) const {
420 auto iter = profile_notifications_.find(id); 438 auto iter = profile_notifications_.find(id);
421 if (iter == profile_notifications_.end()) 439 if (iter == profile_notifications_.end())
422 return nullptr; 440 return nullptr;
423 441
424 return iter->second; 442 return iter->second;
425 } 443 }
426 444
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698