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

Side by Side Diff: chrome/browser/android/offline_pages/downloads/offline_page_notification_bridge.cc

Issue 2772343003: Android: Remove GetApplicationContext part 1 (Closed)
Patch Set: Created 3 years, 9 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/offline_pages/downloads/offline_page_notificati on_bridge.h" 5 #include "chrome/browser/android/offline_pages/downloads/offline_page_notificati on_bridge.h"
6 6
7 #include "base/android/context_utils.h" 7 #include "base/android/context_utils.h"
8 #include "base/android/jni_string.h" 8 #include "base/android/jni_string.h"
9 #include "chrome/browser/android/offline_pages/downloads/offline_page_download_b ridge.h" 9 #include "chrome/browser/android/offline_pages/downloads/offline_page_download_b ridge.h"
10 #include "jni/OfflinePageNotificationBridge_jni.h" 10 #include "jni/OfflinePageNotificationBridge_jni.h"
11 11
12 using base::android::AttachCurrentThread; 12 using base::android::AttachCurrentThread;
13 using base::android::ConvertUTF16ToJavaString; 13 using base::android::ConvertUTF16ToJavaString;
14 using base::android::ConvertUTF8ToJavaString; 14 using base::android::ConvertUTF8ToJavaString;
15 using base::android::GetApplicationContext;
16 15
17 namespace { 16 namespace {
18 17
19 base::android::ScopedJavaLocalRef<jstring> GetDisplayName( 18 base::android::ScopedJavaLocalRef<jstring> GetDisplayName(
20 const offline_pages::DownloadUIItem& item) { 19 const offline_pages::DownloadUIItem& item) {
21 JNIEnv* env = AttachCurrentThread(); 20 JNIEnv* env = AttachCurrentThread();
22 if (!item.title.empty()) 21 if (!item.title.empty())
23 return ConvertUTF16ToJavaString(env, item.title); 22 return ConvertUTF16ToJavaString(env, item.title);
24 23
25 std::string host = item.url.host(); 24 std::string host = item.url.host();
26 if (!host.empty()) 25 if (!host.empty())
27 return ConvertUTF8ToJavaString(env, host); 26 return ConvertUTF8ToJavaString(env, host);
28 27
29 return ConvertUTF8ToJavaString(env, item.url.spec()); 28 return ConvertUTF8ToJavaString(env, item.url.spec());
30 } 29 }
31 30
32 } // namespace 31 } // namespace
33 32
34 namespace offline_pages { 33 namespace offline_pages {
35 namespace android { 34 namespace android {
36 35
37 void OfflinePageNotificationBridge::NotifyDownloadSuccessful( 36 void OfflinePageNotificationBridge::NotifyDownloadSuccessful(
38 const DownloadUIItem& item) { 37 const DownloadUIItem& item) {
39 JNIEnv* env = AttachCurrentThread(); 38 JNIEnv* env = AttachCurrentThread();
40 Java_OfflinePageNotificationBridge_notifyDownloadSuccessful( 39 Java_OfflinePageNotificationBridge_notifyDownloadSuccessful(
41 env, GetApplicationContext(), ConvertUTF8ToJavaString(env, item.guid), 40 env, ConvertUTF8ToJavaString(env, item.guid),
42 ConvertUTF8ToJavaString(env, item.url.spec()), GetDisplayName(item)); 41 ConvertUTF8ToJavaString(env, item.url.spec()), GetDisplayName(item));
43 } 42 }
44 43
45 void OfflinePageNotificationBridge::NotifyDownloadFailed( 44 void OfflinePageNotificationBridge::NotifyDownloadFailed(
46 const DownloadUIItem& item) { 45 const DownloadUIItem& item) {
47 JNIEnv* env = AttachCurrentThread(); 46 JNIEnv* env = AttachCurrentThread();
48 Java_OfflinePageNotificationBridge_notifyDownloadFailed( 47 Java_OfflinePageNotificationBridge_notifyDownloadFailed(
49 env, GetApplicationContext(), ConvertUTF8ToJavaString(env, item.guid), 48 env, ConvertUTF8ToJavaString(env, item.guid),
50 ConvertUTF8ToJavaString(env, item.url.spec()), GetDisplayName(item)); 49 ConvertUTF8ToJavaString(env, item.url.spec()), GetDisplayName(item));
51 } 50 }
52 51
53 void OfflinePageNotificationBridge::NotifyDownloadProgress( 52 void OfflinePageNotificationBridge::NotifyDownloadProgress(
54 const DownloadUIItem& item) { 53 const DownloadUIItem& item) {
55 JNIEnv* env = AttachCurrentThread(); 54 JNIEnv* env = AttachCurrentThread();
56 Java_OfflinePageNotificationBridge_notifyDownloadProgress( 55 Java_OfflinePageNotificationBridge_notifyDownloadProgress(
57 env, GetApplicationContext(), ConvertUTF8ToJavaString(env, item.guid), 56 env, ConvertUTF8ToJavaString(env, item.guid),
58 ConvertUTF8ToJavaString(env, item.url.spec()), 57 ConvertUTF8ToJavaString(env, item.url.spec()),
59 item.start_time.ToJavaTime(), item.download_progress_bytes, 58 item.start_time.ToJavaTime(), item.download_progress_bytes,
60 GetDisplayName(item)); 59 GetDisplayName(item));
61 } 60 }
62 61
63 void OfflinePageNotificationBridge::NotifyDownloadPaused( 62 void OfflinePageNotificationBridge::NotifyDownloadPaused(
64 const DownloadUIItem& item) { 63 const DownloadUIItem& item) {
65 JNIEnv* env = AttachCurrentThread(); 64 JNIEnv* env = AttachCurrentThread();
66 Java_OfflinePageNotificationBridge_notifyDownloadPaused( 65 Java_OfflinePageNotificationBridge_notifyDownloadPaused(
67 env, GetApplicationContext(), ConvertUTF8ToJavaString(env, item.guid), 66 env, ConvertUTF8ToJavaString(env, item.guid), GetDisplayName(item));
68 GetDisplayName(item));
69 } 67 }
70 68
71 void OfflinePageNotificationBridge::NotifyDownloadInterrupted( 69 void OfflinePageNotificationBridge::NotifyDownloadInterrupted(
72 const DownloadUIItem& item) { 70 const DownloadUIItem& item) {
73 JNIEnv* env = AttachCurrentThread(); 71 JNIEnv* env = AttachCurrentThread();
74 Java_OfflinePageNotificationBridge_notifyDownloadInterrupted( 72 Java_OfflinePageNotificationBridge_notifyDownloadInterrupted(
75 env, GetApplicationContext(), ConvertUTF8ToJavaString(env, item.guid), 73 env, ConvertUTF8ToJavaString(env, item.guid), GetDisplayName(item));
76 GetDisplayName(item));
77 } 74 }
78 75
79 void OfflinePageNotificationBridge::NotifyDownloadCanceled( 76 void OfflinePageNotificationBridge::NotifyDownloadCanceled(
80 const DownloadUIItem& item) { 77 const DownloadUIItem& item) {
81 JNIEnv* env = AttachCurrentThread(); 78 JNIEnv* env = AttachCurrentThread();
82 Java_OfflinePageNotificationBridge_notifyDownloadCanceled( 79 Java_OfflinePageNotificationBridge_notifyDownloadCanceled(
83 env, GetApplicationContext(), ConvertUTF8ToJavaString(env, item.guid)); 80 env, ConvertUTF8ToJavaString(env, item.guid));
84 } 81 }
85 82
86 void OfflinePageNotificationBridge::ShowDownloadingToast() { 83 void OfflinePageNotificationBridge::ShowDownloadingToast() {
87 JNIEnv* env = AttachCurrentThread(); 84 JNIEnv* env = AttachCurrentThread();
88 Java_OfflinePageNotificationBridge_showDownloadingToast( 85 Java_OfflinePageNotificationBridge_showDownloadingToast(env);
89 env, GetApplicationContext());
90 } 86 }
91 87
92 } // namespace android 88 } // namespace android
93 } // namespace offline_pages 89 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698