Index: chrome/browser/notifications/notification_platform_bridge_android.cc |
diff --git a/chrome/browser/notifications/notification_platform_bridge_android.cc b/chrome/browser/notifications/notification_platform_bridge_android.cc |
index 3e1204e64312ec893d51fcd83399659cef0d2d10..139c0a68a6a783b64774891cd188b25284b13d94 100644 |
--- a/chrome/browser/notifications/notification_platform_bridge_android.cc |
+++ b/chrome/browser/notifications/notification_platform_bridge_android.cc |
@@ -14,8 +14,10 @@ |
#include "base/logging.h" |
#include "base/strings/string_number_conversions.h" |
#include "chrome/browser/browser_process.h" |
+#include "chrome/browser/notifications/native_notification_display_service.h" |
#include "chrome/browser/notifications/notification.h" |
#include "chrome/browser/notifications/notification_common.h" |
+#include "chrome/browser/notifications/notification_display_service_factory.h" |
#include "chrome/browser/notifications/persistent_notification_delegate.h" |
#include "chrome/browser/notifications/platform_notification_service_impl.h" |
#include "chrome/browser/profiles/profile_manager.h" |
@@ -59,6 +61,31 @@ ScopedJavaLocalRef<jobjectArray> ConvertToJavaBitmaps( |
return ScopedJavaLocalRef<jobjectArray>(env, array); |
} |
+// Callback to run once the profile has been loaded in order to perform a |
+// given |operation| in a notification. |
+// TODO(miguelg) move it to notification_common? |
+void ProfileLoadedCallback(NotificationCommon::Operation operation, |
+ NotificationCommon::Type notification_type, |
+ const std::string& origin, |
+ int64_t notification_id, |
+ int action_index, |
+ Profile* profile) { |
+ if (!profile) { |
+ // TODO(miguelg): Add UMA for this condition. |
+ // Perhaps propagate this through PersistentNotificationStatus. |
+ LOG(WARNING) << "Profile not loaded correctly"; |
+ return; |
+ } |
+ |
+ NotificationDisplayService* display_service = |
+ NotificationDisplayServiceFactory::GetForProfile(profile); |
+ |
+ static_cast<NativeNotificationDisplayService*>(display_service) |
+ ->ProcessNotificationOperation(operation, notification_type, origin, |
+ base::Int64ToString(notification_id), |
+ action_index); |
+} |
+ |
} // namespace |
// Called by the Java side when a notification event has been received, but the |
@@ -95,19 +122,23 @@ void NotificationPlatformBridgeAndroid::OnNotificationClicked( |
const JavaParamRef<jstring>& java_tag, |
const JavaParamRef<jstring>& java_webapk_package, |
jint action_index) { |
- GURL origin(ConvertJavaStringToUTF8(env, java_origin)); |
std::string tag = ConvertJavaStringToUTF8(env, java_tag); |
std::string profile_id = ConvertJavaStringToUTF8(env, java_profile_id); |
std::string webapk_package = |
ConvertJavaStringToUTF8(env, java_webapk_package); |
+ GURL origin(ConvertJavaStringToUTF8(env, java_origin)); |
regenerated_notification_infos_[persistent_notification_id] = |
RegeneratedNotificationInfo(origin.spec(), tag, webapk_package); |
- PlatformNotificationServiceImpl::GetInstance() |
- ->ProcessPersistentNotificationOperation( |
- NotificationCommon::CLICK, profile_id, incognito, origin, |
- persistent_notification_id, action_index); |
+ ProfileManager* profile_manager = g_browser_process->profile_manager(); |
+ DCHECK(profile_manager); |
+ |
+ profile_manager->LoadProfile( |
+ profile_id, incognito, |
+ base::Bind(&ProfileLoadedCallback, NotificationCommon::CLICK, |
+ NotificationCommon::PERSISTENT, origin.spec(), |
+ persistent_notification_id, action_index)); |
} |
void NotificationPlatformBridgeAndroid::OnNotificationClosed( |
@@ -119,37 +150,44 @@ void NotificationPlatformBridgeAndroid::OnNotificationClosed( |
jboolean incognito, |
const JavaParamRef<jstring>& java_tag, |
jboolean by_user) { |
- GURL origin(ConvertJavaStringToUTF8(env, java_origin)); |
std::string profile_id = ConvertJavaStringToUTF8(env, java_profile_id); |
- std::string tag = ConvertJavaStringToUTF8(env, java_tag); |
// The notification was closed by the platform, so clear all local state. |
regenerated_notification_infos_.erase(persistent_notification_id); |
- PlatformNotificationServiceImpl::GetInstance() |
- ->ProcessPersistentNotificationOperation( |
- NotificationCommon::CLOSE, profile_id, incognito, origin, |
- persistent_notification_id, -1); |
+ |
+ ProfileManager* profile_manager = g_browser_process->profile_manager(); |
+ DCHECK(profile_manager); |
+ |
+ profile_manager->LoadProfile( |
+ profile_id, incognito, |
+ base::Bind(&ProfileLoadedCallback, NotificationCommon::CLOSE, |
+ NotificationCommon::PERSISTENT, |
+ ConvertJavaStringToUTF8(env, java_origin), |
+ persistent_notification_id, -1 /* action index */)); |
} |
void NotificationPlatformBridgeAndroid::Display( |
+ NotificationCommon::Type notification_type, |
const std::string& notification_id, |
const std::string& profile_id, |
bool incognito, |
const Notification& notification) { |
JNIEnv* env = AttachCurrentThread(); |
+ // TODO(miguelg): Store the notification type in java instead of assuming it's |
+ // persistent once/if non persistent notifications are ever implemented on |
+ // Android. |
+ DCHECK_EQ(notification_type, NotificationCommon::PERSISTENT); |
+ |
+ // TODO(miguelg): Store the persistent notification in Java and the |
+ // regenerated_notification_infos_ as a string instead of converting it back |
+ // and forth to int64. |
+ int64_t persistent_notification_id; |
+ if (!base::StringToInt64(notification_id, &persistent_notification_id)) { |
+ LOG(ERROR) << "Unable to convert notification ID: " << notification_id |
+ << " to integer."; |
+ return; |
+ } |
- // The Android notification platform bridge only supports Web Notifications, |
- // which have a PersistentNotificationDelegate. The persistent id of the |
- // notification is exposed through it's interface. |
- // |
- // TODO(peter): When content/ passes a message_center::Notification to the |
- // chrome/ layer, the persistent notification id should be captured as a |
- // property on that object instead, making this cast unnecessary. |
- PersistentNotificationDelegate* delegate = |
- static_cast<PersistentNotificationDelegate*>(notification.delegate()); |
- DCHECK(delegate); |
- |
- int64_t persistent_notification_id = delegate->persistent_notification_id(); |
GURL origin_url(notification.origin_url().GetOrigin()); |
ScopedJavaLocalRef<jstring> origin = |