Chromium Code Reviews| OLD | NEW |
|---|---|
| 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_platform_bridge_android.h" | 5 #include "chrome/browser/notifications/notification_platform_bridge_android.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/android/build_info.h" | |
| 10 #include "base/android/jni_array.h" | 11 #include "base/android/jni_array.h" |
| 11 #include "base/android/jni_string.h" | 12 #include "base/android/jni_string.h" |
| 12 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 13 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
| 14 #include "base/logging.h" | 15 #include "base/logging.h" |
| 15 #include "base/strings/nullable_string16.h" | 16 #include "base/strings/nullable_string16.h" |
| 16 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
| 17 #include "chrome/browser/browser_process.h" | 18 #include "chrome/browser/browser_process.h" |
| 18 #include "chrome/browser/notifications/native_notification_display_service.h" | 19 #include "chrome/browser/notifications/native_notification_display_service.h" |
| 19 #include "chrome/browser/notifications/notification.h" | 20 #include "chrome/browser/notifications/notification.h" |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 308 | 309 |
| 309 Java_NotificationPlatformBridge_closeNotification( | 310 Java_NotificationPlatformBridge_closeNotification( |
| 310 env, java_object_, j_profile_id, j_notification_id, origin, tag, | 311 env, java_object_, j_profile_id, j_notification_id, origin, tag, |
| 311 webapk_package); | 312 webapk_package); |
| 312 } | 313 } |
| 313 | 314 |
| 314 bool NotificationPlatformBridgeAndroid::GetDisplayed( | 315 bool NotificationPlatformBridgeAndroid::GetDisplayed( |
| 315 const std::string& profile_id, | 316 const std::string& profile_id, |
| 316 bool incognito, | 317 bool incognito, |
| 317 std::set<std::string>* notifications) const { | 318 std::set<std::string>* notifications) const { |
| 318 // TODO(miguelg): This can actually be implemented for M+ | 319 DCHECK(notifications); |
| 319 return false; | 320 JNIEnv* env = AttachCurrentThread(); |
| 321 | |
| 322 // Android only supports retrieving existing notifications from M+ | |
| 323 if (base::android::BuildInfo::GetInstance()->sdk_int() < | |
| 324 base::android::SDK_VERSION_MARSHMALLOW) { | |
| 325 return false; | |
| 326 } | |
| 327 | |
| 328 const ScopedJavaLocalRef<jstring> j_profile_id = | |
| 329 ConvertUTF8ToJavaString(env, profile_id); | |
| 330 | |
| 331 ScopedJavaLocalRef<jobjectArray> j_notification_ids = | |
| 332 Java_NotificationPlatformBridge_getNotificationsForProfile( | |
| 333 env, java_object_, j_profile_id); | |
| 334 if (j_notification_ids.obj()) { | |
|
Peter Beverloo
2016/12/06 16:54:13
nit: consider early returning:
if (!j_notificatio
Miguel Garcia
2016/12/14 15:47:32
Actually I return null when there are no notificat
| |
| 335 std::vector<std::string> notification_ids; | |
| 336 base::android::AppendJavaStringArrayToStringVector( | |
| 337 env, j_notification_ids.obj(), ¬ification_ids); | |
| 338 for (auto id : notification_ids) { | |
|
Peter Beverloo
2016/12/06 16:54:13
nit: const auto& id (so that you don't make copies
Peter Beverloo
2016/12/06 16:54:13
nit: no brackets for one-line statements
Miguel Garcia
2016/12/14 15:47:32
Done.
Miguel Garcia
2016/12/14 15:47:32
Done.
| |
| 339 notifications->insert(id); | |
| 340 } | |
| 341 } | |
| 342 | |
| 343 return true; | |
| 320 } | 344 } |
| 321 | 345 |
| 322 // static | 346 // static |
| 323 bool NotificationPlatformBridgeAndroid::RegisterNotificationPlatformBridge( | 347 bool NotificationPlatformBridgeAndroid::RegisterNotificationPlatformBridge( |
| 324 JNIEnv* env) { | 348 JNIEnv* env) { |
| 325 return RegisterNativesImpl(env); | 349 return RegisterNativesImpl(env); |
| 326 } | 350 } |
| 327 | 351 |
| 328 // static | 352 // static |
| 329 void NotificationPlatformBridgeAndroid::RegisterProfilePrefs( | 353 void NotificationPlatformBridgeAndroid::RegisterProfilePrefs( |
| 330 user_prefs::PrefRegistrySyncable* registry) { | 354 user_prefs::PrefRegistrySyncable* registry) { |
| 331 registry->RegisterBooleanPref(prefs::kNotificationsVibrateEnabled, true); | 355 registry->RegisterBooleanPref(prefs::kNotificationsVibrateEnabled, true); |
| 332 } | 356 } |
| 333 | 357 |
| 334 NotificationPlatformBridgeAndroid::RegeneratedNotificationInfo:: | 358 NotificationPlatformBridgeAndroid::RegeneratedNotificationInfo:: |
| 335 RegeneratedNotificationInfo() {} | 359 RegeneratedNotificationInfo() {} |
| 336 | 360 |
| 337 NotificationPlatformBridgeAndroid::RegeneratedNotificationInfo:: | 361 NotificationPlatformBridgeAndroid::RegeneratedNotificationInfo:: |
| 338 RegeneratedNotificationInfo(const std::string& origin, | 362 RegeneratedNotificationInfo(const std::string& origin, |
| 339 const std::string& tag, | 363 const std::string& tag, |
| 340 const std::string& webapk_package) | 364 const std::string& webapk_package) |
| 341 : origin(origin), tag(tag), webapk_package(webapk_package) {} | 365 : origin(origin), tag(tag), webapk_package(webapk_package) {} |
| 342 | 366 |
| 343 NotificationPlatformBridgeAndroid::RegeneratedNotificationInfo:: | 367 NotificationPlatformBridgeAndroid::RegeneratedNotificationInfo:: |
| 344 ~RegeneratedNotificationInfo() {} | 368 ~RegeneratedNotificationInfo() {} |
| OLD | NEW |