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

Side by Side Diff: chrome/android/java_staging/src/org/chromium/chrome/browser/omaha/UpdateInfoBarHelper.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.omaha;
6
7 import android.content.res.Resources;
8 import android.os.AsyncTask;
9
10 import com.google.android.apps.chrome.R;
11
12 import org.chromium.base.ThreadUtils;
13 import org.chromium.chrome.browser.ChromeActivity;
14 import org.chromium.chrome.browser.Tab;
15
16 /**
17 * Shows an InfoBar indicating that a new version of Chrome is available.
18 */
19 public class UpdateInfoBarHelper {
20 /** Whether OmahaClient has already been checked for an update. */
21 private boolean mAlreadyCheckedForUpdates;
22
23 /** Whether to show the InfoBar indicating a new version is available. */
24 private boolean mMustShowInfoBar;
25
26 /** URL to direct the user to when Omaha detects a newer version available. */
27 private String mUpdateURL;
28
29 /** Checks if the OmahaClient knows about an update. */
30 public void checkForUpdateOnBackgroundThread(final ChromeActivity activity) {
31 ThreadUtils.assertOnUiThread();
32
33 if (mAlreadyCheckedForUpdates) return;
34 mAlreadyCheckedForUpdates = true;
35
36 new AsyncTask<Void, Void, Void>() {
37 @Override
38 protected Void doInBackground(Void... params) {
39 if (OmahaClient.isNewerVersionAvailable(activity)) {
40 mUpdateURL = OmahaClient.getMarketURL(activity);
41 mMustShowInfoBar = true;
42 } else {
43 mMustShowInfoBar = false;
44 }
45 return null;
46 }
47
48 @Override
49 protected void onPostExecute(Void result) {
50 if (activity.isActivityDestroyed()) return;
51 showUpdateInfobarIfNecessary(activity);
52 }
53 }.execute();
54 }
55
56 /** Shows the InfoBar if it needs to be shown. */
57 public void showUpdateInfobarIfNecessary(ChromeActivity activity) {
58 if (mMustShowInfoBar) showUpdateInfoBar(activity);
59 }
60
61 /** Shows an InfoBar indicating that a new version of Chrome is available. * /
62 private void showUpdateInfoBar(ChromeActivity activity) {
63 ThreadUtils.assertOnUiThread();
64
65 // Don't show the InfoBar if it doesn't make sense to.
66 Tab currentTab = activity.getActivityTab();
67 boolean tabIsInvalid = currentTab == null || currentTab.isNativePage();
68 boolean mayShowUpdateInfoBar = activity.mayShowUpdateInfoBar();
69 boolean urlIsInvalid = mUpdateURL == null;
70 if (tabIsInvalid || !mayShowUpdateInfoBar || urlIsInvalid) {
71 mMustShowInfoBar = true;
72 return;
73 }
74
75 // Create and show the InfoBar.
76 Resources resources = activity.getResources();
77 String message = resources.getString(R.string.update_available_infobar);
78 String button = resources.getString(R.string.update_available_infobar_bu tton);
79 OmahaUpdateInfobar updateBar =
80 new OmahaUpdateInfobar(activity, message, button, mUpdateURL);
81 currentTab.getInfoBarContainer().addInfoBar(updateBar);
82 mMustShowInfoBar = false;
83 }
84 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698