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

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

Powered by Google App Engine
This is Rietveld 408576698