Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/offline_page_bridge.h" | 5 #include "chrome/browser/android/offline_pages/offline_page_bridge.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/android/jni_array.h" | 10 #include "base/android/jni_array.h" |
| 11 #include "base/android/jni_string.h" | 11 #include "base/android/jni_string.h" |
| 12 #include "chrome/browser/android/offline_pages/offline_page_mhtml_archiver.h" | 12 #include "chrome/browser/android/offline_pages/offline_page_mhtml_archiver.h" |
| 13 #include "chrome/browser/android/offline_pages/offline_page_model_factory.h" | 13 #include "chrome/browser/android/offline_pages/offline_page_model_factory.h" |
| 14 #include "chrome/browser/android/offline_pages/offline_page_utils.h" | 14 #include "chrome/browser/android/offline_pages/offline_page_utils.h" |
| 15 #include "chrome/browser/android/offline_pages/request_coordinator_factory.h" | |
| 15 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/browser/profiles/profile_android.h" | 17 #include "chrome/browser/profiles/profile_android.h" |
| 18 #include "components/offline_pages/background/request_coordinator.h" | |
| 19 #include "components/offline_pages/background/save_page_request.h" | |
| 17 #include "components/offline_pages/offline_page_feature.h" | 20 #include "components/offline_pages/offline_page_feature.h" |
| 18 #include "components/offline_pages/offline_page_item.h" | 21 #include "components/offline_pages/offline_page_item.h" |
| 19 #include "components/offline_pages/offline_page_model.h" | 22 #include "components/offline_pages/offline_page_model.h" |
| 20 #include "components/offline_pages/proto/offline_pages.pb.h" | 23 #include "components/offline_pages/proto/offline_pages.pb.h" |
| 21 #include "content/public/browser/browser_context.h" | 24 #include "content/public/browser/browser_context.h" |
| 22 #include "content/public/browser/web_contents.h" | 25 #include "content/public/browser/web_contents.h" |
| 23 #include "jni/OfflinePageBridge_jni.h" | 26 #include "jni/OfflinePageBridge_jni.h" |
| 24 #include "net/base/filename_util.h" | 27 #include "net/base/filename_util.h" |
| 25 | 28 |
| 26 using base::android::ConvertJavaStringToUTF8; | 29 using base::android::ConvertJavaStringToUTF8; |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 309 | 312 |
| 310 offline_pages::ClientId client_id; | 313 offline_pages::ClientId client_id; |
| 311 client_id.name_space = ConvertJavaStringToUTF8(env, j_client_id_namespace); | 314 client_id.name_space = ConvertJavaStringToUTF8(env, j_client_id_namespace); |
| 312 client_id.id = ConvertJavaStringToUTF8(env, j_client_id); | 315 client_id.id = ConvertJavaStringToUTF8(env, j_client_id); |
| 313 | 316 |
| 314 offline_page_model_->SavePage( | 317 offline_page_model_->SavePage( |
| 315 url, client_id, std::move(archiver), | 318 url, client_id, std::move(archiver), |
| 316 base::Bind(&SavePageCallback, j_callback_ref, url)); | 319 base::Bind(&SavePageCallback, j_callback_ref, url)); |
| 317 } | 320 } |
| 318 | 321 |
| 322 void OfflinePageBridge::SavePageLater( | |
| 323 JNIEnv* env, | |
| 324 const JavaParamRef<jobject>& obj, | |
| 325 const JavaParamRef<jstring>& j_url, | |
| 326 const JavaParamRef<jstring>& j_client_id_namespace, | |
| 327 const JavaParamRef<jstring>& j_client_id) { | |
| 328 // TODO(petewil): We want a more robust scheme for allocating new IDs. | |
| 329 static int64_t id = 0; | |
| 330 offline_pages::ClientId client_id; | |
| 331 client_id.name_space = ConvertJavaStringToUTF8(env, j_client_id_namespace); | |
| 332 client_id.id = ConvertJavaStringToUTF8(env, j_client_id); | |
| 333 | |
| 334 offline_pages::SavePageRequest request( | |
|
fgorski
2016/05/06 07:03:09
Pete, use the same signature as for SavePage:
url
Pete Williamson
2016/05/06 18:28:13
Done. I had been following the interface spec tha
| |
| 335 id++, | |
| 336 GURL(ConvertJavaStringToUTF8(env, j_url)), | |
| 337 client_id, | |
| 338 base::Time::Now()); | |
| 339 | |
| 340 // Get a background request coordinator. | |
| 341 RequestCoordinator* coordinator = | |
| 342 offline_pages::RequestCoordinatorFactory::GetInstance()-> | |
| 343 GetForBrowserContext(browser_context_); | |
| 344 | |
| 345 // Make a request to the background offliner. | |
| 346 coordinator->SavePageLater(request); | |
| 347 } | |
| 348 | |
| 319 void OfflinePageBridge::DeletePages( | 349 void OfflinePageBridge::DeletePages( |
| 320 JNIEnv* env, | 350 JNIEnv* env, |
| 321 const JavaParamRef<jobject>& obj, | 351 const JavaParamRef<jobject>& obj, |
| 322 const JavaParamRef<jobject>& j_callback_obj, | 352 const JavaParamRef<jobject>& j_callback_obj, |
| 323 const JavaParamRef<jlongArray>& offline_ids_array) { | 353 const JavaParamRef<jlongArray>& offline_ids_array) { |
| 324 DCHECK(j_callback_obj); | 354 DCHECK(j_callback_obj); |
| 325 | 355 |
| 326 ScopedJavaGlobalRef<jobject> j_callback_ref; | 356 ScopedJavaGlobalRef<jobject> j_callback_ref; |
| 327 j_callback_ref.Reset(env, j_callback_obj); | 357 j_callback_ref.Reset(env, j_callback_obj); |
| 328 | 358 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 378 ConvertUTF8ToJavaString(env, client_id.name_space).obj(), | 408 ConvertUTF8ToJavaString(env, client_id.name_space).obj(), |
| 379 ConvertUTF8ToJavaString(env, client_id.id).obj()); | 409 ConvertUTF8ToJavaString(env, client_id.id).obj()); |
| 380 } | 410 } |
| 381 | 411 |
| 382 bool RegisterOfflinePageBridge(JNIEnv* env) { | 412 bool RegisterOfflinePageBridge(JNIEnv* env) { |
| 383 return RegisterNativesImpl(env); | 413 return RegisterNativesImpl(env); |
| 384 } | 414 } |
| 385 | 415 |
| 386 } // namespace android | 416 } // namespace android |
| 387 } // namespace offline_pages | 417 } // namespace offline_pages |
| OLD | NEW |