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

Side by Side Diff: chrome/android/java_staging/src/org/chromium/chrome/browser/omaha/OmahaUpdateInfobar.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.ActivityNotFoundException;
8 import android.content.Context;
9 import android.content.Intent;
10 import android.net.Uri;
11 import android.os.SystemClock;
12 import android.util.Log;
13
14 import com.google.android.apps.chrome.R;
15
16 import org.chromium.base.VisibleForTesting;
17 import org.chromium.base.metrics.RecordHistogram;
18 import org.chromium.chrome.browser.infobar.ConfirmInfoBar;
19 import org.chromium.chrome.browser.infobar.InfoBar;
20 import org.chromium.chrome.browser.infobar.InfoBarListeners;
21
22 import java.util.concurrent.TimeUnit;
23
24
25 /**
26 * An InfoBar implementation that displays a message and a button that sends a u ser to the
27 * given URL.
28 */
29 public class OmahaUpdateInfobar extends ConfirmInfoBar {
30 private static final String TAG = "OmahaUpdateInfobar";
31 private static final int ACTION_CLOSED = 0;
32 private static final int ACTION_CLICKED_UPDATE_SUCCESS = 1;
33 private static final int ACTION_CLICKED_UPDATE_FAIL = 2;
34 private static final int ACTION_DISMISSED = 3;
35 private static final int ACTION_MAX = 3;
36
37 private String mUrl;
38 private Context mActivityContext;
39 private boolean mActionTaken;
40 private long mShownTime;
41
42 /**
43 * Listens for the InfoBar being dismissed and checks whether it was caused by a user action
44 * on the InfoBar or another event which caused the InfoBar to be dimissed i mplicitly
45 * (e.g. user entered a new url in the omnibox.)
46 */
47 private static class DismissListener implements InfoBarListeners.Confirm {
48 @Override
49 public void onInfoBarDismissed(InfoBar infoBar) {
50 assert infoBar instanceof OmahaUpdateInfobar;
51
52 OmahaUpdateInfobar infoBarInstance = (OmahaUpdateInfobar) infoBar;
53 // If the user hasn't taken an action and the infobar is getting dis missed, then
54 // record that it was dismissed.
55 if (!infoBarInstance.mActionTaken) {
56 infoBarInstance.recordHistograms(ACTION_DISMISSED);
57 }
58 }
59
60 @Override
61 public void onConfirmInfoBarButtonClicked(ConfirmInfoBar infoBar, boolea n confirm) {
62 // Ignored.
63 }
64 }
65
66 public OmahaUpdateInfobar(Context activityContext, String message, String bu ttonMessage,
67 String url) {
68 super(0, new DismissListener(), R.drawable.infobar_warning, null, messag e, null,
69 buttonMessage, null);
70 mActivityContext = activityContext;
71 mUrl = url;
72 mShownTime = SystemClock.uptimeMillis();
73 }
74
75 private void recordHistograms(int action) {
76 RecordHistogram.recordEnumeratedHistogram("GoogleUpdate.InfoBar.ActionTa ken",
77 action, ACTION_MAX);
78 RecordHistogram.recordMediumTimesHistogram("GoogleUpdate.InfoBar.TimeSho wn",
79 SystemClock.uptimeMillis() - mShownTime, TimeUnit.MILLISECONDS);
80 }
81
82 @Override
83 public void onCloseButtonClicked() {
84 mActionTaken = true;
85 recordHistograms(ACTION_CLOSED);
86 super.onCloseButtonClicked();
87 }
88
89 @Override
90 public void onButtonClicked(boolean isPrimaryButton) {
91 mActionTaken = true;
92 dismissJavaOnlyInfoBar();
93
94 // Fire an intent to open the URL.
95 try {
96 Intent launchIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(mUrl) );
97 mActivityContext.startActivity(launchIntent);
98 recordHistograms(ACTION_CLICKED_UPDATE_SUCCESS);
99 } catch (ActivityNotFoundException e) {
100 Log.e(TAG, "Failed to launch Activity for: " + mUrl);
101 recordHistograms(ACTION_CLICKED_UPDATE_FAIL);
102 }
103 }
104
105 /** Returns the URL that is supposed to be opened when the button is clicked . */
106 @VisibleForTesting
107 public String getUrl() {
108 return mUrl;
109 }
110 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698