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.preferences.website; | 5 package org.chromium.chrome.browser.preferences.website; |
6 | 6 |
7 import android.util.Pair; | 7 import android.util.Pair; |
8 | 8 |
9 import org.chromium.base.Callback; | 9 import org.chromium.base.Callback; |
10 import org.chromium.chrome.browser.ContentSettingsType; | 10 import org.chromium.chrome.browser.ContentSettingsType; |
(...skipping 16 matching lines...) Expand all Loading... |
27 public interface WebsitePermissionsCallback { | 27 public interface WebsitePermissionsCallback { |
28 void onWebsitePermissionsAvailable(Collection<Website> sites); | 28 void onWebsitePermissionsAvailable(Collection<Website> sites); |
29 } | 29 } |
30 | 30 |
31 // This map looks up Websites by their origin and embedder. | 31 // This map looks up Websites by their origin and embedder. |
32 private final Map<Pair<WebsiteAddress, WebsiteAddress>, Website> mSites = ne
w HashMap<>(); | 32 private final Map<Pair<WebsiteAddress, WebsiteAddress>, Website> mSites = ne
w HashMap<>(); |
33 | 33 |
34 // The callback to run when the permissions have been fetched. | 34 // The callback to run when the permissions have been fetched. |
35 private final WebsitePermissionsCallback mCallback; | 35 private final WebsitePermissionsCallback mCallback; |
36 | 36 |
| 37 private final boolean mFetchSiteImportantInfo; |
| 38 |
37 /** | 39 /** |
38 * @param callback The callback to run when the fetch is complete. | 40 * @param callback The callback to run when the fetch is complete. |
39 */ | 41 */ |
40 public WebsitePermissionsFetcher(WebsitePermissionsCallback callback) { | 42 public WebsitePermissionsFetcher(WebsitePermissionsCallback callback) { |
41 mCallback = callback; | 43 this(callback, false); |
42 } | 44 } |
43 | 45 |
44 /** | 46 /** |
| 47 * @param callback The callback to run when the fetch is complete. |
| 48 * @param fetchSiteImportantInfo if the fetcher should query whether each si
te is 'important'. |
| 49 */ |
| 50 public WebsitePermissionsFetcher( |
| 51 WebsitePermissionsCallback callback, boolean fetchSiteImportantInfo)
{ |
| 52 mCallback = callback; |
| 53 mFetchSiteImportantInfo = fetchSiteImportantInfo; |
| 54 } |
| 55 |
| 56 /** |
45 * Fetches preferences for all sites that have them. | 57 * Fetches preferences for all sites that have them. |
46 * TODO(mvanouwerkerk): Add an argument |url| to only fetch permissions for | 58 * TODO(mvanouwerkerk): Add an argument |url| to only fetch permissions for |
47 * sites from the same origin as that of |url| - https://crbug.com/459222. | 59 * sites from the same origin as that of |url| - https://crbug.com/459222. |
48 */ | 60 */ |
49 public void fetchAllPreferences() { | 61 public void fetchAllPreferences() { |
50 TaskQueue queue = new TaskQueue(); | 62 TaskQueue queue = new TaskQueue(); |
51 // Populate features from more specific to less specific. | 63 // Populate features from more specific to less specific. |
52 // Geolocation lookup permission is per-origin and per-embedder. | 64 // Geolocation lookup permission is per-origin and per-embedder. |
53 queue.add(new GeolocationInfoFetcher()); | 65 queue.add(new GeolocationInfoFetcher()); |
54 // Midi sysex access permission is per-origin and per-embedder. | 66 // Midi sysex access permission is per-origin and per-embedder. |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 for (Object o : result.entrySet()) { | 303 for (Object o : result.entrySet()) { |
292 @SuppressWarnings("unchecked") | 304 @SuppressWarnings("unchecked") |
293 Map.Entry<String, LocalStorageInfo> entry = | 305 Map.Entry<String, LocalStorageInfo> entry = |
294 (Map.Entry<String, LocalStorageInfo>) o; | 306 (Map.Entry<String, LocalStorageInfo>) o; |
295 WebsiteAddress address = WebsiteAddress.create(entry.get
Key()); | 307 WebsiteAddress address = WebsiteAddress.create(entry.get
Key()); |
296 if (address == null) continue; | 308 if (address == null) continue; |
297 findOrCreateSite(address, null).setLocalStorageInfo(entr
y.getValue()); | 309 findOrCreateSite(address, null).setLocalStorageInfo(entr
y.getValue()); |
298 } | 310 } |
299 queue.next(); | 311 queue.next(); |
300 } | 312 } |
301 }); | 313 }, mFetchSiteImportantInfo); |
302 } | 314 } |
303 } | 315 } |
304 | 316 |
305 private class WebStorageInfoFetcher extends Task { | 317 private class WebStorageInfoFetcher extends Task { |
306 @Override | 318 @Override |
307 public void runAsync(final TaskQueue queue) { | 319 public void runAsync(final TaskQueue queue) { |
308 WebsitePreferenceBridge.fetchStorageInfo(new Callback<ArrayList>() { | 320 WebsitePreferenceBridge.fetchStorageInfo(new Callback<ArrayList>() { |
309 @Override | 321 @Override |
310 public void onResult(ArrayList result) { | 322 public void onResult(ArrayList result) { |
311 @SuppressWarnings("unchecked") | 323 @SuppressWarnings("unchecked") |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 } | 402 } |
391 } | 403 } |
392 | 404 |
393 private class PermissionsAvailableCallbackRunner extends Task { | 405 private class PermissionsAvailableCallbackRunner extends Task { |
394 @Override | 406 @Override |
395 public void run() { | 407 public void run() { |
396 mCallback.onWebsitePermissionsAvailable(mSites.values()); | 408 mCallback.onWebsitePermissionsAvailable(mSites.values()); |
397 } | 409 } |
398 } | 410 } |
399 } | 411 } |
OLD | NEW |