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

Unified Diff: chrome/browser/notifications/notification_platform_bridge_android.cc

Issue 2974573002: Refactor WebApkServiceConnectionManager. (Closed)
Patch Set: pkotwicz@‘s comments. Created 3 years, 5 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 side-by-side diff with in-line comments
Download patch
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 7e928f279298e93015e0d898ff4596204b01869a..67aac1eec82be608e78be1b2bf793662358c8bb5 100644
--- a/chrome/browser/notifications/notification_platform_bridge_android.cc
+++ b/chrome/browser/notifications/notification_platform_bridge_android.cc
@@ -9,6 +9,7 @@
#include "base/android/jni_array.h"
#include "base/android/jni_string.h"
+#include "base/bind.h"
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/logging.h"
@@ -43,6 +44,10 @@ using base::android::ScopedJavaLocalRef;
namespace {
+// Callback to call after querying WebAPK package name is done.
+// The parameter is the package name of the WebAPK that matches the query.
+using QueryWebApkPackageCallback = base::Callback<void(const std::string&)>;
+
// A Java counterpart will be generated for this enum.
// GENERATED_JAVA_ENUM_PACKAGE: org.chromium.chrome.browser.notifications
enum NotificationActionType {
@@ -139,7 +144,8 @@ NotificationPlatformBridge* NotificationPlatformBridge::Create() {
return new NotificationPlatformBridgeAndroid();
}
-NotificationPlatformBridgeAndroid::NotificationPlatformBridgeAndroid() {
+NotificationPlatformBridgeAndroid::NotificationPlatformBridgeAndroid()
+ : weak_ptr_factory_(this) {
java_object_.Reset(Java_NotificationPlatformBridge_create(
AttachCurrentThread(), reinterpret_cast<intptr_t>(this)));
}
@@ -212,6 +218,20 @@ void NotificationPlatformBridgeAndroid::OnNotificationClosed(
-1 /* action index */, base::NullableString16() /* reply */));
}
+void NotificationPlatformBridgeAndroid::OnQueryWebApkPackage(
+ JNIEnv* env,
+ const JavaParamRef<jobject>& java_object,
+ const JavaParamRef<jstring>& java_webapk_package,
+ const jlong jcallback_pointer) {
+ DCHECK(jcallback_pointer);
+ std::string webapk_package =
+ ConvertJavaStringToUTF8(env, java_webapk_package);
+ QueryWebApkPackageCallback* callback =
+ reinterpret_cast<QueryWebApkPackageCallback*>(jcallback_pointer);
+ callback->Run(webapk_package);
+ delete callback;
+}
+
void NotificationPlatformBridgeAndroid::Display(
NotificationCommon::Type notification_type,
const std::string& notification_id,
@@ -224,19 +244,31 @@ void NotificationPlatformBridgeAndroid::Display(
// Android.
DCHECK_EQ(notification_type, NotificationCommon::PERSISTENT);
- GURL origin_url(notification.origin_url().GetOrigin());
-
GURL scope_url(notification.service_worker_scope());
if (!scope_url.is_valid())
- scope_url = origin_url;
+ scope_url = GURL(notification.origin_url().GetOrigin());
ScopedJavaLocalRef<jstring> j_scope_url =
ConvertUTF8ToJavaString(env, scope_url.spec());
- ScopedJavaLocalRef<jstring> webapk_package =
- Java_NotificationPlatformBridge_queryWebApkPackage(
- env, java_object_, j_scope_url);
+ uintptr_t callback_pointer =
+ reinterpret_cast<uintptr_t>(new QueryWebApkPackageCallback(
+ base::Bind(&NotificationPlatformBridgeAndroid::DisplayInternal,
+ weak_ptr_factory_.GetWeakPtr(), notification_id,
+ profile_id, incognito, notification)));
+ Java_NotificationPlatformBridge_queryWebApkPackage(
+ env, java_object_, j_scope_url, callback_pointer);
+}
+void NotificationPlatformBridgeAndroid::DisplayInternal(
pkotwicz 2017/07/20 01:32:05 .cc and .h order applies to DisplayInternal() too
Xi Han 2017/07/21 20:36:35 Done.
+ const std::string& notification_id,
+ const std::string& profile_id,
+ bool incognito,
+ const Notification& notification,
+ const std::string& webapk_package) {
+ JNIEnv* env = AttachCurrentThread();
ScopedJavaLocalRef<jstring> j_notification_id =
ConvertUTF8ToJavaString(env, notification_id);
+
+ GURL origin_url(notification.origin_url().GetOrigin());
ScopedJavaLocalRef<jstring> j_origin =
ConvertUTF8ToJavaString(env, origin_url.spec());
ScopedJavaLocalRef<jstring> tag =
@@ -269,16 +301,18 @@ void NotificationPlatformBridgeAndroid::Display(
ScopedJavaLocalRef<jstring> j_profile_id =
ConvertUTF8ToJavaString(env, profile_id);
+ ScopedJavaLocalRef<jstring> j_webapk_package =
+ ConvertUTF8ToJavaString(env, webapk_package);
Java_NotificationPlatformBridge_displayNotification(
env, java_object_, j_notification_id, j_origin, j_profile_id, incognito,
- tag, webapk_package, title, body, image, notification_icon, badge,
+ tag, j_webapk_package, title, body, image, notification_icon, badge,
vibration_pattern, notification.timestamp().ToJavaTime(),
notification.renotify(), notification.silent(), actions);
regenerated_notification_infos_[notification_id] =
RegeneratedNotificationInfo(origin_url.spec(), notification.tag(),
- ConvertJavaStringToUTF8(env, webapk_package));
+ webapk_package);
}
void NotificationPlatformBridgeAndroid::Close(

Powered by Google App Engine
This is Rietveld 408576698