| OLD | NEW |
| 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/evaluation/offline_page_evaluatio
n_bridge.h" | 5 #include "chrome/browser/android/offline_pages/evaluation/offline_page_evaluatio
n_bridge.h" |
| 6 | 6 |
| 7 #include "base/android/callback_android.h" | 7 #include "base/android/callback_android.h" |
| 8 #include "base/android/jni_android.h" | 8 #include "base/android/jni_android.h" |
| 9 #include "base/android/jni_string.h" | 9 #include "base/android/jni_string.h" |
| 10 #include "chrome/browser/android/offline_pages/offline_page_model_factory.h" | 10 #include "chrome/browser/android/offline_pages/offline_page_model_factory.h" |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 void OnPushRequestsDone(const ScopedJavaGlobalRef<jobject>& j_callback_obj, | 69 void OnPushRequestsDone(const ScopedJavaGlobalRef<jobject>& j_callback_obj, |
| 70 bool result) { | 70 bool result) { |
| 71 base::android::RunCallbackAndroid(j_callback_obj, result); | 71 base::android::RunCallbackAndroid(j_callback_obj, result); |
| 72 } | 72 } |
| 73 | 73 |
| 74 } // namespace | 74 } // namespace |
| 75 | 75 |
| 76 static ScopedJavaLocalRef<jobject> GetBridgeForProfile( | 76 static ScopedJavaLocalRef<jobject> GetBridgeForProfile( |
| 77 JNIEnv* env, | 77 JNIEnv* env, |
| 78 const JavaParamRef<jclass>& jcaller, | 78 const JavaParamRef<jclass>& jcaller, |
| 79 const JavaParamRef<jobject>& j_profile) { | 79 const JavaParamRef<jobject>& j_profile, |
| 80 const jboolean j_use_evaluation_scheduler) { |
| 80 Profile* profile = ProfileAndroid::FromProfileAndroid(j_profile); | 81 Profile* profile = ProfileAndroid::FromProfileAndroid(j_profile); |
| 81 | 82 |
| 82 OfflinePageModel* offline_page_model = | 83 OfflinePageModel* offline_page_model = |
| 83 OfflinePageModelFactory::GetForBrowserContext(profile); | 84 OfflinePageModelFactory::GetForBrowserContext(profile); |
| 84 | 85 |
| 85 RequestCoordinator* request_coordinator = | 86 RequestCoordinator* request_coordinator = nullptr; |
| 86 RequestCoordinatorFactory::GetForBrowserContext(profile); | 87 |
| 88 if (j_use_evaluation_scheduler) { |
| 89 request_coordinator = static_cast<RequestCoordinator*>( |
| 90 RequestCoordinatorFactory::GetInstance()->SetTestingFactoryAndUse( |
| 91 profile, &RequestCoordinatorFactory::GetTestingFactory)); |
| 92 } else { |
| 93 request_coordinator = |
| 94 RequestCoordinatorFactory::GetForBrowserContext(profile); |
| 95 } |
| 87 | 96 |
| 88 if (offline_page_model == nullptr || request_coordinator == nullptr) | 97 if (offline_page_model == nullptr || request_coordinator == nullptr) |
| 89 return ScopedJavaLocalRef<jobject>(); | 98 return ScopedJavaLocalRef<jobject>(); |
| 90 | 99 |
| 91 OfflinePageEvaluationBridge* bridge = new OfflinePageEvaluationBridge( | 100 OfflinePageEvaluationBridge* bridge = new OfflinePageEvaluationBridge( |
| 92 env, profile, offline_page_model, request_coordinator); | 101 env, profile, offline_page_model, request_coordinator); |
| 93 | 102 |
| 94 return ScopedJavaLocalRef<jobject>(bridge->java_ref()); | 103 return ScopedJavaLocalRef<jobject>(bridge->java_ref()); |
| 95 } | 104 } |
| 96 | 105 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 DCHECK(j_result_obj); | 174 DCHECK(j_result_obj); |
| 166 DCHECK(j_callback_obj); | 175 DCHECK(j_callback_obj); |
| 167 | 176 |
| 168 ScopedJavaGlobalRef<jobject> j_result_ref(j_result_obj); | 177 ScopedJavaGlobalRef<jobject> j_result_ref(j_result_obj); |
| 169 ScopedJavaGlobalRef<jobject> j_callback_ref(j_callback_obj); | 178 ScopedJavaGlobalRef<jobject> j_callback_ref(j_callback_obj); |
| 170 | 179 |
| 171 offline_page_model_->GetAllPages( | 180 offline_page_model_->GetAllPages( |
| 172 base::Bind(&GetAllPagesCallback, j_result_ref, j_callback_ref)); | 181 base::Bind(&GetAllPagesCallback, j_result_ref, j_callback_ref)); |
| 173 } | 182 } |
| 174 | 183 |
| 175 void OfflinePageEvaluationBridge::PushRequestProcessing( | 184 bool OfflinePageEvaluationBridge::PushRequestProcessing( |
| 176 JNIEnv* env, | 185 JNIEnv* env, |
| 177 const JavaParamRef<jobject>& obj, | 186 const JavaParamRef<jobject>& obj, |
| 178 const JavaParamRef<jobject>& j_callback_obj) { | 187 const JavaParamRef<jobject>& j_callback_obj) { |
| 179 ScopedJavaGlobalRef<jobject> j_callback_ref(j_callback_obj); | 188 ScopedJavaGlobalRef<jobject> j_callback_ref(j_callback_obj); |
| 180 DCHECK(request_coordinator_); | 189 DCHECK(request_coordinator_); |
| 181 base::android::RunCallbackAndroid(j_callback_obj, false); | 190 base::android::RunCallbackAndroid(j_callback_obj, false); |
| 182 | 191 |
| 183 net::NetworkChangeNotifier::ConnectionType connection = | 192 net::NetworkChangeNotifier::ConnectionType connection = |
| 184 net::NetworkChangeNotifier::GetConnectionType(); | 193 net::NetworkChangeNotifier::GetConnectionType(); |
| 185 DeviceConditions device_conditions(false, 0, connection); | 194 DeviceConditions device_conditions(false, 0, connection); |
| 186 request_coordinator_->StartProcessing( | 195 return request_coordinator_->StartProcessing( |
| 187 device_conditions, base::Bind(&OnPushRequestsDone, j_callback_ref)); | 196 device_conditions, base::Bind(&OnPushRequestsDone, j_callback_ref)); |
| 188 } | 197 } |
| 189 | 198 |
| 190 void OfflinePageEvaluationBridge::SavePageLater( | 199 void OfflinePageEvaluationBridge::SavePageLater( |
| 191 JNIEnv* env, | 200 JNIEnv* env, |
| 192 const JavaParamRef<jobject>& obj, | 201 const JavaParamRef<jobject>& obj, |
| 193 const JavaParamRef<jstring>& j_url, | 202 const JavaParamRef<jstring>& j_url, |
| 194 const JavaParamRef<jstring>& j_namespace, | 203 const JavaParamRef<jstring>& j_namespace, |
| 195 const JavaParamRef<jstring>& j_client_id, | 204 const JavaParamRef<jstring>& j_client_id, |
| 196 jboolean user_requested) { | 205 jboolean user_requested) { |
| 197 offline_pages::ClientId client_id; | 206 offline_pages::ClientId client_id; |
| 198 client_id.name_space = ConvertJavaStringToUTF8(env, j_namespace); | 207 client_id.name_space = ConvertJavaStringToUTF8(env, j_namespace); |
| 199 client_id.id = ConvertJavaStringToUTF8(env, j_client_id); | 208 client_id.id = ConvertJavaStringToUTF8(env, j_client_id); |
| 200 | 209 |
| 201 request_coordinator_->SavePageLater( | 210 request_coordinator_->SavePageLater( |
| 202 GURL(ConvertJavaStringToUTF8(env, j_url)), client_id, | 211 GURL(ConvertJavaStringToUTF8(env, j_url)), client_id, |
| 203 static_cast<bool>(user_requested), | 212 static_cast<bool>(user_requested), |
| 204 RequestCoordinator::RequestAvailability::ENABLED_FOR_OFFLINER); | 213 RequestCoordinator::RequestAvailability::ENABLED_FOR_OFFLINER); |
| 205 } | 214 } |
| 206 | 215 |
| 207 void OfflinePageEvaluationBridge::NotifyIfDoneLoading() const { | 216 void OfflinePageEvaluationBridge::NotifyIfDoneLoading() const { |
| 208 if (!offline_page_model_->is_loaded()) | 217 if (!offline_page_model_->is_loaded()) |
| 209 return; | 218 return; |
| 210 JNIEnv* env = base::android::AttachCurrentThread(); | 219 JNIEnv* env = base::android::AttachCurrentThread(); |
| 211 Java_OfflinePageEvaluationBridge_offlinePageModelLoaded(env, java_ref_); | 220 Java_OfflinePageEvaluationBridge_offlinePageModelLoaded(env, java_ref_); |
| 212 } | 221 } |
| 213 | 222 |
| 214 } // namespace android | 223 } // namespace android |
| 215 } // namespace offline_pages | 224 } // namespace offline_pages |
| OLD | NEW |