Chromium Code Reviews| OLD | NEW |
|---|---|
| (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.download.items; | |
| 6 | |
| 7 import android.content.Context; | |
| 8 | |
| 9 import org.chromium.chrome.browser.download.items.OfflineContentAggregatorNotifi er.NotifierUi; | |
| 10 import org.chromium.chrome.browser.profiles.Profile; | |
| 11 import org.chromium.components.offline_items_collection.OfflineContentProvider; | |
| 12 | |
| 13 /** | |
| 14 * A factory helper to create and hold a {@link OfflineContentAggregatorNotifier }. This will glue | |
| 15 * the {@link Profile} owned {@link OfflineContentProvider} to the | |
| 16 * {@link org.chromium.chrome.browser.download.DownloadNotificationService}. | |
| 17 */ | |
| 18 public class OfflineContentAggregatorNotifierFactory { | |
|
David Trainor- moved to gerrit
2017/03/18 00:45:41
I eventually need to have a better story for how w
gone
2017/03/20 19:03:36
Does it make sense to put this in DeferredStartupH
| |
| 19 private static OfflineContentAggregatorNotifier sNotifier; | |
| 20 | |
| 21 /** | |
| 22 * Creates a {@link OfflineContentAggregatorNotifier} and connects it to the UI and the | |
| 23 * underlying {@link OfflineContentProvider}. Save to call more than once. Will be a NOOP if | |
| 24 * the notifier is already created. | |
| 25 * @param context | |
|
gone
2017/03/20 19:03:36
fill this in
David Trainor- moved to gerrit
2017/03/25 03:31:13
Done.
| |
| 26 */ | |
| 27 public static void create(Context context) { | |
| 28 if (sNotifier != null) return; | |
|
gone
2017/03/20 19:03:36
Should synchronize on an Object to prevent this fr
David Trainor- moved to gerrit
2017/03/25 03:31:13
Put an assert check for UI thread. LMK if you'd l
| |
| 29 | |
| 30 Profile profile = Profile.getLastUsedProfile(); | |
| 31 OfflineContentProvider provider = OfflineContentAggregatorFactory.forPro file(profile); | |
| 32 NotifierUi ui = new DownloadNotificationServiceNotifierUi(context); | |
| 33 | |
| 34 sNotifier = new OfflineContentAggregatorNotifier(provider, ui); | |
| 35 } | |
| 36 | |
| 37 /** | |
| 38 * Destroys the internal {@link OfflineContentAggregatorNotifier}. Safe to call more than once. | |
| 39 * Will be a NOOP if called when there is no notifier built. | |
| 40 * TODO(dtrainor): Currently we have no path to destroy this, given the vari ous ways Chrome can | |
| 41 * be started and stopped. It's fine to leave this running during the durat ion of the process | |
| 42 * though. | |
| 43 */ | |
| 44 public static void destroy() { | |
| 45 if (sNotifier == null) return; | |
|
gone
2017/03/20 19:03:36
should probably also synchronize here
| |
| 46 | |
| 47 sNotifier.destroy(); | |
| 48 sNotifier = null; | |
| 49 } | |
| 50 } | |
| OLD | NEW |