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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/omaha/UpdateMenuItemHelper.java

Issue 2825173002: Launch "Update Chrome" menu item (Closed)
Patch Set: Created 3 years, 8 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
« no previous file with comments | « no previous file | chrome/browser/about_flags.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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.omaha; 5 package org.chromium.chrome.browser.omaha;
6 6
7 import android.animation.Animator; 7 import android.animation.Animator;
8 import android.animation.AnimatorListenerAdapter; 8 import android.animation.AnimatorListenerAdapter;
9 import android.animation.AnimatorSet; 9 import android.animation.AnimatorSet;
10 import android.animation.ObjectAnimator; 10 import android.animation.ObjectAnimator;
(...skipping 27 matching lines...) Expand all
38 /** 38 /**
39 * Contains logic for whether the update menu item should be shown, whether the update toolbar badge 39 * Contains logic for whether the update menu item should be shown, whether the update toolbar badge
40 * should be shown, and UMA logging for the update menu item. 40 * should be shown, and UMA logging for the update menu item.
41 */ 41 */
42 public class UpdateMenuItemHelper { 42 public class UpdateMenuItemHelper {
43 private static final String TAG = "UpdateMenuItemHelper"; 43 private static final String TAG = "UpdateMenuItemHelper";
44 44
45 // VariationsAssociatedData configs 45 // VariationsAssociatedData configs
46 private static final String FIELD_TRIAL_NAME = "UpdateMenuItem"; 46 private static final String FIELD_TRIAL_NAME = "UpdateMenuItem";
47 private static final String ENABLED_VALUE = "true"; 47 private static final String ENABLED_VALUE = "true";
48 private static final String ENABLE_UPDATE_MENU_ITEM = "enable_update_menu_it em";
49 private static final String ENABLE_UPDATE_BADGE = "enable_update_badge";
50 private static final String SHOW_SUMMARY = "show_summary";
51 private static final String USE_NEW_FEATURES_SUMMARY = "use_new_features_sum mary";
52 private static final String CUSTOM_SUMMARY = "custom_summary"; 48 private static final String CUSTOM_SUMMARY = "custom_summary";
53 49
54 // UMA constants for logging whether the menu item was clicked. 50 // UMA constants for logging whether the menu item was clicked.
55 private static final int ITEM_NOT_CLICKED = 0; 51 private static final int ITEM_NOT_CLICKED = 0;
56 private static final int ITEM_CLICKED_INTENT_LAUNCHED = 1; 52 private static final int ITEM_CLICKED_INTENT_LAUNCHED = 1;
57 private static final int ITEM_CLICKED_INTENT_FAILED = 2; 53 private static final int ITEM_CLICKED_INTENT_FAILED = 2;
58 private static final int ITEM_CLICKED_BOUNDARY = 3; 54 private static final int ITEM_CLICKED_BOUNDARY = 3;
59 55
60 // UMA constants for logging whether Chrome was updated after the menu item was clicked. 56 // UMA constants for logging whether Chrome was updated after the menu item was clicked.
61 private static final int UPDATED = 0; 57 private static final int UPDATED = 0;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 } 90 }
95 return sInstance; 91 return sInstance;
96 } 92 }
97 } 93 }
98 94
99 /** 95 /**
100 * Checks if the {@link OmahaClient} knows about an update. 96 * Checks if the {@link OmahaClient} knows about an update.
101 * @param activity The current {@link ChromeActivity}. 97 * @param activity The current {@link ChromeActivity}.
102 */ 98 */
103 public void checkForUpdateOnBackgroundThread(final ChromeActivity activity) { 99 public void checkForUpdateOnBackgroundThread(final ChromeActivity activity) {
104 if (!getBooleanParam(ENABLE_UPDATE_MENU_ITEM)
105 && !getBooleanParam(ChromeSwitches.FORCE_SHOW_UPDATE_MENU_ITEM)
106 && !getBooleanParam(ChromeSwitches.FORCE_SHOW_UPDATE_MENU_BADGE) ) {
107 return;
108 }
109
110 ThreadUtils.assertOnUiThread(); 100 ThreadUtils.assertOnUiThread();
111 101
112 if (mAlreadyCheckedForUpdates) { 102 if (mAlreadyCheckedForUpdates) {
113 if (activity.isActivityDestroyed()) return; 103 if (activity.isActivityDestroyed()) return;
114 activity.onCheckForUpdate(mUpdateAvailable); 104 activity.onCheckForUpdate(mUpdateAvailable);
115 return; 105 return;
116 } 106 }
117 107
118 mAlreadyCheckedForUpdates = true; 108 mAlreadyCheckedForUpdates = true;
119 109
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 143
154 /** 144 /**
155 * @param activity The current {@link ChromeActivity}. 145 * @param activity The current {@link ChromeActivity}.
156 * @return Whether the update menu item should be shown. 146 * @return Whether the update menu item should be shown.
157 */ 147 */
158 public boolean shouldShowMenuItem(ChromeActivity activity) { 148 public boolean shouldShowMenuItem(ChromeActivity activity) {
159 if (getBooleanParam(ChromeSwitches.FORCE_SHOW_UPDATE_MENU_ITEM)) { 149 if (getBooleanParam(ChromeSwitches.FORCE_SHOW_UPDATE_MENU_ITEM)) {
160 return true; 150 return true;
161 } 151 }
162 152
163 if (!getBooleanParam(ENABLE_UPDATE_MENU_ITEM)) {
164 return false;
165 }
166
167 return updateAvailable(activity); 153 return updateAvailable(activity);
168 } 154 }
169 155
170 /** 156 /**
171 * @param context The current {@link Context}. 157 * @param context The current {@link Context}.
172 * @return The string to use for summary text or the empty string if no summ ary should be shown. 158 * @return The string to use for summary text or the empty string if no summ ary should be shown.
173 */ 159 */
174 public String getMenuItemSummaryText(Context context) { 160 public String getMenuItemSummaryText(Context context) {
175 if (!getBooleanParam(SHOW_SUMMARY) && !getBooleanParam(USE_NEW_FEATURES_ SUMMARY)
176 && !getBooleanParam(CUSTOM_SUMMARY)) {
177 return "";
178 }
179
180 String customSummary = getStringParamValue(CUSTOM_SUMMARY); 161 String customSummary = getStringParamValue(CUSTOM_SUMMARY);
181 if (!TextUtils.isEmpty(customSummary)) { 162 if (!TextUtils.isEmpty(customSummary)) {
182 return customSummary; 163 return customSummary;
183 } 164 }
184 165
185 if (getBooleanParam(USE_NEW_FEATURES_SUMMARY)) {
186 return context.getResources().getString(R.string.menu_update_summary _new_features);
187 }
188
189 return context.getResources().getString(R.string.menu_update_summary_def ault); 166 return context.getResources().getString(R.string.menu_update_summary_def ault);
190 } 167 }
191 168
192 /** 169 /**
193 * @param activity The current {@link ChromeActivity}. 170 * @param activity The current {@link ChromeActivity}.
194 * @return Whether the update badge should be shown in the toolbar. 171 * @return Whether the update badge should be shown in the toolbar.
195 */ 172 */
196 public boolean shouldShowToolbarBadge(ChromeActivity activity) { 173 public boolean shouldShowToolbarBadge(ChromeActivity activity) {
197 if (getBooleanParam(ChromeSwitches.FORCE_SHOW_UPDATE_MENU_BADGE)) { 174 if (getBooleanParam(ChromeSwitches.FORCE_SHOW_UPDATE_MENU_BADGE)) {
198 return true; 175 return true;
199 } 176 }
200 177
201 // The badge is hidden if the update menu item has been clicked until th ere is an 178 // The badge is hidden if the update menu item has been clicked until th ere is an
202 // even newer version of Chrome available. 179 // even newer version of Chrome available.
203 String latestVersionWhenClicked = 180 String latestVersionWhenClicked =
204 PrefServiceBridge.getInstance().getLatestVersionWhenClickedUpdat eMenuItem(); 181 PrefServiceBridge.getInstance().getLatestVersionWhenClickedUpdat eMenuItem();
205 if (!getBooleanParam(ENABLE_UPDATE_BADGE) 182 if (TextUtils.equals(latestVersionWhenClicked, mLatestVersion)) {
206 || TextUtils.equals(latestVersionWhenClicked, mLatestVersion)) {
207 return false; 183 return false;
208 } 184 }
209 185
210 return updateAvailable(activity); 186 return updateAvailable(activity);
211 } 187 }
212 188
213 /** 189 /**
214 * Handles a click on the update menu item. 190 * Handles a click on the update menu item.
215 * @param activity The current {@link ChromeActivity}. 191 * @param activity The current {@link ChromeActivity}.
216 */ 192 */
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 return statFs.getAvailableBytes() / (1024 * 1024); 388 return statFs.getAvailableBytes() / (1024 * 1024);
413 } 389 }
414 390
415 @SuppressWarnings("deprecation") 391 @SuppressWarnings("deprecation")
416 private static long getSize(StatFs statFs) { 392 private static long getSize(StatFs statFs) {
417 int blockSize = statFs.getBlockSize(); 393 int blockSize = statFs.getBlockSize();
418 int availableBlocks = statFs.getAvailableBlocks(); 394 int availableBlocks = statFs.getAvailableBlocks();
419 return (blockSize * availableBlocks) / (1024 * 1024); 395 return (blockSize * availableBlocks) / (1024 * 1024);
420 } 396 }
421 } 397 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/about_flags.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698