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

Side by Side Diff: chrome/android/java_staging/src/org/chromium/chrome/browser/compositor/overlays/strip/TabLoadTracker.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.compositor.overlays.strip;
6
7 import android.os.Handler;
8
9 /**
10 * {@code TabLoadTracker} is used to handle tracking whether or not to visually show if a tab is
11 * loading or not.
12 */
13 public class TabLoadTracker {
14 private static final long LOAD_FINISHED_VISUAL_DELAY_MS = 100;
15
16 private final Handler mHandler = new Handler();
17
18 // Callback Tracking State
19 private final int mId;
20 private final TabLoadTrackerCallback mCallback;
21
22 // Internal Loading State
23 private boolean mLoading;
24 private boolean mPageLoading;
25
26 /**
27 * The callback object to be notified of when the loading state changes.
28 */
29 public interface TabLoadTrackerCallback {
30 /**
31 * Called when the loading state tracked by this tab should visually cha nge.
32 * @param id The id of the Tab.
33 */
34 public void loadStateChanged(int id);
35 }
36
37 /**
38 * Creates an instance of the {@link TabLoadTracker} class.
39 * @param id The id of the tab to track for callback purposes.
40 * @param callback The {@link TabLoadTrackerCallback} to notify on loading s tate changes.
41 */
42 public TabLoadTracker(int id, TabLoadTrackerCallback callback) {
43 mId = id;
44 mCallback = callback;
45 }
46
47 /**
48 * Called when this tab has started loading.
49 */
50 public void pageLoadingStarted() {
51 if (!mPageLoading) {
52 mPageLoading = true;
53 mCallback.loadStateChanged(mId);
54 }
55 mHandler.removeCallbacks(mPageLoadFinishedRunnable);
56 }
57
58 /**
59 * Called when this tab has finished loading.
60 */
61 public void pageLoadingFinished() {
62 if (!mPageLoading) return;
63 mHandler.removeCallbacks(mPageLoadFinishedRunnable);
64 mHandler.postDelayed(mPageLoadFinishedRunnable, LOAD_FINISHED_VISUAL_DEL AY_MS);
65 }
66
67 /**
68 * Called when this tab has started loading resources.
69 */
70 public void loadingStarted() {
71 if (!mLoading) {
72 mLoading = true;
73 mCallback.loadStateChanged(mId);
74 }
75 mHandler.removeCallbacks(mLoadFinishedRunnable);
76 }
77
78 /**
79 * Called when this tab has finished loading resources.
80 */
81 public void loadingFinished() {
82 if (!mLoading) return;
83 mHandler.removeCallbacks(mLoadFinishedRunnable);
84 mHandler.postDelayed(mLoadFinishedRunnable, LOAD_FINISHED_VISUAL_DELAY_M S);
85 }
86
87 /**
88 * @return Whether or not this tab should be visually represented as loading .
89 */
90 public boolean isLoading() {
91 return mLoading || mPageLoading;
92 }
93
94 private Runnable mLoadFinishedRunnable = new Runnable() {
95 @Override
96 public void run() {
97 mLoading = false;
98 mCallback.loadStateChanged(mId);
99 }
100 };
101
102 private Runnable mPageLoadFinishedRunnable = new Runnable() {
103 @Override
104 public void run() {
105 mPageLoading = false;
106 mCallback.loadStateChanged(mId);
107 }
108 };
109 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698