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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/preferences/website/SingleWebsitePreferences.java

Issue 2135133003: Make Website hashable so it can be deduplicated. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/android/java/src/org/chromium/chrome/browser/preferences/website/Website.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/android/java/src/org/chromium/chrome/browser/preferences/website/SingleWebsitePreferences.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/preferences/website/SingleWebsitePreferences.java b/chrome/android/java/src/org/chromium/chrome/browser/preferences/website/SingleWebsitePreferences.java
index 0fb403de14258042e56ab52a01fb76218dce4eb3..27ccc90227106c74f4b03b8813ae508a8ef1a695 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/preferences/website/SingleWebsitePreferences.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/preferences/website/SingleWebsitePreferences.java
@@ -29,8 +29,7 @@ import org.chromium.chrome.browser.util.UrlUtilities;
import org.chromium.content_public.browser.WebContents;
import java.net.URI;
-import java.util.ArrayList;
-import java.util.List;
+import java.util.HashSet;
import java.util.Map;
import java.util.Set;
@@ -122,9 +121,13 @@ public class SingleWebsitePreferences extends PreferenceFragment
if (getActivity() == null) return;
// TODO(mvanouwerkerk): Do this merge at data retrieval time in C++, instead of now.
- List<Set<Website>> allSites = new ArrayList<>();
- allSites.addAll(sitesByOrigin.values());
- allSites.addAll(sitesByHost.values());
+ Set<Website> allSites = new HashSet<>();
+ for (Set<Website> sites : sitesByOrigin.values()) {
+ allSites.addAll(sites);
+ }
+ for (Set<Website> sites : sitesByHost.values()) {
+ allSites.addAll(sites);
+ }
// TODO(mvanouwerkerk): Avoid modifying the outer class from this inner class.
mSite = mergePermissionInfoForTopLevelOrigin(mSiteAddress, allSites);
@@ -192,78 +195,76 @@ public class SingleWebsitePreferences extends PreferenceFragment
* first place.
*
* @param address The address to search for.
- * @param websiteSets The websites to search in.
+ * @param websites The websites to search in.
* @return The merged website.
*/
private static Website mergePermissionInfoForTopLevelOrigin(
- WebsiteAddress address, List<Set<Website>> websiteSets) {
+ WebsiteAddress address, Set<Website> websites) {
String origin = address.getOrigin();
String host = Uri.parse(origin).getHost();
Website merged = new Website(address);
- // This nested loop looks expensive, but the amount of data is likely to be relatively
+ // This loop looks expensive, but the amount of data is likely to be relatively
// small because most sites have very few permissions.
- for (Set<Website> websiteSet : websiteSets) {
- for (Website other : websiteSet) {
- if (merged.getFullscreenInfo() == null && other.getFullscreenInfo() != null
- && permissionInfoIsForTopLevelOrigin(other.getFullscreenInfo(), origin)) {
- merged.setFullscreenInfo(other.getFullscreenInfo());
- }
- if (merged.getGeolocationInfo() == null && other.getGeolocationInfo() != null
- && permissionInfoIsForTopLevelOrigin(other.getGeolocationInfo(), origin)) {
- merged.setGeolocationInfo(other.getGeolocationInfo());
- }
- if (merged.getKeygenInfo() == null && other.getKeygenInfo() != null
- && permissionInfoIsForTopLevelOrigin(other.getKeygenInfo(), origin)) {
- merged.setKeygenInfo(other.getKeygenInfo());
- }
- if (merged.getMidiInfo() == null && other.getMidiInfo() != null
- && permissionInfoIsForTopLevelOrigin(other.getMidiInfo(), origin)) {
- merged.setMidiInfo(other.getMidiInfo());
- }
- if (merged.getProtectedMediaIdentifierInfo() == null
- && other.getProtectedMediaIdentifierInfo() != null
- && permissionInfoIsForTopLevelOrigin(
- other.getProtectedMediaIdentifierInfo(), origin)) {
- merged.setProtectedMediaIdentifierInfo(other.getProtectedMediaIdentifierInfo());
- }
- if (merged.getNotificationInfo() == null
- && other.getNotificationInfo() != null
- && permissionInfoIsForTopLevelOrigin(
- other.getNotificationInfo(), origin)) {
- merged.setNotificationInfo(other.getNotificationInfo());
- }
- if (merged.getCameraInfo() == null && other.getCameraInfo() != null) {
- if (origin.equals(other.getCameraInfo().getOrigin())
- && (origin.equals(other.getCameraInfo().getEmbedderSafe())
- || "*".equals(other.getCameraInfo().getEmbedderSafe()))) {
- merged.setCameraInfo(other.getCameraInfo());
- }
- }
- if (merged.getMicrophoneInfo() == null && other.getMicrophoneInfo() != null) {
- if (origin.equals(other.getMicrophoneInfo().getOrigin())
- && (origin.equals(other.getMicrophoneInfo().getEmbedderSafe())
- || "*".equals(other.getMicrophoneInfo().getEmbedderSafe()))) {
- merged.setMicrophoneInfo(other.getMicrophoneInfo());
- }
+ for (Website other : websites) {
+ if (merged.getFullscreenInfo() == null && other.getFullscreenInfo() != null
+ && permissionInfoIsForTopLevelOrigin(other.getFullscreenInfo(), origin)) {
+ merged.setFullscreenInfo(other.getFullscreenInfo());
+ }
+ if (merged.getGeolocationInfo() == null && other.getGeolocationInfo() != null
+ && permissionInfoIsForTopLevelOrigin(other.getGeolocationInfo(), origin)) {
+ merged.setGeolocationInfo(other.getGeolocationInfo());
+ }
+ if (merged.getKeygenInfo() == null && other.getKeygenInfo() != null
+ && permissionInfoIsForTopLevelOrigin(other.getKeygenInfo(), origin)) {
+ merged.setKeygenInfo(other.getKeygenInfo());
+ }
+ if (merged.getMidiInfo() == null && other.getMidiInfo() != null
+ && permissionInfoIsForTopLevelOrigin(other.getMidiInfo(), origin)) {
+ merged.setMidiInfo(other.getMidiInfo());
+ }
+ if (merged.getProtectedMediaIdentifierInfo() == null
+ && other.getProtectedMediaIdentifierInfo() != null
+ && permissionInfoIsForTopLevelOrigin(
+ other.getProtectedMediaIdentifierInfo(), origin)) {
+ merged.setProtectedMediaIdentifierInfo(other.getProtectedMediaIdentifierInfo());
+ }
+ if (merged.getNotificationInfo() == null
+ && other.getNotificationInfo() != null
+ && permissionInfoIsForTopLevelOrigin(
+ other.getNotificationInfo(), origin)) {
+ merged.setNotificationInfo(other.getNotificationInfo());
+ }
+ if (merged.getCameraInfo() == null && other.getCameraInfo() != null) {
+ if (origin.equals(other.getCameraInfo().getOrigin())
+ && (origin.equals(other.getCameraInfo().getEmbedderSafe())
+ || "*".equals(other.getCameraInfo().getEmbedderSafe()))) {
+ merged.setCameraInfo(other.getCameraInfo());
}
- if (merged.getLocalStorageInfo() == null
- && other.getLocalStorageInfo() != null
- && origin.equals(other.getLocalStorageInfo().getOrigin())) {
- merged.setLocalStorageInfo(other.getLocalStorageInfo());
+ }
+ if (merged.getMicrophoneInfo() == null && other.getMicrophoneInfo() != null) {
+ if (origin.equals(other.getMicrophoneInfo().getOrigin())
+ && (origin.equals(other.getMicrophoneInfo().getEmbedderSafe())
+ || "*".equals(other.getMicrophoneInfo().getEmbedderSafe()))) {
+ merged.setMicrophoneInfo(other.getMicrophoneInfo());
}
- for (StorageInfo storageInfo : other.getStorageInfo()) {
- if (host.equals(storageInfo.getHost())) {
- merged.addStorageInfo(storageInfo);
- }
+ }
+ if (merged.getLocalStorageInfo() == null
+ && other.getLocalStorageInfo() != null
+ && origin.equals(other.getLocalStorageInfo().getOrigin())) {
+ merged.setLocalStorageInfo(other.getLocalStorageInfo());
+ }
+ for (StorageInfo storageInfo : other.getStorageInfo()) {
+ if (host.equals(storageInfo.getHost())) {
+ merged.addStorageInfo(storageInfo);
}
-
- // TODO(mvanouwerkerk): Make the various info types share a common interface that
- // supports reading the origin or host.
- // TODO(mvanouwerkerk): Merge in PopupExceptionInfo? It uses a pattern, and is never
- // set on Android.
- // TODO(mvanouwerkerk): Merge in JavaScriptExceptionInfo? It uses a pattern.
- // TODO(lshang): Merge in CookieException? It will use patterns.
}
+
+ // TODO(mvanouwerkerk): Make the various info types share a common interface that
+ // supports reading the origin or host.
+ // TODO(mvanouwerkerk): Merge in PopupExceptionInfo? It uses a pattern, and is never
+ // set on Android.
+ // TODO(mvanouwerkerk): Merge in JavaScriptExceptionInfo? It uses a pattern.
+ // TODO(lshang): Merge in CookieException? It will use patterns.
}
return merged;
}
« no previous file with comments | « no previous file | chrome/android/java/src/org/chromium/chrome/browser/preferences/website/Website.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698