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

Side by Side Diff: chrome/android/java_staging/src/org/chromium/chrome/browser/DeferredStartupHandler.java

Issue 1141283003: Upstream oodles of Chrome for Android code into Chromium. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: final patch? Created 5 years, 7 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 2015 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;
6
7 import android.os.AsyncTask;
8
9 import org.chromium.base.PowerMonitor;
10 import org.chromium.base.ThreadUtils;
11 import org.chromium.base.TraceEvent;
12 import org.chromium.base.VisibleForTesting;
13 import org.chromium.chrome.browser.bookmarkswidget.BookmarkThumbnailWidgetProvid erBase;
14 import org.chromium.chrome.browser.crash.CrashFileManager;
15 import org.chromium.chrome.browser.crash.MinidumpUploadService;
16 import org.chromium.chrome.browser.download.DownloadManagerService;
17 import org.chromium.chrome.browser.media.MediaNotificationService;
18 import org.chromium.chrome.browser.partnerbookmarks.PartnerBookmarksShim;
19 import org.chromium.chrome.browser.precache.PrecacheLauncher;
20 import org.chromium.chrome.browser.preferences.ChromePreferenceManager;
21 import org.chromium.chrome.browser.preferences.privacy.PrivacyPreferencesManager ;
22 import org.chromium.chrome.browser.share.ShareHelper;
23 import org.chromium.chrome.browser.signin.AccountManagementFragmentDelegateImpl;
24
25 /**
26 * Handler for application level tasks to be completed on deferred startup.
27 */
28 public class DeferredStartupHandler {
29 private static DeferredStartupHandler sDeferredStartupHandler;
30 private boolean mDeferredStartupComplete;
31
32 /**
33 * This class is an application specific object that handles the deferred st artup.
34 * @return The singleton instance of {@link DeferredStartupHandler}.
35 */
36 public static DeferredStartupHandler getInstance() {
37 if (sDeferredStartupHandler == null) {
38 sDeferredStartupHandler = new DeferredStartupHandler();
39 }
40 return sDeferredStartupHandler;
41 }
42
43 private DeferredStartupHandler() { }
44
45 /**
46 * Handle application level deferred startup tasks that can be lazily done a fter all
47 * the necessary initialization has been completed. Any calls requiring netw ork access should
48 * probably go here.
49 * @param application The application object to use for context.
50 * @param crashDumpUploadingDisabled Whether crash dump uploading should be disabled.
51 */
52 public void onDeferredStartup(final ChromeMobileApplication application,
53 final boolean crashDumpUploadingDisabled) {
54 if (mDeferredStartupComplete) return;
55 ThreadUtils.assertOnUiThread();
56
57 // Punt all tasks that may block the UI thread off onto a background thr ead.
58 new AsyncTask<Void, Void, Void>() {
59 @Override
60 protected Void doInBackground(Void... params) {
61 try {
62 TraceEvent.begin("ChromeBrowserInitializer.onDeferredStartup .doInBackground");
63 if (crashDumpUploadingDisabled) {
64 PrivacyPreferencesManager.getInstance(application).disab leCrashUploading();
65 } else {
66 MinidumpUploadService.tryUploadAllCrashDumps(application );
67 }
68 CrashFileManager crashFileManager =
69 new CrashFileManager(application.getCacheDir());
70 crashFileManager.cleanOutAllNonFreshMinidumpFiles();
71
72 MinidumpUploadService.storeBreakpadUploadAttemptsInUma(
73 ChromePreferenceManager.getInstance(application) );
74
75 // Force a widget refresh in order to wake up any possible z ombie widgets.
76 // This is needed to ensure the right behavior when the proc ess is suddenly
77 // killed.
78 BookmarkThumbnailWidgetProviderBase.refreshAllWidgets(applic ation);
79
80 // Initialize whether or not precaching is enabled.
81 PrecacheLauncher.updatePrecachingEnabled(
82 PrivacyPreferencesManager.getInstance(application), application);
83
84 return null;
85 } finally {
86 TraceEvent.end("ChromeBrowserInitializer.onDeferredStartup.d oInBackground");
87 }
88 }
89 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
90
91 // TODO(aruslan): http://b/6397072 This will be moved elsewhere
92 PartnerBookmarksShim.kickOffReading(application);
93
94 PowerMonitor.create(application);
95
96 // Starts syncing with GSA.
97 application.createGsaHelper().startSync();
98
99 DownloadManagerService.getDownloadManagerService(application)
100 .clearPendingDownloadNotifications();
101
102 AccountManagementFragmentDelegateImpl.registerAccountManagementFragmentD elegate();
103
104 application.initializeSharedClasses();
105
106 ShareHelper.clearSharedScreenshots(application);
107
108 // Clear any media notifications that existed when Chrome was last kille d.
109 MediaNotificationService.clearMediaNotifications(application);
110
111 mDeferredStartupComplete = true;
112 }
113
114 /**
115 * @return Whether deferred startup has been completed.
116 */
117 @VisibleForTesting
118 public boolean isDeferredStartupComplete() {
119 return mDeferredStartupComplete;
120 }
121 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698