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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/offlinepages/OfflinePageBridge.java

Issue 1694863003: Refactor the offline page storage to include client namespace and id. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments. Created 4 years, 10 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 package org.chromium.chrome.browser.offlinepages; 5 package org.chromium.chrome.browser.offlinepages;
6 6
7 import android.os.AsyncTask; 7 import android.os.AsyncTask;
8 8
9 import org.chromium.base.ObserverList; 9 import org.chromium.base.ObserverList;
10 import org.chromium.base.ThreadUtils; 10 import org.chromium.base.ThreadUtils;
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 * Called when the native side of offline pages is changed due to adding , removing or 81 * Called when the native side of offline pages is changed due to adding , removing or
82 * update an offline page. 82 * update an offline page.
83 */ 83 */
84 public void offlinePageModelChanged() {} 84 public void offlinePageModelChanged() {}
85 85
86 /** 86 /**
87 * Called when an offline page is deleted. This can be called as a resul t of 87 * Called when an offline page is deleted. This can be called as a resul t of
88 * #checkOfflinePageMetadata(). 88 * #checkOfflinePageMetadata().
89 * @param bookmarkId A bookmark ID of the deleted offline page. 89 * @param bookmarkId A bookmark ID of the deleted offline page.
90 */ 90 */
91 public void offlinePageDeleted(BookmarkId bookmarkId) {} 91 public void offlinePageDeleted(BookmarkId bookmarkId) {}
fgorski 2016/02/23 17:15:30 I think this is already an offlineId on the C++ si
bburns 2016/02/23 19:25:38 This changes the consumer API, I'd rather change t
92 } 92 }
93 93
94 private static long getTotalSize(List<OfflinePageItem> offlinePages) { 94 private static long getTotalSize(List<OfflinePageItem> offlinePages) {
95 long totalSize = 0; 95 long totalSize = 0;
96 for (OfflinePageItem offlinePage : offlinePages) { 96 for (OfflinePageItem offlinePage : offlinePages) {
97 totalSize += offlinePage.getFileSize(); 97 totalSize += offlinePage.getFileSize();
98 } 98 }
99 return totalSize; 99 return totalSize;
100 } 100 }
101 101
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 * @return Gets all available offline pages. Requires that the model is alre ady loaded. 215 * @return Gets all available offline pages. Requires that the model is alre ady loaded.
216 */ 216 */
217 public List<OfflinePageItem> getAllPages() { 217 public List<OfflinePageItem> getAllPages() {
218 assert mIsNativeOfflinePageModelLoaded; 218 assert mIsNativeOfflinePageModelLoaded;
219 List<OfflinePageItem> result = new ArrayList<OfflinePageItem>(); 219 List<OfflinePageItem> result = new ArrayList<OfflinePageItem>();
220 nativeGetAllPages(mNativeOfflinePageBridge, result); 220 nativeGetAllPages(mNativeOfflinePageBridge, result);
221 return result; 221 return result;
222 } 222 }
223 223
224 /** 224 /**
225 * @return A list of all offline ids that match a particular
226 * (namespace, client_id)
227 */
228 public long[] getOfflineIdsForClientId(String clientIdNamespace, String clie ntId) {
fgorski 2016/02/23 17:15:30 Looking at all the other methods in this class, an
bburns 2016/02/23 19:25:38 Done.
229 assert mIsNativeOfflinePageModelLoaded;
230 return nativeGetOfflineIdsForClientId(mNativeOfflinePageBridge, clientId Namespace,
231 clientId);
232 }
233
234 /**
225 * Gets an offline page associated with a provided bookmark ID. 235 * Gets an offline page associated with a provided bookmark ID.
226 * 236 *
227 * @param bookmarkId Id of the bookmark associated with an offline page. 237 * @param bookmarkId Id of the bookmark associated with an offline page.
228 * @return An {@link OfflinePageItem} matching the bookmark Id or <code>null </code> if none 238 * @return An {@link OfflinePageItem} matching the bookmark Id or <code>null </code> if none
229 * exist. 239 * exist.
230 */ 240 */
231 public OfflinePageItem getPageByBookmarkId(BookmarkId bookmarkId) { 241 public OfflinePageItem getPageByBookmarkId(BookmarkId bookmarkId) {
fgorski 2016/02/23 17:15:30 It bothers me that we are not converting the bookm
bburns 2016/02/23 19:25:38 Ok, I fixed that here.
232 return nativeGetPageByBookmarkId(mNativeOfflinePageBridge, bookmarkId.ge tId()); 242 return nativeGetPageByOfflineId(mNativeOfflinePageBridge, bookmarkId.get Id());
233 } 243 }
234 244
235 /** 245 /**
236 * Gets an offline page associated with a provided online URL. 246 * Gets an offline page associated with a provided online URL.
237 * 247 *
238 * @param onlineURL URL of the page. 248 * @param onlineURL URL of the page.
239 * @return An {@link OfflinePageItem} matching the URL or <code>null</code> if none exist. 249 * @return An {@link OfflinePageItem} matching the URL or <code>null</code> if none exist.
240 */ 250 */
241 public OfflinePageItem getPageByOnlineURL(String onlineURL) { 251 public OfflinePageItem getPageByOnlineURL(String onlineURL) {
242 return nativeGetPageByOnlineURL(mNativeOfflinePageBridge, onlineURL); 252 return nativeGetPageByOnlineURL(mNativeOfflinePageBridge, onlineURL);
(...skipping 26 matching lines...) Expand all
269 // See http://crbug.com/566939 279 // See http://crbug.com/566939
270 if (savePageResult == SavePageResult.SUCCESS && isOfflinePageMod elLoaded()) { 280 if (savePageResult == SavePageResult.SUCCESS && isOfflinePageMod elLoaded()) {
271 long totalPageSizeAfter = getTotalSize(getAllPages()); 281 long totalPageSizeAfter = getTotalSize(getAllPages());
272 recordStorageHistograms(0, totalPageSizeAfter); 282 recordStorageHistograms(0, totalPageSizeAfter);
273 } 283 }
274 callback.onSavePageDone(savePageResult, url); 284 callback.onSavePageDone(savePageResult, url);
275 } 285 }
276 }; 286 };
277 recordFreeSpaceHistograms( 287 recordFreeSpaceHistograms(
278 "OfflinePages.SavePage.FreeSpacePercentage", "OfflinePages.SaveP age.FreeSpaceMB"); 288 "OfflinePages.SavePage.FreeSpacePercentage", "OfflinePages.SaveP age.FreeSpaceMB");
279 nativeSavePage(mNativeOfflinePageBridge, callbackWrapper, webContents, b ookmarkId.getId()); 289 nativeSavePage(mNativeOfflinePageBridge, callbackWrapper, webContents, b ookmarkId.getId(),
290 "bookmark", Long.toString(bookmarkId.getId()));
280 } 291 }
281 292
282 /** 293 /**
283 * Marks that an offline page related to a specified bookmark has been acces sed. 294 * Marks that an offline page related to a specified bookmark has been acces sed.
284 * 295 *
285 * @param bookmarkId Bookmark ID for which the offline copy will be deleted. 296 * @param bookmarkId Bookmark ID for which the offline copy will be deleted.
286 */ 297 */
287 public void markPageAccessed(BookmarkId bookmarkId) { 298 public void markPageAccessed(BookmarkId bookmarkId) {
288 assert mIsNativeOfflinePageModelLoaded; 299 assert mIsNativeOfflinePageModelLoaded;
289 nativeMarkPageAccessed(mNativeOfflinePageBridge, bookmarkId.getId()); 300 nativeMarkPageAccessed(mNativeOfflinePageBridge, bookmarkId.getId());
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 } 411 }
401 412
402 @CalledByNative 413 @CalledByNative
403 private void offlinePageModelChanged() { 414 private void offlinePageModelChanged() {
404 for (OfflinePageModelObserver observer : mObservers) { 415 for (OfflinePageModelObserver observer : mObservers) {
405 observer.offlinePageModelChanged(); 416 observer.offlinePageModelChanged();
406 } 417 }
407 } 418 }
408 419
409 @CalledByNative 420 @CalledByNative
410 private void offlinePageDeleted(long bookmarkId) { 421 private void offlinePageDeleted(long offlineId) {
411 BookmarkId id = new BookmarkId(bookmarkId, BookmarkType.NORMAL); 422 BookmarkId id = new BookmarkId(offlineId, BookmarkType.NORMAL);
412 for (OfflinePageModelObserver observer : mObservers) { 423 for (OfflinePageModelObserver observer : mObservers) {
413 observer.offlinePageDeleted(id); 424 observer.offlinePageDeleted(id);
414 } 425 }
415 } 426 }
416 427
417 @CalledByNative 428 @CalledByNative
418 private static void createOfflinePageAndAddToList(List<OfflinePageItem> offl inePagesList, 429 private static void createOfflinePageAndAddToList(List<OfflinePageItem> offl inePagesList,
419 String url, long bookmarkId, String offlineUrl, long fileSize, long creationTime, 430 String url, long offlineId, String offlineUrl, long fileSize, long c reationTime,
420 int accessCount, long lastAccessTimeMs) { 431 int accessCount, long lastAccessTimeMs) {
421 offlinePagesList.add(createOfflinePageItem( 432 offlinePagesList.add(createOfflinePageItem(
422 url, bookmarkId, offlineUrl, fileSize, creationTime, accessCount , 433 url, offlineId, offlineUrl, fileSize, creationTime, accessCount,
423 lastAccessTimeMs)); 434 lastAccessTimeMs));
424 } 435 }
425 436
426 @CalledByNative 437 @CalledByNative
427 private static OfflinePageItem createOfflinePageItem(String url, long bookma rkId, 438 private static OfflinePageItem createOfflinePageItem(String url, long offlin eId,
428 String offlineUrl, long fileSize, long creationTime, int accessCount , 439 String offlineUrl, long fileSize, long creationTime, int accessCount ,
429 long lastAccessTimeMs) { 440 long lastAccessTimeMs) {
430 return new OfflinePageItem( 441 return new OfflinePageItem(
431 url, bookmarkId, offlineUrl, fileSize, creationTime, accessCount , lastAccessTimeMs); 442 url, offlineId, offlineUrl, fileSize, creationTime, accessCount, lastAccessTimeMs);
432 } 443 }
433 444
434 private static native int nativeGetFeatureMode(); 445 private static native int nativeGetFeatureMode();
435 private static native boolean nativeCanSavePage(String url); 446 private static native boolean nativeCanSavePage(String url);
436 447
437 private native long nativeInit(Profile profile); 448 private native long nativeInit(Profile profile);
438 private native void nativeDestroy(long nativeOfflinePageBridge); 449 private native void nativeDestroy(long nativeOfflinePageBridge);
439 private native void nativeGetAllPages( 450 private native void nativeGetAllPages(
440 long nativeOfflinePageBridge, List<OfflinePageItem> offlinePages); 451 long nativeOfflinePageBridge, List<OfflinePageItem> offlinePages);
441 private native OfflinePageItem nativeGetPageByBookmarkId( 452 private native long[] nativeGetOfflineIdsForClientId(
442 long nativeOfflinePageBridge, long bookmarkId); 453 long nativeOfflinePageBridge, String clientNamespace, String clientI d);
454 private native OfflinePageItem nativeGetPageByOfflineId(
455 long nativeOfflinePageBridge, long offlineId);
443 private native OfflinePageItem nativeGetPageByOnlineURL( 456 private native OfflinePageItem nativeGetPageByOnlineURL(
444 long nativeOfflinePageBridge, String onlineURL); 457 long nativeOfflinePageBridge, String onlineURL);
445 private native void nativeSavePage(long nativeOfflinePageBridge, SavePageCal lback callback, 458 private native void nativeSavePage(long nativeOfflinePageBridge, SavePageCal lback callback,
446 WebContents webContents, long bookmarkId); 459 WebContents webContents, long offlineId, String clientNamespace, Str ing clientId);
447 private native void nativeMarkPageAccessed(long nativeOfflinePageBridge, lon g bookmarkId); 460 private native void nativeMarkPageAccessed(long nativeOfflinePageBridge, lon g offlineId);
448 private native void nativeDeletePage(long nativeOfflinePageBridge, 461 private native void nativeDeletePage(long nativeOfflinePageBridge,
449 DeletePageCallback callback, long bookmarkId); 462 DeletePageCallback callback, long offlineId);
450 private native void nativeDeletePages( 463 private native void nativeDeletePages(
451 long nativeOfflinePageBridge, DeletePageCallback callback, long[] bo okmarkIds); 464 long nativeOfflinePageBridge, DeletePageCallback callback, long[] of flineIds);
452 private native void nativeGetPagesToCleanUp( 465 private native void nativeGetPagesToCleanUp(
453 long nativeOfflinePageBridge, List<OfflinePageItem> offlinePages); 466 long nativeOfflinePageBridge, List<OfflinePageItem> offlinePages);
454 private native void nativeCheckMetadataConsistency(long nativeOfflinePageBri dge); 467 private native void nativeCheckMetadataConsistency(long nativeOfflinePageBri dge);
455 private native String nativeGetOfflineUrlForOnlineUrl( 468 private native String nativeGetOfflineUrlForOnlineUrl(
456 long nativeOfflinePageBridge, String onlineUrl); 469 long nativeOfflinePageBridge, String onlineUrl);
457 private native boolean nativeIsOfflinePageUrl(long nativeOfflinePageBridge, String offlineUrl); 470 private native boolean nativeIsOfflinePageUrl(long nativeOfflinePageBridge, String offlineUrl);
458 } 471 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698