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; | 5 package org.chromium.chrome.browser; |
6 | 6 |
| 7 import android.annotation.SuppressLint; |
7 import android.content.Context; | 8 import android.content.Context; |
8 import android.content.SharedPreferences; | 9 import android.content.SharedPreferences; |
9 import android.os.AsyncTask; | 10 import android.os.AsyncTask; |
10 import android.os.Looper; | 11 import android.os.Looper; |
11 import android.os.MessageQueue; | 12 import android.os.MessageQueue; |
12 import android.os.SystemClock; | 13 import android.os.SystemClock; |
13 import android.support.annotation.UiThread; | 14 import android.support.annotation.UiThread; |
14 import android.support.annotation.WorkerThread; | 15 import android.support.annotation.WorkerThread; |
15 import android.view.inputmethod.InputMethodInfo; | 16 import android.view.inputmethod.InputMethodInfo; |
16 import android.view.inputmethod.InputMethodManager; | 17 import android.view.inputmethod.InputMethodManager; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 * Handler for application level tasks to be completed on deferred startup. | 63 * Handler for application level tasks to be completed on deferred startup. |
63 */ | 64 */ |
64 public class DeferredStartupHandler { | 65 public class DeferredStartupHandler { |
65 private static final String TAG = "DeferredStartup"; | 66 private static final String TAG = "DeferredStartup"; |
66 /** Prevents race conditions when deleting snapshot database. */ | 67 /** Prevents race conditions when deleting snapshot database. */ |
67 private static final Object SNAPSHOT_DATABASE_LOCK = new Object(); | 68 private static final Object SNAPSHOT_DATABASE_LOCK = new Object(); |
68 private static final String SNAPSHOT_DATABASE_REMOVED = "snapshot_database_r
emoved"; | 69 private static final String SNAPSHOT_DATABASE_REMOVED = "snapshot_database_r
emoved"; |
69 private static final String SNAPSHOT_DATABASE_NAME = "snapshots.db"; | 70 private static final String SNAPSHOT_DATABASE_NAME = "snapshots.db"; |
70 | 71 |
71 private static class Holder { | 72 private static class Holder { |
| 73 @SuppressLint("StaticFieldLeak") |
72 private static final DeferredStartupHandler INSTANCE = new DeferredStart
upHandler(); | 74 private static final DeferredStartupHandler INSTANCE = new DeferredStart
upHandler(); |
73 } | 75 } |
74 | 76 |
75 private boolean mDeferredStartupInitializedForApp; | 77 private boolean mDeferredStartupInitializedForApp; |
76 private boolean mDeferredStartupCompletedForApp; | 78 private boolean mDeferredStartupCompletedForApp; |
77 private long mDeferredStartupDuration; | 79 private long mDeferredStartupDuration; |
78 private long mMaxTaskDuration; | 80 private long mMaxTaskDuration; |
79 private final Context mAppContext; | 81 private final Context mAppContext; |
80 | 82 |
81 private final Queue<Runnable> mDeferredTasks; | 83 private final Queue<Runnable> mDeferredTasks; |
82 | 84 |
83 /** | 85 /** |
84 * This class is an application specific object that handles the deferred st
artup. | 86 * This class is an application specific object that handles the deferred st
artup. |
85 * @return The singleton instance of {@link DeferredStartupHandler}. | 87 * @return The singleton instance of {@link DeferredStartupHandler}. |
86 */ | 88 */ |
87 public static DeferredStartupHandler getInstance() { | 89 public static DeferredStartupHandler getInstance() { |
88 return sDeferredStartupHandler == null ? Holder.INSTANCE : sDeferredStar
tupHandler; | 90 return sDeferredStartupHandler == null ? Holder.INSTANCE : sDeferredStar
tupHandler; |
89 } | 91 } |
90 | 92 |
91 @VisibleForTesting | 93 @VisibleForTesting |
92 public static void setInstanceForTests(DeferredStartupHandler handler) { | 94 public static void setInstanceForTests(DeferredStartupHandler handler) { |
93 sDeferredStartupHandler = handler; | 95 sDeferredStartupHandler = handler; |
94 } | 96 } |
95 | 97 |
| 98 @SuppressLint("StaticFieldLeak") |
96 private static DeferredStartupHandler sDeferredStartupHandler; | 99 private static DeferredStartupHandler sDeferredStartupHandler; |
97 | 100 |
98 protected DeferredStartupHandler() { | 101 protected DeferredStartupHandler() { |
99 mAppContext = ContextUtils.getApplicationContext(); | 102 mAppContext = ContextUtils.getApplicationContext(); |
100 mDeferredTasks = new LinkedList<>(); | 103 mDeferredTasks = new LinkedList<>(); |
101 } | 104 } |
102 | 105 |
103 /** | 106 /** |
104 * Add the idle handler which will run deferred startup tasks in sequence wh
en idle. This can | 107 * Add the idle handler which will run deferred startup tasks in sequence wh
en idle. This can |
105 * be called multiple times by different activities to schedule their own de
ferred startup | 108 * be called multiple times by different activities to schedule their own de
ferred startup |
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 } | 477 } |
475 | 478 |
476 /** | 479 /** |
477 * @return Whether deferred startup has been completed. | 480 * @return Whether deferred startup has been completed. |
478 */ | 481 */ |
479 @VisibleForTesting | 482 @VisibleForTesting |
480 public boolean isDeferredStartupCompleteForApp() { | 483 public boolean isDeferredStartupCompleteForApp() { |
481 return mDeferredStartupCompletedForApp; | 484 return mDeferredStartupCompletedForApp; |
482 } | 485 } |
483 } | 486 } |
OLD | NEW |