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

Side by Side Diff: chrome/browser/android/offline_pages/offline_page_bridge.cc

Issue 1956633002: Menu hook plumbed through to RequestCoordinator. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove reference to unit test which I forgot to include Created 4 years, 7 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 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 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 ScopedJavaGlobalRef<jobject> j_callback_ref; 235 ScopedJavaGlobalRef<jobject> j_callback_ref;
233 j_callback_ref.Reset(env, j_callback_obj); 236 j_callback_ref.Reset(env, j_callback_obj);
234 237
235 offline_page_model_->GetAllPages( 238 offline_page_model_->GetAllPages(
236 base::Bind(&GetAllPagesCallback, j_result_ref, j_callback_ref)); 239 base::Bind(&GetAllPagesCallback, j_result_ref, j_callback_ref));
237 } 240 }
238 241
239 ScopedJavaLocalRef<jlongArray> OfflinePageBridge::GetOfflineIdsForClientId( 242 ScopedJavaLocalRef<jlongArray> OfflinePageBridge::GetOfflineIdsForClientId(
240 JNIEnv* env, 243 JNIEnv* env,
241 const JavaParamRef<jobject>& obj, 244 const JavaParamRef<jobject>& obj,
242 const JavaParamRef<jstring>& j_client_id_namespace, 245 const JavaParamRef<jstring>& j_namespace,
243 const JavaParamRef<jstring>& j_client_id) { 246 const JavaParamRef<jstring>& j_client_id) {
244 DCHECK(offline_page_model_->is_loaded()); 247 DCHECK(offline_page_model_->is_loaded());
245 offline_pages::ClientId client_id; 248 offline_pages::ClientId client_id;
246 client_id.name_space = ConvertJavaStringToUTF8(env, j_client_id_namespace); 249 client_id.name_space = ConvertJavaStringToUTF8(env, j_namespace);
247 client_id.id = ConvertJavaStringToUTF8(env, j_client_id); 250 client_id.id = ConvertJavaStringToUTF8(env, j_client_id);
248 251
249 std::vector<int64_t> results = 252 std::vector<int64_t> results =
250 offline_page_model_->MaybeGetOfflineIdsForClientId(client_id); 253 offline_page_model_->MaybeGetOfflineIdsForClientId(client_id);
251 254
252 return base::android::ToJavaLongArray(env, results); 255 return base::android::ToJavaLongArray(env, results);
253 } 256 }
254 257
255 ScopedJavaLocalRef<jobject> OfflinePageBridge::GetPageByOfflineId( 258 ScopedJavaLocalRef<jobject> OfflinePageBridge::GetPageByOfflineId(
256 JNIEnv* env, 259 JNIEnv* env,
(...skipping 28 matching lines...) Expand all
285 if (!offline_page) 288 if (!offline_page)
286 return ScopedJavaLocalRef<jobject>(); 289 return ScopedJavaLocalRef<jobject>();
287 return CreateOfflinePageItem(env, *offline_page); 290 return CreateOfflinePageItem(env, *offline_page);
288 } 291 }
289 292
290 void OfflinePageBridge::SavePage( 293 void OfflinePageBridge::SavePage(
291 JNIEnv* env, 294 JNIEnv* env,
292 const JavaParamRef<jobject>& obj, 295 const JavaParamRef<jobject>& obj,
293 const JavaParamRef<jobject>& j_callback_obj, 296 const JavaParamRef<jobject>& j_callback_obj,
294 const JavaParamRef<jobject>& j_web_contents, 297 const JavaParamRef<jobject>& j_web_contents,
295 const JavaParamRef<jstring>& j_client_id_namespace, 298 const JavaParamRef<jstring>& j_namespace,
296 const JavaParamRef<jstring>& j_client_id) { 299 const JavaParamRef<jstring>& j_client_id) {
297 DCHECK(j_callback_obj); 300 DCHECK(j_callback_obj);
298 DCHECK(j_web_contents); 301 DCHECK(j_web_contents);
299 302
300 ScopedJavaGlobalRef<jobject> j_callback_ref; 303 ScopedJavaGlobalRef<jobject> j_callback_ref;
301 j_callback_ref.Reset(env, j_callback_obj); 304 j_callback_ref.Reset(env, j_callback_obj);
302 305
303 content::WebContents* web_contents = 306 content::WebContents* web_contents =
304 content::WebContents::FromJavaWebContents(j_web_contents); 307 content::WebContents::FromJavaWebContents(j_web_contents);
305 GURL url(web_contents->GetLastCommittedURL()); 308 GURL url(web_contents->GetLastCommittedURL());
306 309
307 std::unique_ptr<OfflinePageArchiver> archiver( 310 std::unique_ptr<OfflinePageArchiver> archiver(
308 new OfflinePageMHTMLArchiver(web_contents)); 311 new OfflinePageMHTMLArchiver(web_contents));
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_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_namespace,
327 const JavaParamRef<jstring>& j_client_id) {
328 offline_pages::ClientId client_id;
329 client_id.name_space = ConvertJavaStringToUTF8(env, j_namespace);
330 client_id.id = ConvertJavaStringToUTF8(env, j_client_id);
331
332 RequestCoordinator* coordinator =
333 offline_pages::RequestCoordinatorFactory::GetInstance()->
334 GetForBrowserContext(browser_context_);
335
336 coordinator->SavePageLater(
337 GURL(ConvertJavaStringToUTF8(env, j_url)), client_id);
338 }
339
319 void OfflinePageBridge::DeletePages( 340 void OfflinePageBridge::DeletePages(
320 JNIEnv* env, 341 JNIEnv* env,
321 const JavaParamRef<jobject>& obj, 342 const JavaParamRef<jobject>& obj,
322 const JavaParamRef<jobject>& j_callback_obj, 343 const JavaParamRef<jobject>& j_callback_obj,
323 const JavaParamRef<jlongArray>& offline_ids_array) { 344 const JavaParamRef<jlongArray>& offline_ids_array) {
324 DCHECK(j_callback_obj); 345 DCHECK(j_callback_obj);
325 346
326 ScopedJavaGlobalRef<jobject> j_callback_ref; 347 ScopedJavaGlobalRef<jobject> j_callback_ref;
327 j_callback_ref.Reset(env, j_callback_obj); 348 j_callback_ref.Reset(env, j_callback_obj);
328 349
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 ConvertUTF8ToJavaString(env, client_id.name_space).obj(), 399 ConvertUTF8ToJavaString(env, client_id.name_space).obj(),
379 ConvertUTF8ToJavaString(env, client_id.id).obj()); 400 ConvertUTF8ToJavaString(env, client_id.id).obj());
380 } 401 }
381 402
382 bool RegisterOfflinePageBridge(JNIEnv* env) { 403 bool RegisterOfflinePageBridge(JNIEnv* env) {
383 return RegisterNativesImpl(env); 404 return RegisterNativesImpl(env);
384 } 405 }
385 406
386 } // namespace android 407 } // namespace android
387 } // namespace offline_pages 408 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698