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

Side by Side Diff: chrome/browser/banners/app_banner_settings_helper.cc

Issue 2620613006: Check if a PWA is installed before checking the service worker and icon. (Closed)
Patch Set: Add lost metrics back Created 3 years, 11 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #include "chrome/browser/banners/app_banner_settings_helper.h" 5 #include "chrome/browser/banners/app_banner_settings_helper.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <string> 10 #include <string>
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 // spamminess. 239 // spamminess.
240 if (event == APP_BANNER_EVENT_DID_ADD_TO_HOMESCREEN) 240 if (event == APP_BANNER_EVENT_DID_ADD_TO_HOMESCREEN)
241 settings->FlushLossyWebsiteSettings(); 241 settings->FlushLossyWebsiteSettings();
242 } 242 }
243 243
244 InstallableStatusCode AppBannerSettingsHelper::ShouldShowBanner( 244 InstallableStatusCode AppBannerSettingsHelper::ShouldShowBanner(
245 content::WebContents* web_contents, 245 content::WebContents* web_contents,
246 const GURL& origin_url, 246 const GURL& origin_url,
247 const std::string& package_name_or_start_url, 247 const std::string& package_name_or_start_url,
248 base::Time time) { 248 base::Time time) {
249 // Ignore all checks if the flag to do so is set.
250 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
dominickn 2017/01/10 22:51:59 This is covered by AppBannerSettingsHelper::HasSuf
251 switches::kBypassAppBannerEngagementChecks)) {
252 return NO_ERROR_DETECTED;
253 }
254
255 // Never show a banner when the package name or URL is empty. 249 // Never show a banner when the package name or URL is empty.
256 if (package_name_or_start_url.empty()) 250 if (package_name_or_start_url.empty())
257 return PACKAGE_NAME_OR_START_URL_EMPTY; 251 return PACKAGE_NAME_OR_START_URL_EMPTY;
258 252
259 // Don't show if it has been added to the homescreen. 253 // Don't show if it has been added to the homescreen.
260 base::Time added_time = 254 base::Time added_time =
261 GetSingleBannerEvent(web_contents, origin_url, package_name_or_start_url, 255 GetSingleBannerEvent(web_contents, origin_url, package_name_or_start_url,
262 APP_BANNER_EVENT_DID_ADD_TO_HOMESCREEN); 256 APP_BANNER_EVENT_DID_ADD_TO_HOMESCREEN);
263 if (!added_time.is_null()) 257 if (!added_time.is_null())
264 return ALREADY_INSTALLED; 258 return ALREADY_INSTALLED;
265 259
266 base::Time blocked_time = 260 base::Time blocked_time =
267 GetSingleBannerEvent(web_contents, origin_url, package_name_or_start_url, 261 GetSingleBannerEvent(web_contents, origin_url, package_name_or_start_url,
268 APP_BANNER_EVENT_DID_BLOCK); 262 APP_BANNER_EVENT_DID_BLOCK);
269 263
270 // Null times are in the distant past, so the delta between real times and 264 // Null times are in the distant past, so the delta between real times and
271 // null events will always be greater than the limits. 265 // null events will always be greater than the limits.
272 if (time - blocked_time < 266 if (time - blocked_time <
273 base::TimeDelta::FromDays(gDaysAfterDismissedToShow)) { 267 base::TimeDelta::FromDays(gDaysAfterDismissedToShow)) {
274 return PREVIOUSLY_BLOCKED; 268 return PREVIOUSLY_BLOCKED;
275 } 269 }
276 270
277 base::Time shown_time = 271 base::Time shown_time =
278 GetSingleBannerEvent(web_contents, origin_url, package_name_or_start_url, 272 GetSingleBannerEvent(web_contents, origin_url, package_name_or_start_url,
279 APP_BANNER_EVENT_DID_SHOW); 273 APP_BANNER_EVENT_DID_SHOW);
280 if (time - shown_time < base::TimeDelta::FromDays(gDaysAfterIgnoredToShow)) { 274 if (time - shown_time < base::TimeDelta::FromDays(gDaysAfterIgnoredToShow))
281 return PREVIOUSLY_IGNORED; 275 return PREVIOUSLY_IGNORED;
282 }
283 276
284 return NO_ERROR_DETECTED; 277 return NO_ERROR_DETECTED;
285 } 278 }
286 279
287 base::Time AppBannerSettingsHelper::GetSingleBannerEvent( 280 base::Time AppBannerSettingsHelper::GetSingleBannerEvent(
288 content::WebContents* web_contents, 281 content::WebContents* web_contents,
289 const GURL& origin_url, 282 const GURL& origin_url,
290 const std::string& package_name_or_start_url, 283 const std::string& package_name_or_start_url,
291 AppBannerEvent event) { 284 AppBannerEvent event) {
292 DCHECK(event < APP_BANNER_EVENT_NUM_EVENTS); 285 DCHECK(event < APP_BANNER_EVENT_NUM_EVENTS);
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 unsigned int language_option = 0; 399 unsigned int language_option = 0;
407 400
408 if (param.empty() || !base::StringToUint(param, &language_option) || 401 if (param.empty() || !base::StringToUint(param, &language_option) ||
409 language_option < LANGUAGE_OPTION_MIN || 402 language_option < LANGUAGE_OPTION_MIN ||
410 language_option > LANGUAGE_OPTION_MAX) { 403 language_option > LANGUAGE_OPTION_MAX) {
411 return LANGUAGE_OPTION_DEFAULT; 404 return LANGUAGE_OPTION_DEFAULT;
412 } 405 }
413 406
414 return static_cast<LanguageOption>(language_option); 407 return static_cast<LanguageOption>(language_option);
415 } 408 }
OLDNEW
« chrome/browser/banners/app_banner_manager.cc ('K') | « chrome/browser/banners/app_banner_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698