| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "components/offline_items_collection/core/android/offline_content_aggre
gator_bridge.h" | 5 #include "components/offline_items_collection/core/android/offline_content_aggre
gator_bridge.h" |
| 6 | 6 |
| 7 #include "base/android/jni_string.h" | 7 #include "base/android/jni_string.h" |
| 8 #include "base/bind.h" |
| 8 #include "components/offline_items_collection/core/android/offline_item_bridge.h
" | 9 #include "components/offline_items_collection/core/android/offline_item_bridge.h
" |
| 10 #include "components/offline_items_collection/core/android/offline_item_visuals_
bridge.h" |
| 9 #include "components/offline_items_collection/core/offline_item.h" | 11 #include "components/offline_items_collection/core/offline_item.h" |
| 10 #include "jni/OfflineContentAggregatorBridge_jni.h" | 12 #include "jni/OfflineContentAggregatorBridge_jni.h" |
| 11 | 13 |
| 12 using base::android::AttachCurrentThread; | 14 using base::android::AttachCurrentThread; |
| 13 using base::android::ConvertJavaStringToUTF8; | 15 using base::android::ConvertJavaStringToUTF8; |
| 14 using base::android::ConvertUTF8ToJavaString; | 16 using base::android::ConvertUTF8ToJavaString; |
| 15 using base::android::JavaParamRef; | 17 using base::android::JavaParamRef; |
| 16 using base::android::ScopedJavaLocalRef; | 18 using base::android::ScopedJavaLocalRef; |
| 19 using base::android::ScopedJavaGlobalRef; |
| 17 | 20 |
| 18 namespace offline_items_collection { | 21 namespace offline_items_collection { |
| 19 namespace android { | 22 namespace android { |
| 20 | 23 |
| 21 namespace { | 24 namespace { |
| 22 const char kOfflineContentAggregatorBridgeUserDataKey[] = "aggregator_bridge"; | 25 const char kOfflineContentAggregatorBridgeUserDataKey[] = "aggregator_bridge"; |
| 23 | 26 |
| 24 ContentId CreateContentId(JNIEnv* env, | 27 ContentId CreateContentId(JNIEnv* env, |
| 25 const JavaParamRef<jstring>& j_namespace, | 28 const JavaParamRef<jstring>& j_namespace, |
| 26 const JavaParamRef<jstring>& j_id) { | 29 const JavaParamRef<jstring>& j_id) { |
| 27 return ContentId(ConvertJavaStringToUTF8(env, j_namespace), | 30 return ContentId(ConvertJavaStringToUTF8(env, j_namespace), |
| 28 ConvertJavaStringToUTF8(env, j_id)); | 31 ConvertJavaStringToUTF8(env, j_id)); |
| 29 } | 32 } |
| 30 | 33 |
| 34 void GetVisualsForItemHelperCallback(ScopedJavaGlobalRef<jobject> j_callback, |
| 35 const ContentId& id, |
| 36 const OfflineItemVisuals* visuals) { |
| 37 JNIEnv* env = AttachCurrentThread(); |
| 38 Java_OfflineContentAggregatorBridge_onVisualsAvailable( |
| 39 env, j_callback.obj(), ConvertUTF8ToJavaString(env, id.name_space), |
| 40 ConvertUTF8ToJavaString(env, id.id), |
| 41 OfflineItemVisualsBridge::CreateOfflineItemVisuals(env, visuals)); |
| 42 } |
| 43 |
| 31 } // namespace | 44 } // namespace |
| 32 | 45 |
| 33 // static. | 46 // static. |
| 34 bool OfflineContentAggregatorBridge::Register(JNIEnv* env) { | 47 bool OfflineContentAggregatorBridge::Register(JNIEnv* env) { |
| 35 return RegisterNativesImpl(env); | 48 return RegisterNativesImpl(env); |
| 36 } | 49 } |
| 37 | 50 |
| 38 // static | 51 // static |
| 39 base::android::ScopedJavaLocalRef<jobject> | 52 base::android::ScopedJavaLocalRef<jobject> |
| 40 OfflineContentAggregatorBridge::GetBridgeForOfflineContentAggregator( | 53 OfflineContentAggregatorBridge::GetBridgeForOfflineContentAggregator( |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 return OfflineItemBridge::CreateOfflineItem(env, item); | 139 return OfflineItemBridge::CreateOfflineItem(env, item); |
| 127 } | 140 } |
| 128 | 141 |
| 129 ScopedJavaLocalRef<jobject> OfflineContentAggregatorBridge::GetAllItems( | 142 ScopedJavaLocalRef<jobject> OfflineContentAggregatorBridge::GetAllItems( |
| 130 JNIEnv* env, | 143 JNIEnv* env, |
| 131 const JavaParamRef<jobject>& jobj) { | 144 const JavaParamRef<jobject>& jobj) { |
| 132 return OfflineItemBridge::CreateOfflineItemList(env, | 145 return OfflineItemBridge::CreateOfflineItemList(env, |
| 133 aggregator_->GetAllItems()); | 146 aggregator_->GetAllItems()); |
| 134 } | 147 } |
| 135 | 148 |
| 149 void OfflineContentAggregatorBridge::GetVisualsForItem( |
| 150 JNIEnv* env, |
| 151 const JavaParamRef<jobject>& jobj, |
| 152 const JavaParamRef<jstring>& j_namespace, |
| 153 const JavaParamRef<jstring>& j_id, |
| 154 const JavaParamRef<jobject>& j_callback) { |
| 155 aggregator_->GetVisualsForItem( |
| 156 CreateContentId(env, j_namespace, j_id), |
| 157 base::Bind(&GetVisualsForItemHelperCallback, |
| 158 ScopedJavaGlobalRef<jobject>(env, j_callback))); |
| 159 } |
| 160 |
| 136 void OfflineContentAggregatorBridge::OnItemsAvailable( | 161 void OfflineContentAggregatorBridge::OnItemsAvailable( |
| 137 OfflineContentProvider* provider) { | 162 OfflineContentProvider* provider) { |
| 138 if (java_ref_.is_null()) | 163 if (java_ref_.is_null()) |
| 139 return; | 164 return; |
| 140 | 165 |
| 141 JNIEnv* env = AttachCurrentThread(); | 166 JNIEnv* env = AttachCurrentThread(); |
| 142 Java_OfflineContentAggregatorBridge_onItemsAvailable(env, java_ref_.obj()); | 167 Java_OfflineContentAggregatorBridge_onItemsAvailable(env, java_ref_.obj()); |
| 143 } | 168 } |
| 144 | 169 |
| 145 void OfflineContentAggregatorBridge::OnItemsAdded( | 170 void OfflineContentAggregatorBridge::OnItemsAdded( |
| (...skipping 21 matching lines...) Expand all Loading... |
| 167 if (java_ref_.is_null()) | 192 if (java_ref_.is_null()) |
| 168 return; | 193 return; |
| 169 | 194 |
| 170 JNIEnv* env = AttachCurrentThread(); | 195 JNIEnv* env = AttachCurrentThread(); |
| 171 Java_OfflineContentAggregatorBridge_onItemUpdated( | 196 Java_OfflineContentAggregatorBridge_onItemUpdated( |
| 172 env, java_ref_.obj(), OfflineItemBridge::CreateOfflineItem(env, &item)); | 197 env, java_ref_.obj(), OfflineItemBridge::CreateOfflineItem(env, &item)); |
| 173 } | 198 } |
| 174 | 199 |
| 175 } // namespace android | 200 } // namespace android |
| 176 } // namespace offline_items_collection | 201 } // namespace offline_items_collection |
| OLD | NEW |