Chromium Code Reviews| 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 // TODO(crbug.com/635567): Fix this properly. | |
|
Ted C
2017/04/27 19:02:47
same comment, this is correct and no fix is needed
F
2017/04/28 18:25:14
Done.
| |
| 74 @SuppressLint("StaticFieldLeak") | |
| 72 private static final DeferredStartupHandler INSTANCE = new DeferredStart upHandler(); | 75 private static final DeferredStartupHandler INSTANCE = new DeferredStart upHandler(); |
| 73 } | 76 } |
| 74 | 77 |
| 75 private boolean mDeferredStartupInitializedForApp; | 78 private boolean mDeferredStartupInitializedForApp; |
| 76 private boolean mDeferredStartupCompletedForApp; | 79 private boolean mDeferredStartupCompletedForApp; |
| 77 private long mDeferredStartupDuration; | 80 private long mDeferredStartupDuration; |
| 78 private long mMaxTaskDuration; | 81 private long mMaxTaskDuration; |
| 79 private final Context mAppContext; | 82 private final Context mAppContext; |
| 80 | 83 |
| 81 private final Queue<Runnable> mDeferredTasks; | 84 private final Queue<Runnable> mDeferredTasks; |
| 82 | 85 |
| 83 /** | 86 /** |
| 84 * This class is an application specific object that handles the deferred st artup. | 87 * This class is an application specific object that handles the deferred st artup. |
| 85 * @return The singleton instance of {@link DeferredStartupHandler}. | 88 * @return The singleton instance of {@link DeferredStartupHandler}. |
| 86 */ | 89 */ |
| 87 public static DeferredStartupHandler getInstance() { | 90 public static DeferredStartupHandler getInstance() { |
| 88 return sDeferredStartupHandler == null ? Holder.INSTANCE : sDeferredStar tupHandler; | 91 return sDeferredStartupHandler == null ? Holder.INSTANCE : sDeferredStar tupHandler; |
| 89 } | 92 } |
| 90 | 93 |
| 91 @VisibleForTesting | 94 @VisibleForTesting |
| 92 public static void setInstanceForTests(DeferredStartupHandler handler) { | 95 public static void setInstanceForTests(DeferredStartupHandler handler) { |
| 93 sDeferredStartupHandler = handler; | 96 sDeferredStartupHandler = handler; |
| 94 } | 97 } |
| 95 | 98 |
| 99 // TODO(crbug.com/635567): Fix this properly. | |
| 100 @SuppressLint("StaticFieldLeak") | |
| 96 private static DeferredStartupHandler sDeferredStartupHandler; | 101 private static DeferredStartupHandler sDeferredStartupHandler; |
| 97 | 102 |
| 98 protected DeferredStartupHandler() { | 103 protected DeferredStartupHandler() { |
| 99 mAppContext = ContextUtils.getApplicationContext(); | 104 mAppContext = ContextUtils.getApplicationContext(); |
| 100 mDeferredTasks = new LinkedList<>(); | 105 mDeferredTasks = new LinkedList<>(); |
| 101 } | 106 } |
| 102 | 107 |
| 103 /** | 108 /** |
| 104 * Add the idle handler which will run deferred startup tasks in sequence wh en idle. This can | 109 * 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 | 110 * 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 } | 479 } |
| 475 | 480 |
| 476 /** | 481 /** |
| 477 * @return Whether deferred startup has been completed. | 482 * @return Whether deferred startup has been completed. |
| 478 */ | 483 */ |
| 479 @VisibleForTesting | 484 @VisibleForTesting |
| 480 public boolean isDeferredStartupCompleteForApp() { | 485 public boolean isDeferredStartupCompleteForApp() { |
| 481 return mDeferredStartupCompletedForApp; | 486 return mDeferredStartupCompletedForApp; |
| 482 } | 487 } |
| 483 } | 488 } |
| OLD | NEW |