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

Side by Side Diff: chrome/browser/android/ntp/content_suggestions_notification_helper.cc

Issue 2616893003: Hide notifications after their deadline (Closed)
Patch Set: import annotation Created 3 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/android/ntp/content_suggestions_notification_helper.h" 5 #include "chrome/browser/android/ntp/content_suggestions_notification_helper.h"
6 6
7 #include <limits>
8
7 #include "base/android/jni_android.h" 9 #include "base/android/jni_android.h"
8 #include "base/android/jni_string.h" 10 #include "base/android/jni_string.h"
9 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
10 #include "jni/ContentSuggestionsNotificationHelper_jni.h" 12 #include "jni/ContentSuggestionsNotificationHelper_jni.h"
11 #include "ui/gfx/android/java_bitmap.h" 13 #include "ui/gfx/android/java_bitmap.h"
12 #include "ui/gfx/image/image.h" 14 #include "ui/gfx/image/image.h"
13 #include "ui/gfx/image/image_skia.h" 15 #include "ui/gfx/image/image_skia.h"
14 16
15 namespace ntp_snippets { 17 namespace ntp_snippets {
16 18
17 void ContentSuggestionsNotificationHelper::OpenURL(const GURL& url) { 19 void ContentSuggestionsNotificationHelper::OpenURL(const GURL& url) {
18 JNIEnv* env = base::android::AttachCurrentThread(); 20 JNIEnv* env = base::android::AttachCurrentThread();
19 Java_ContentSuggestionsNotificationHelper_openUrl( 21 Java_ContentSuggestionsNotificationHelper_openUrl(
20 env, base::android::ConvertUTF8ToJavaString(env, url.spec())); 22 env, base::android::ConvertUTF8ToJavaString(env, url.spec()));
21 } 23 }
22 24
23 void ContentSuggestionsNotificationHelper::SendNotification( 25 void ContentSuggestionsNotificationHelper::SendNotification(
24 const GURL& url, 26 const GURL& url,
25 const base::string16& title, 27 const base::string16& title,
26 const base::string16& text, 28 const base::string16& text,
27 const gfx::Image& image) { 29 const gfx::Image& image,
30 base::Time timeout_at) {
28 JNIEnv* env = base::android::AttachCurrentThread(); 31 JNIEnv* env = base::android::AttachCurrentThread();
29 SkBitmap skimage = image.AsImageSkia().GetRepresentation(1.0f).sk_bitmap(); 32 SkBitmap skimage = image.AsImageSkia().GetRepresentation(1.0f).sk_bitmap();
30 if (skimage.empty()) 33 if (skimage.empty())
31 return; 34 return;
32 35
36 jint timeout_at_millis = timeout_at.ToJavaTime();
37 if (timeout_at == base::Time::Max()) {
38 timeout_at_millis = std::numeric_limits<jint>::max();
39 }
40
33 Java_ContentSuggestionsNotificationHelper_showNotification( 41 Java_ContentSuggestionsNotificationHelper_showNotification(
34 env, base::android::ConvertUTF8ToJavaString(env, url.spec()), 42 env, base::android::ConvertUTF8ToJavaString(env, url.spec()),
35 base::android::ConvertUTF16ToJavaString(env, title), 43 base::android::ConvertUTF16ToJavaString(env, title),
36 base::android::ConvertUTF16ToJavaString(env, text), 44 base::android::ConvertUTF16ToJavaString(env, text),
37 gfx::ConvertToJavaBitmap(&skimage)); 45 gfx::ConvertToJavaBitmap(&skimage), timeout_at_millis);
38 } 46 }
39 47
40 void ContentSuggestionsNotificationHelper::HideNotification() { 48 void ContentSuggestionsNotificationHelper::HideAllNotifications() {
41 JNIEnv* env = base::android::AttachCurrentThread(); 49 JNIEnv* env = base::android::AttachCurrentThread();
42 Java_ContentSuggestionsNotificationHelper_hideNotification(env); 50 Java_ContentSuggestionsNotificationHelper_hideAllNotifications(env);
43 } 51 }
44 52
45 } // namespace ntp_snippets 53 } // namespace ntp_snippets
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698