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 package org.chromium.chrome.browser.offlinepages; | 5 package org.chromium.chrome.browser.offlinepages; |
6 | 6 |
7 import org.chromium.base.Callback; | 7 import org.chromium.base.Callback; |
8 import org.chromium.base.ObserverList; | 8 import org.chromium.base.ObserverList; |
9 import org.chromium.base.ThreadUtils; | 9 import org.chromium.base.ThreadUtils; |
10 import org.chromium.base.VisibleForTesting; | 10 import org.chromium.base.VisibleForTesting; |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 * @param tabId Android tab ID. | 327 * @param tabId Android tab ID. |
328 * @param callback callback to pass back the | 328 * @param callback callback to pass back the |
329 * matching {@link OfflinePageItem} if found. Will pass back null if not. | 329 * matching {@link OfflinePageItem} if found. Will pass back null if not. |
330 */ | 330 */ |
331 public void selectPageForOnlineUrl(String onlineUrl, int tabId, | 331 public void selectPageForOnlineUrl(String onlineUrl, int tabId, |
332 Callback<OfflinePageItem> callback) { | 332 Callback<OfflinePageItem> callback) { |
333 nativeSelectPageForOnlineUrl(mNativeOfflinePageBridge, onlineUrl, tabId,
callback); | 333 nativeSelectPageForOnlineUrl(mNativeOfflinePageBridge, onlineUrl, tabId,
callback); |
334 } | 334 } |
335 | 335 |
336 /** | 336 /** |
337 * Get the offline page associated with the provided offline URL. | |
338 * | |
339 * @param offlineUrl URL pointing to the offline copy of the web page. | |
340 * @param callback callback to pass back the | |
341 * matching {@link OfflinePageItem} if found. Will pass back <code>null</cod
e> if not. | |
342 */ | |
343 public void getPageByOfflineUrl(String offlineUrl, Callback<OfflinePageItem>
callback) { | |
344 nativeGetPageByOfflineUrl(mNativeOfflinePageBridge, offlineUrl, callback
); | |
345 } | |
346 | |
347 /** | |
348 * Get the offline page associated with the provided offline ID. | 337 * Get the offline page associated with the provided offline ID. |
349 * | 338 * |
350 * @param offlineId ID of the offline page. | 339 * @param offlineId ID of the offline page. |
351 * @param callback callback to pass back the | 340 * @param callback callback to pass back the |
352 * matching {@link OfflinePageItem} if found. Will pass back <code>null</cod
e> if not. | 341 * matching {@link OfflinePageItem} if found. Will pass back <code>null</cod
e> if not. |
353 */ | 342 */ |
354 public void getPageByOfflineId(final long offlineId, final Callback<OfflineP
ageItem> callback) { | 343 public void getPageByOfflineId(final long offlineId, final Callback<OfflineP
ageItem> callback) { |
355 runWhenLoaded(new Runnable() { | 344 runWhenLoaded(new Runnable() { |
356 @Override | 345 @Override |
357 public void run() { | 346 public void run() { |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
564 | 553 |
565 @CalledByNative | 554 @CalledByNative |
566 void offlinePageDeleted(long offlineId, ClientId clientId) { | 555 void offlinePageDeleted(long offlineId, ClientId clientId) { |
567 for (OfflinePageModelObserver observer : mObservers) { | 556 for (OfflinePageModelObserver observer : mObservers) { |
568 observer.offlinePageDeleted(offlineId, clientId); | 557 observer.offlinePageDeleted(offlineId, clientId); |
569 } | 558 } |
570 } | 559 } |
571 | 560 |
572 @CalledByNative | 561 @CalledByNative |
573 private static void createOfflinePageAndAddToList(List<OfflinePageItem> offl
inePagesList, | 562 private static void createOfflinePageAndAddToList(List<OfflinePageItem> offl
inePagesList, |
574 String url, long offlineId, String clientNamespace, String clientId,
String offlineUrl, | 563 String url, long offlineId, String clientNamespace, String clientId,
String filePath, |
575 String filePath, long fileSize, long creationTime, int accessCount, | 564 long fileSize, long creationTime, int accessCount, long lastAccessTi
meMs) { |
576 long lastAccessTimeMs) { | |
577 offlinePagesList.add(createOfflinePageItem(url, offlineId, clientNamespa
ce, clientId, | 565 offlinePagesList.add(createOfflinePageItem(url, offlineId, clientNamespa
ce, clientId, |
578 offlineUrl, filePath, fileSize, creationTime, accessCount, lastA
ccessTimeMs)); | 566 filePath, fileSize, creationTime, accessCount, lastAccessTimeMs)
); |
579 } | 567 } |
580 | 568 |
581 @CalledByNative | 569 @CalledByNative |
582 private static OfflinePageItem createOfflinePageItem(String url, long offlin
eId, | 570 private static OfflinePageItem createOfflinePageItem(String url, long offlin
eId, |
583 String clientNamespace, String clientId, String offlineUrl, String f
ilePath, | 571 String clientNamespace, String clientId, String filePath, long fileS
ize, |
584 long fileSize, long creationTime, int accessCount, long lastAccessTi
meMs) { | 572 long creationTime, int accessCount, long lastAccessTimeMs) { |
585 return new OfflinePageItem(url, offlineId, clientNamespace, clientId, of
flineUrl, filePath, | 573 return new OfflinePageItem(url, offlineId, clientNamespace, clientId, fi
lePath, |
586 fileSize, creationTime, accessCount, lastAccessTimeMs); | 574 fileSize, creationTime, accessCount, lastAccessTimeMs); |
587 } | 575 } |
588 | 576 |
589 @CalledByNative | 577 @CalledByNative |
590 private static ClientId createClientId(String clientNamespace, String id) { | 578 private static ClientId createClientId(String clientNamespace, String id) { |
591 return new ClientId(clientNamespace, id); | 579 return new ClientId(clientNamespace, id); |
592 } | 580 } |
593 | 581 |
594 private static native boolean nativeIsOfflinePagesEnabled(); | 582 private static native boolean nativeIsOfflinePagesEnabled(); |
595 private static native boolean nativeIsOfflineBookmarksEnabled(); | 583 private static native boolean nativeIsOfflineBookmarksEnabled(); |
(...skipping 20 matching lines...) Expand all Loading... |
616 | 604 |
617 @VisibleForTesting | 605 @VisibleForTesting |
618 native void nativeRemoveRequestsFromQueue( | 606 native void nativeRemoveRequestsFromQueue( |
619 long nativeOfflinePageBridge, long[] requestIds, RequestsRemovedCall
back callback); | 607 long nativeOfflinePageBridge, long[] requestIds, RequestsRemovedCall
back callback); |
620 | 608 |
621 @VisibleForTesting | 609 @VisibleForTesting |
622 native OfflinePageItem nativeGetPageByOfflineId(long nativeOfflinePageBridge
, long offlineId); | 610 native OfflinePageItem nativeGetPageByOfflineId(long nativeOfflinePageBridge
, long offlineId); |
623 private native void nativeSelectPageForOnlineUrl( | 611 private native void nativeSelectPageForOnlineUrl( |
624 long nativeOfflinePageBridge, String onlineUrl, int tabId, | 612 long nativeOfflinePageBridge, String onlineUrl, int tabId, |
625 Callback<OfflinePageItem> callback); | 613 Callback<OfflinePageItem> callback); |
626 private native void nativeGetPageByOfflineUrl( | |
627 long nativeOfflinePageBridge, String offlineUrl, Callback<OfflinePag
eItem> callback); | |
628 private native void nativeSavePage(long nativeOfflinePageBridge, SavePageCal
lback callback, | 614 private native void nativeSavePage(long nativeOfflinePageBridge, SavePageCal
lback callback, |
629 WebContents webContents, String clientNamespace, String clientId); | 615 WebContents webContents, String clientNamespace, String clientId); |
630 private native void nativeSavePageLater(long nativeOfflinePageBridge, String
url, | 616 private native void nativeSavePageLater(long nativeOfflinePageBridge, String
url, |
631 String clientNamespace, String clientId, boolean userRequested); | 617 String clientNamespace, String clientId, boolean userRequested); |
632 private native void nativeDeletePages( | 618 private native void nativeDeletePages( |
633 long nativeOfflinePageBridge, Callback<Integer> callback, long[] off
lineIds); | 619 long nativeOfflinePageBridge, Callback<Integer> callback, long[] off
lineIds); |
634 private native void nativeCheckMetadataConsistency(long nativeOfflinePageBri
dge); | 620 private native void nativeCheckMetadataConsistency(long nativeOfflinePageBri
dge); |
635 } | 621 } |
OLD | NEW |