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 org.chromium.chrome.browser.ContentSettingsType; | 7 import org.chromium.chrome.browser.ContentSettingsType; |
8 | 8 |
9 import java.util.ArrayList; | 9 import java.util.ArrayList; |
10 import java.util.HashMap; | 10 import java.util.HashMap; |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 private Set<Website> findOrCreateSitesByHost(WebsiteAddress address) { | 155 private Set<Website> findOrCreateSitesByHost(WebsiteAddress address) { |
156 String host = address.getHost(); | 156 String host = address.getHost(); |
157 if (!mSitesByHost.containsKey(host)) { | 157 if (!mSitesByHost.containsKey(host)) { |
158 mSitesByHost.put(host, new HashSet<Website>()); | 158 mSitesByHost.put(host, new HashSet<Website>()); |
159 mSitesByHost.get(host).add(new Website(address)); | 159 mSitesByHost.get(host).add(new Website(address)); |
160 } | 160 } |
161 return mSitesByHost.get(host); | 161 return mSitesByHost.get(host); |
162 } | 162 } |
163 | 163 |
164 /** | 164 /** |
165 * A single task in the WebsitePermissionsFetcher task queue. We need | 165 * A single task in the WebsitePermissionsFetcher task queue. We need fetchi
ng of features to be |
166 * fetching of features to be serialized, as we need to have all the origins | 166 * serialized, as we need to have all the origins in place prior to populati
ng the hosts. |
167 * in place prior to populating the hosts. | |
168 */ | 167 */ |
169 private interface Task { | 168 private abstract class Task { |
170 void run(TaskQueue queue); | 169 /** Override this method to implement a synchronous task. */ |
| 170 void run() {} |
| 171 |
| 172 /** |
| 173 * Override this method to implement an asynchronous task. Call queue.ne
xt() once execution |
| 174 * is complete. |
| 175 */ |
| 176 void runAsync(TaskQueue queue) { |
| 177 run(); |
| 178 queue.next(); |
| 179 } |
171 } | 180 } |
172 | 181 |
173 /** | 182 /** |
174 * A queue used to store the sequence of tasks to run to fetch the website | 183 * A queue used to store the sequence of tasks to run to fetch the website p
references. Each |
175 * preferences. Each task is run sequentially (although the queue as a whole | 184 * task is run sequentially, and some of the tasks may run asynchronously. |
176 * is run asynchronously). Each task should call queue.next() at the end to | |
177 * run the next task in the queue. | |
178 */ | 185 */ |
179 private static class TaskQueue extends LinkedList<Task> { | 186 private static class TaskQueue extends LinkedList<Task> { |
180 void next() { | 187 void next() { |
181 if (!isEmpty()) removeFirst().run(this); | 188 if (!isEmpty()) removeFirst().runAsync(this); |
182 } | 189 } |
183 } | 190 } |
184 | 191 |
185 private class GeolocationInfoFetcher implements Task { | 192 private class GeolocationInfoFetcher extends Task { |
186 @Override | 193 @Override |
187 public void run(TaskQueue queue) { | 194 public void run() { |
188 for (GeolocationInfo info : WebsitePreferenceBridge.getGeolocationIn
fo()) { | 195 for (GeolocationInfo info : WebsitePreferenceBridge.getGeolocationIn
fo()) { |
189 WebsiteAddress address = WebsiteAddress.create(info.getOrigin())
; | 196 WebsiteAddress address = WebsiteAddress.create(info.getOrigin())
; |
190 if (address == null) continue; | 197 if (address == null) continue; |
191 createSiteByOriginAndHost(address).setGeolocationInfo(info); | 198 createSiteByOriginAndHost(address).setGeolocationInfo(info); |
192 } | 199 } |
193 queue.next(); | |
194 } | 200 } |
195 } | 201 } |
196 | 202 |
197 private class MidiInfoFetcher implements Task { | 203 private class MidiInfoFetcher extends Task { |
198 @Override | 204 @Override |
199 public void run(TaskQueue queue) { | 205 public void run() { |
200 for (MidiInfo info : WebsitePreferenceBridge.getMidiInfo()) { | 206 for (MidiInfo info : WebsitePreferenceBridge.getMidiInfo()) { |
201 WebsiteAddress address = WebsiteAddress.create(info.getOrigin())
; | 207 WebsiteAddress address = WebsiteAddress.create(info.getOrigin())
; |
202 if (address == null) continue; | 208 if (address == null) continue; |
203 createSiteByOriginAndHost(address).setMidiInfo(info); | 209 createSiteByOriginAndHost(address).setMidiInfo(info); |
204 } | 210 } |
205 queue.next(); | |
206 } | 211 } |
207 } | 212 } |
208 | 213 |
209 private class PopupExceptionInfoFetcher implements Task { | 214 private class PopupExceptionInfoFetcher extends Task { |
210 @Override | 215 @Override |
211 public void run(TaskQueue queue) { | 216 public void run() { |
212 for (ContentSettingException exception : | 217 for (ContentSettingException exception : |
213 WebsitePreferenceBridge.getContentSettingsExceptions( | 218 WebsitePreferenceBridge.getContentSettingsExceptions( |
214 ContentSettingsType.CONTENT_SETTINGS_TYPE_POPUPS)) { | 219 ContentSettingsType.CONTENT_SETTINGS_TYPE_POPUPS)) { |
215 // The pattern "*" represents the default setting, not a | 220 // The pattern "*" represents the default setting, not a |
216 // specific website. | 221 // specific website. |
217 if (exception.getPattern().equals("*")) continue; | 222 if (exception.getPattern().equals("*")) continue; |
218 WebsiteAddress address = WebsiteAddress.create(exception.getPatt
ern()); | 223 WebsiteAddress address = WebsiteAddress.create(exception.getPatt
ern()); |
219 if (address == null) continue; | 224 if (address == null) continue; |
220 Set<Website> sites = findOrCreateSitesByHost(address); | 225 Set<Website> sites = findOrCreateSitesByHost(address); |
221 for (Website site : sites) { | 226 for (Website site : sites) { |
222 site.setPopupException(exception); | 227 site.setPopupException(exception); |
223 } | 228 } |
224 } | 229 } |
225 queue.next(); | |
226 } | 230 } |
227 } | 231 } |
228 | 232 |
229 private class JavaScriptExceptionInfoFetcher implements Task { | 233 private class JavaScriptExceptionInfoFetcher extends Task { |
230 @Override | 234 @Override |
231 public void run(TaskQueue queue) { | 235 public void run() { |
232 for (ContentSettingException exception | 236 for (ContentSettingException exception |
233 : WebsitePreferenceBridge.getContentSettingsExceptions( | 237 : WebsitePreferenceBridge.getContentSettingsExceptions( |
234 ContentSettingsType.CONTENT_SETTINGS_TYPE_JAVASCRIPT
)) { | 238 ContentSettingsType.CONTENT_SETTINGS_TYPE_JAVASCRIPT
)) { |
235 // The pattern "*" represents the default setting, not a specifi
c website. | 239 // The pattern "*" represents the default setting, not a specifi
c website. |
236 if (exception.getPattern().equals("*")) continue; | 240 if (exception.getPattern().equals("*")) continue; |
237 WebsiteAddress address = WebsiteAddress.create(exception.getPatt
ern()); | 241 WebsiteAddress address = WebsiteAddress.create(exception.getPatt
ern()); |
238 if (address == null) continue; | 242 if (address == null) continue; |
239 Set<Website> sites = findOrCreateSitesByHost(address); | 243 Set<Website> sites = findOrCreateSitesByHost(address); |
240 for (Website site : sites) { | 244 for (Website site : sites) { |
241 site.setJavaScriptException(exception); | 245 site.setJavaScriptException(exception); |
242 } | 246 } |
243 } | 247 } |
244 queue.next(); | |
245 } | 248 } |
246 } | 249 } |
247 | 250 |
248 private class CookieInfoFetcher implements Task { | 251 private class CookieInfoFetcher extends Task { |
249 @Override | 252 @Override |
250 public void run(TaskQueue queue) { | 253 public void run() { |
251 for (CookieInfo info : WebsitePreferenceBridge.getCookieInfo()) { | 254 for (CookieInfo info : WebsitePreferenceBridge.getCookieInfo()) { |
252 WebsiteAddress address = WebsiteAddress.create(info.getOrigin())
; | 255 WebsiteAddress address = WebsiteAddress.create(info.getOrigin())
; |
253 if (address == null) continue; | 256 if (address == null) continue; |
254 createSiteByOriginAndHost(address).setCookieInfo(info); | 257 createSiteByOriginAndHost(address).setCookieInfo(info); |
255 } | 258 } |
256 queue.next(); | |
257 } | 259 } |
258 } | 260 } |
259 | 261 |
260 /** | 262 /** |
261 * Class for fetching the fullscreen information. | 263 * Class for fetching the fullscreen information. |
262 */ | 264 */ |
263 private class FullscreenInfoFetcher implements Task { | 265 private class FullscreenInfoFetcher extends Task { |
264 @Override | 266 @Override |
265 public void run(TaskQueue queue) { | 267 public void run() { |
266 for (FullscreenInfo info : WebsitePreferenceBridge.getFullscreenInfo
()) { | 268 for (FullscreenInfo info : WebsitePreferenceBridge.getFullscreenInfo
()) { |
267 WebsiteAddress address = WebsiteAddress.create(info.getOrigin())
; | 269 WebsiteAddress address = WebsiteAddress.create(info.getOrigin())
; |
268 if (address == null) continue; | 270 if (address == null) continue; |
269 createSiteByOriginAndHost(address).setFullscreenInfo(info); | 271 createSiteByOriginAndHost(address).setFullscreenInfo(info); |
270 } | 272 } |
271 queue.next(); | |
272 } | 273 } |
273 } | 274 } |
274 | 275 |
275 private class LocalStorageInfoFetcher implements Task { | 276 private class LocalStorageInfoFetcher extends Task { |
276 @Override | 277 @Override |
277 public void run(final TaskQueue queue) { | 278 public void runAsync(final TaskQueue queue) { |
278 WebsitePreferenceBridge.fetchLocalStorageInfo( | 279 WebsitePreferenceBridge.fetchLocalStorageInfo( |
279 new WebsitePreferenceBridge.LocalStorageInfoReadyCallback()
{ | 280 new WebsitePreferenceBridge.LocalStorageInfoReadyCallback()
{ |
280 @SuppressWarnings("unchecked") | 281 @SuppressWarnings("unchecked") |
281 @Override | 282 @Override |
282 public void onLocalStorageInfoReady(HashMap map) { | 283 public void onLocalStorageInfoReady(HashMap map) { |
283 for (Object o : map.entrySet()) { | 284 for (Object o : map.entrySet()) { |
284 Map.Entry<String, LocalStorageInfo> entry = | 285 Map.Entry<String, LocalStorageInfo> entry = |
285 (Map.Entry<String, LocalStorageInfo>) o; | 286 (Map.Entry<String, LocalStorageInfo>) o; |
286 WebsiteAddress address = WebsiteAddress.create(e
ntry.getKey()); | 287 WebsiteAddress address = WebsiteAddress.create(e
ntry.getKey()); |
287 if (address == null) continue; | 288 if (address == null) continue; |
288 Set<Website> sites = findOrCreateSitesByOrigin(a
ddress); | 289 Set<Website> sites = findOrCreateSitesByOrigin(a
ddress); |
289 for (Website site : sites) { | 290 for (Website site : sites) { |
290 site.setLocalStorageInfo(entry.getValue()); | 291 site.setLocalStorageInfo(entry.getValue()); |
291 } | 292 } |
292 } | 293 } |
293 queue.next(); | 294 queue.next(); |
294 } | 295 } |
295 }); | 296 }); |
296 } | 297 } |
297 } | 298 } |
298 | 299 |
299 private class WebStorageInfoFetcher implements Task { | 300 private class WebStorageInfoFetcher extends Task { |
300 @Override | 301 @Override |
301 public void run(final TaskQueue queue) { | 302 public void runAsync(final TaskQueue queue) { |
302 WebsitePreferenceBridge.fetchStorageInfo( | 303 WebsitePreferenceBridge.fetchStorageInfo( |
303 new WebsitePreferenceBridge.StorageInfoReadyCallback() { | 304 new WebsitePreferenceBridge.StorageInfoReadyCallback() { |
304 @SuppressWarnings("unchecked") | 305 @SuppressWarnings("unchecked") |
305 @Override | 306 @Override |
306 public void onStorageInfoReady(ArrayList array) { | 307 public void onStorageInfoReady(ArrayList array) { |
307 ArrayList<StorageInfo> infoArray = array; | 308 ArrayList<StorageInfo> infoArray = array; |
308 for (StorageInfo info : infoArray) { | 309 for (StorageInfo info : infoArray) { |
309 WebsiteAddress address = WebsiteAddress.create(i
nfo.getHost()); | 310 WebsiteAddress address = WebsiteAddress.create(i
nfo.getHost()); |
310 if (address == null) continue; | 311 if (address == null) continue; |
311 Set<Website> sites = findOrCreateSitesByHost(add
ress); | 312 Set<Website> sites = findOrCreateSitesByHost(add
ress); |
312 for (Website site : sites) { | 313 for (Website site : sites) { |
313 site.addStorageInfo(info); | 314 site.addStorageInfo(info); |
314 } | 315 } |
315 } | 316 } |
316 queue.next(); | 317 queue.next(); |
317 } | 318 } |
318 }); | 319 }); |
319 } | 320 } |
320 } | 321 } |
321 | 322 |
322 private class ProtectedMediaIdentifierInfoFetcher implements Task { | 323 private class ProtectedMediaIdentifierInfoFetcher extends Task { |
323 @Override | 324 @Override |
324 public void run(TaskQueue queue) { | 325 public void run() { |
325 for (ProtectedMediaIdentifierInfo info : | 326 for (ProtectedMediaIdentifierInfo info : |
326 WebsitePreferenceBridge.getProtectedMediaIdentifierInfo()) { | 327 WebsitePreferenceBridge.getProtectedMediaIdentifierInfo()) { |
327 WebsiteAddress address = WebsiteAddress.create(info.getOrigin())
; | 328 WebsiteAddress address = WebsiteAddress.create(info.getOrigin())
; |
328 if (address == null) continue; | 329 if (address == null) continue; |
329 createSiteByOriginAndHost(address).setProtectedMediaIdentifierIn
fo(info); | 330 createSiteByOriginAndHost(address).setProtectedMediaIdentifierIn
fo(info); |
330 } | 331 } |
331 queue.next(); | |
332 } | 332 } |
333 } | 333 } |
334 | 334 |
335 private class PushNotificationInfoFetcher implements Task { | 335 private class PushNotificationInfoFetcher extends Task { |
336 @Override | 336 @Override |
337 public void run(TaskQueue queue) { | 337 public void run() { |
338 for (PushNotificationInfo info : WebsitePreferenceBridge.getPushNoti
ficationInfo()) { | 338 for (PushNotificationInfo info : WebsitePreferenceBridge.getPushNoti
ficationInfo()) { |
339 WebsiteAddress address = WebsiteAddress.create(info.getOrigin())
; | 339 WebsiteAddress address = WebsiteAddress.create(info.getOrigin())
; |
340 if (address == null) continue; | 340 if (address == null) continue; |
341 createSiteByOriginAndHost(address).setPushNotificationInfo(info)
; | 341 createSiteByOriginAndHost(address).setPushNotificationInfo(info)
; |
342 } | 342 } |
343 queue.next(); | |
344 } | 343 } |
345 } | 344 } |
346 | 345 |
347 private class CameraCaptureInfoFetcher implements Task { | 346 private class CameraCaptureInfoFetcher extends Task { |
348 @Override | 347 @Override |
349 public void run(TaskQueue queue) { | 348 public void run() { |
350 for (CameraInfo info : WebsitePreferenceBridge.getCameraInfo()) { | 349 for (CameraInfo info : WebsitePreferenceBridge.getCameraInfo()) { |
351 WebsiteAddress address = WebsiteAddress.create(info.getOrigin())
; | 350 WebsiteAddress address = WebsiteAddress.create(info.getOrigin())
; |
352 if (address == null) continue; | 351 if (address == null) continue; |
353 createSiteByOriginAndHost(address).setCameraInfo(info); | 352 createSiteByOriginAndHost(address).setCameraInfo(info); |
354 } | 353 } |
355 queue.next(); | |
356 } | 354 } |
357 } | 355 } |
358 | 356 |
359 private class MicrophoneCaptureInfoFetcher implements Task { | 357 private class MicrophoneCaptureInfoFetcher extends Task { |
360 @Override | 358 @Override |
361 public void run(TaskQueue queue) { | 359 public void run() { |
362 for (MicrophoneInfo info : WebsitePreferenceBridge.getMicrophoneInfo
()) { | 360 for (MicrophoneInfo info : WebsitePreferenceBridge.getMicrophoneInfo
()) { |
363 WebsiteAddress address = WebsiteAddress.create(info.getOrigin())
; | 361 WebsiteAddress address = WebsiteAddress.create(info.getOrigin())
; |
364 if (address == null) continue; | 362 if (address == null) continue; |
365 createSiteByOriginAndHost(address).setMicrophoneInfo(info); | 363 createSiteByOriginAndHost(address).setMicrophoneInfo(info); |
366 } | 364 } |
367 queue.next(); | |
368 } | 365 } |
369 } | 366 } |
370 | 367 |
371 private class PermissionsAvailableCallbackRunner implements Task { | 368 private class PermissionsAvailableCallbackRunner extends Task { |
372 @Override | 369 @Override |
373 public void run(TaskQueue queue) { | 370 public void run() { |
374 mCallback.onWebsitePermissionsAvailable(mSitesByOrigin, mSitesByHost
); | 371 mCallback.onWebsitePermissionsAvailable(mSitesByOrigin, mSitesByHost
); |
375 queue.next(); | |
376 } | 372 } |
377 } | 373 } |
378 } | 374 } |
OLD | NEW |