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

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

Issue 1772233003: Flag for Background Loading of Offline Pages. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Put @VisibleForTesting in the right place. Created 4 years, 9 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
« no previous file with comments | « no previous file | chrome/android/javatests/src/org/chromium/chrome/browser/offlinepages/OfflinePageBridgeTest.java » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
11 import org.chromium.base.VisibleForTesting;
11 import org.chromium.base.annotations.CalledByNative; 12 import org.chromium.base.annotations.CalledByNative;
12 import org.chromium.base.annotations.JNINamespace; 13 import org.chromium.base.annotations.JNINamespace;
13 import org.chromium.base.metrics.RecordHistogram; 14 import org.chromium.base.metrics.RecordHistogram;
15 import org.chromium.chrome.browser.ChromeFeatureList;
14 import org.chromium.chrome.browser.profiles.Profile; 16 import org.chromium.chrome.browser.profiles.Profile;
15 import org.chromium.components.offlinepages.DeletePageResult; 17 import org.chromium.components.offlinepages.DeletePageResult;
16 import org.chromium.components.offlinepages.FeatureMode; 18 import org.chromium.components.offlinepages.FeatureMode;
17 import org.chromium.components.offlinepages.SavePageResult; 19 import org.chromium.components.offlinepages.SavePageResult;
18 import org.chromium.content_public.browser.WebContents; 20 import org.chromium.content_public.browser.WebContents;
19 21
20 import java.util.ArrayList; 22 import java.util.ArrayList;
21 import java.util.HashSet; 23 import java.util.HashSet;
22 import java.util.List; 24 import java.util.List;
23 import java.util.Set; 25 import java.util.Set;
24 26
25 /** 27 /**
26 * Access gate to C++ side offline pages functionalities. 28 * Access gate to C++ side offline pages functionalities.
27 */ 29 */
28 @JNINamespace("offline_pages::android") 30 @JNINamespace("offline_pages::android")
29 public class OfflinePageBridge { 31 public class OfflinePageBridge {
30 public static final String BOOKMARK_NAMESPACE = "bookmark"; 32 public static final String BOOKMARK_NAMESPACE = "bookmark";
31 public static final long INVALID_OFFLINE_ID = 0; 33 public static final long INVALID_OFFLINE_ID = 0;
34 private static final String OFFLINE_PAGES_BACKGROUND_LOADING_FEATURE_NAME =
35 "offline-pages-background-loading";
32 36
33 /** 37 /**
34 * Retrieves the OfflinePageBridge for the given profile, creating it the fi rst time 38 * Retrieves the OfflinePageBridge for the given profile, creating it the fi rst time
35 * getForProfile is called for a given profile. Must be called on the UI th read. 39 * getForProfile is called for a given profile. Must be called on the UI th read.
36 * 40 *
37 * @param profile The profile associated with the OfflinePageBridge to get. 41 * @param profile The profile associated with the OfflinePageBridge to get.
38 */ 42 */
39 public static OfflinePageBridge getForProfile(Profile profile) { 43 public static OfflinePageBridge getForProfile(Profile profile) {
40 ThreadUtils.assertOnUiThread(); 44 ThreadUtils.assertOnUiThread();
41 45
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 /** 186 /**
183 * @return True if the offline pages feature is enabled, regardless whether bookmark or saved 187 * @return True if the offline pages feature is enabled, regardless whether bookmark or saved
184 * page shown in UI strings. 188 * page shown in UI strings.
185 */ 189 */
186 public static boolean isEnabled() { 190 public static boolean isEnabled() {
187 ThreadUtils.assertOnUiThread(); 191 ThreadUtils.assertOnUiThread();
188 return getFeatureMode() != FeatureMode.DISABLED; 192 return getFeatureMode() != FeatureMode.DISABLED;
189 } 193 }
190 194
191 /** 195 /**
196 * @return True if the offline pages feature is enabled, regardless whether bookmark or saved
197 * page shown in UI strings.
198 */
199 @VisibleForTesting
200 public static boolean isBackgroundLoadingEnabled() {
201 return ChromeFeatureList.isEnabled(OFFLINE_PAGES_BACKGROUND_LOADING_FEAT URE_NAME);
202 }
203
204 /**
192 * @return True if an offline copy of the given URL can be saved. 205 * @return True if an offline copy of the given URL can be saved.
193 */ 206 */
194 public static boolean canSavePage(String url) { 207 public static boolean canSavePage(String url) {
195 return nativeCanSavePage(url); 208 return nativeCanSavePage(url);
196 } 209 }
197 210
198 /** 211 /**
199 * Adds an observer to offline page model changes. 212 * Adds an observer to offline page model changes.
200 * @param observer The observer to be added. 213 * @param observer The observer to be added.
201 */ 214 */
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 private native void nativeDeletePages( 550 private native void nativeDeletePages(
538 long nativeOfflinePageBridge, DeletePageCallback callback, long[] of flineIds); 551 long nativeOfflinePageBridge, DeletePageCallback callback, long[] of flineIds);
539 private native void nativeGetPagesToCleanUp( 552 private native void nativeGetPagesToCleanUp(
540 long nativeOfflinePageBridge, List<OfflinePageItem> offlinePages); 553 long nativeOfflinePageBridge, List<OfflinePageItem> offlinePages);
541 private native void nativeCheckMetadataConsistency(long nativeOfflinePageBri dge); 554 private native void nativeCheckMetadataConsistency(long nativeOfflinePageBri dge);
542 private native String nativeGetOfflineUrlForOnlineUrl( 555 private native String nativeGetOfflineUrlForOnlineUrl(
543 long nativeOfflinePageBridge, String onlineUrl); 556 long nativeOfflinePageBridge, String onlineUrl);
544 private native void nativeRecordStorageHistograms(long nativeOfflinePageBrid ge, 557 private native void nativeRecordStorageHistograms(long nativeOfflinePageBrid ge,
545 long totalSpaceInBytes, long freeSpaceInBytes, boolean reportingAfte rDelete); 558 long totalSpaceInBytes, long freeSpaceInBytes, boolean reportingAfte rDelete);
546 } 559 }
OLDNEW
« no previous file with comments | « no previous file | chrome/android/javatests/src/org/chromium/chrome/browser/offlinepages/OfflinePageBridgeTest.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698