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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/preferences/privacy/BrowsingDataBridge.java

Issue 2756173002: Move code about browsing data from PrefServiceBridge to BrowsingDataBridge. (Closed)
Patch Set: fix comments Created 3 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
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package org.chromium.chrome.browser.preferences.privacy;
6
7 import org.chromium.base.ThreadUtils;
8 import org.chromium.base.VisibleForTesting;
9 import org.chromium.base.annotations.CalledByNative;
10 import org.chromium.chrome.browser.browsing_data.BrowsingDataType;
11 import org.chromium.chrome.browser.browsing_data.TimePeriod;
12
13 /**
14 * Communicates between ClearBrowsingData, ImportantSitesUtils (C++) and
15 * ClearBrowsingDataPreferences (Java UI).
16 */
17 public final class BrowsingDataBridge {
18 private static BrowsingDataBridge sInstance;
19
20 // Object to notify when "clear browsing data" completes.
21 private OnClearBrowsingDataListener mClearBrowsingDataListener;
22
23 /**
24 * Interface for a class that is listening to clear browser data events.
25 */
26 public interface OnClearBrowsingDataListener { void onBrowsingDataCleared(); }
27
28 /**
29 * Interface for a class that is fetching important site information.
30 */
31 public interface ImportantSitesCallback {
32 /**
33 * Called when the list of important registerable domains has been fetch ed from cpp.
34 * See net/base/registry_controlled_domains/registry_controlled_domain.h for more details on
35 * registrable domains and the current list of effective eTLDs.
36 * @param domains Important registerable domains.
37 * @param exampleOrigins Example origins for each domain. These can be u sed to retrieve
38 * favicons.
39 * @param importantReasons Bitfield of reasons why this domain was selec ted. Pass this back
40 * to clearBrowinsgData so we can record metrics .
41 * @param dialogDisabled If the important dialog has been ignored too ma ny times and should
42 * not be shown.
43 */
44 @CalledByNative("ImportantSitesCallback")
45 void onImportantRegisterableDomainsReady(String[] domains, String[] exam pleOrigins,
46 int[] importantReasons, boolean dialogDisabled);
47 }
48
49 /**
50 * Interface to a class that receives callbacks instructing it to inform the user about other
51 * forms of browsing history.
52 */
53 public interface OtherFormsOfBrowsingHistoryListener {
54 /**
55 * Called by the web history service when it discovers that other forms of browsing history
56 * exist.
57 */
58 @CalledByNative("OtherFormsOfBrowsingHistoryListener")
59 void enableDialogAboutOtherFormsOfBrowsingHistory();
60
61 /**
62 * Called by the web history service when the conditions for showing the dialog about
63 * other forms of browsing history are met.
64 */
65 @CalledByNative("OtherFormsOfBrowsingHistoryListener")
66 void showNoticeAboutOtherFormsOfBrowsingHistory();
67 }
68
69 private BrowsingDataBridge() {}
70
71 /**
72 * @return The singleton bridge object.
73 */
74 public static BrowsingDataBridge getInstance() {
75 ThreadUtils.assertOnUiThread();
76 if (sInstance == null) sInstance = new BrowsingDataBridge();
77 return sInstance;
78 }
79
80 @CalledByNative
81 private void browsingDataCleared() {
82 if (mClearBrowsingDataListener != null) {
83 mClearBrowsingDataListener.onBrowsingDataCleared();
84 mClearBrowsingDataListener = null;
85 }
86 }
87
88 /**
89 * Clear the specified types of browsing data asynchronously.
90 * |listener| is an object to be notified when clearing completes.
91 * It can be null, but many operations (e.g. navigation) are
92 * ill-advised while browsing data is being cleared.
93 * @param listener A listener to call back when the clearing is finished.
94 * @param dataTypes An array of browsing data types to delete, represented a s values from
95 * the shared enum {@link BrowsingDataType}.
96 * @param timePeriod The time period for which to delete the data, represent ed as a value from
97 * the shared enum {@link TimePeriod}.
98 */
99 public void clearBrowsingData(
100 OnClearBrowsingDataListener listener, int[] dataTypes, int timePerio d) {
101 clearBrowsingDataExcludingDomains(listener, dataTypes, timePeriod, new S tring[0],
102 new int[0], new String[0], new int[0]);
103 }
104
105 /**
106 * Same as above, but now we can specify a list of domains to exclude from c learing browsing
107 * data.
108 * Do not use this method unless caller knows what they're doing. Not all ba ckends are supported
109 * yet, and more data than expected could be deleted. See crbug.com/113621.
110 * @param listener A listener to call back when the clearing is finished.
111 * @param dataTypes An array of browsing data types to delete, represented a s values from
112 * the shared enum {@link BrowsingDataType}.
113 * @param timePeriod The time period for which to delete the data, represent ed as a value from
114 * the shared enum {@link TimePeriod}.
115 * @param blacklistDomains A list of registerable domains that we don't clea r data for.
116 * @param blacklistedDomainReasons A list of the reason metadata for the bla cklisted domains.
117 * @param ignoredDomains A list of ignored domains that the user chose to no t blacklist. We use
118 * these to remove important site entries if the user ignores them enough.
119 * @param ignoredDomainReasons A list of reason metadata for the ignored dom ains.
120 */
121 public void clearBrowsingDataExcludingDomains(OnClearBrowsingDataListener li stener,
122 int[] dataTypes, int timePeriod, String[] blacklistDomains,
123 int[] blacklistedDomainReasons, String[] ignoredDomains, int[] ignor edDomainReasons) {
124 assert mClearBrowsingDataListener == null;
125 mClearBrowsingDataListener = listener;
126 nativeClearBrowsingData(dataTypes, timePeriod, blacklistDomains, blackli stedDomainReasons,
127 ignoredDomains, ignoredDomainReasons);
128 }
129
130 /**
131 * This fetches sites (registerable domains) that we consider important. Thi s combines many
132 * pieces of information, including site engagement and permissions. The cal lback is called
133 * with the list of important registerable domains.
134 *
135 * See net/base/registry_controlled_domains/registry_controlled_domain.h for more details on
136 * registrable domains and the current list of effective eTLDs.
137 * @param callback The callback that will be used to set the list of importa nt sites.
138 */
139 public static void fetchImportantSites(ImportantSitesCallback callback) {
140 nativeFetchImportantSites(callback);
141 }
142
143 /**
144 * @return The maximum number of important sites that will be returned from the call above.
145 * This is a constant that won't change.
146 */
147 public static int getMaxImportantSites() {
148 return nativeGetMaxImportantSites();
149 }
150
151 /** This lets us mark an origin as important for testing. */
152 @VisibleForTesting
153 public static void markOriginAsImportantForTesting(String origin) {
154 nativeMarkOriginAsImportantForTesting(origin);
155 }
156
157 /**
158 * Requests that the web history service finds out if we should inform the u ser about the
159 * existence of other forms of browsing history. The response will be asynch ronous, through
160 * {@link OtherFormsOfBrowsingHistoryListener}.
161 */
162 public void requestInfoAboutOtherFormsOfBrowsingHistory(
163 OtherFormsOfBrowsingHistoryListener listener) {
164 nativeRequestInfoAboutOtherFormsOfBrowsingHistory(listener);
165 }
166
167 private native void nativeClearBrowsingData(int[] dataTypes, int timePeriod,
168 String[] blacklistDomains, int[] blacklistedDomainReasons, String[] ignoredDomains,
169 int[] ignoredDomainReasons);
170 private native void nativeRequestInfoAboutOtherFormsOfBrowsingHistory(
171 OtherFormsOfBrowsingHistoryListener listener);
172 private static native void nativeFetchImportantSites(ImportantSitesCallback callback);
173 private static native int nativeGetMaxImportantSites();
174 private static native void nativeMarkOriginAsImportantForTesting(String orig in);
175 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698