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

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

Issue 2620613006: Check if a PWA is installed before checking the service worker and icon. (Closed)
Patch Set: Add missing enum value 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 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 #include "chrome/browser/banners/app_banner_manager.h" 5 #include "chrome/browser/banners/app_banner_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 233
234 manifest_url_ = data.manifest_url; 234 manifest_url_ = data.manifest_url;
235 manifest_ = data.manifest; 235 manifest_ = data.manifest;
236 app_title_ = (manifest_.name.is_null()) ? manifest_.short_name.string() 236 app_title_ = (manifest_.name.is_null()) ? manifest_.short_name.string()
237 : manifest_.name.string(); 237 : manifest_.name.string();
238 238
239 PerformInstallableCheck(); 239 PerformInstallableCheck();
240 } 240 }
241 241
242 void AppBannerManager::PerformInstallableCheck() { 242 void AppBannerManager::PerformInstallableCheck() {
243 if (IsWebAppInstalled(web_contents()->GetBrowserContext(), 243 if (!CheckIfShouldShowBanner())
244 manifest_.start_url, manifest_url_) &&
245 !IsDebugMode()) {
246 ReportStatus(web_contents(), ALREADY_INSTALLED);
247 Stop();
248 }
249
250 if (!is_active_)
251 return; 244 return;
252 245
253 // Fetch and verify the other required information. 246 // Fetch and verify the other required information.
254 manager_->GetData(ParamsToPerformInstallableCheck(GetIdealIconSizeInPx(), 247 manager_->GetData(ParamsToPerformInstallableCheck(GetIdealIconSizeInPx(),
255 GetMinimumIconSizeInPx()), 248 GetMinimumIconSizeInPx()),
256 base::Bind(&AppBannerManager::OnDidPerformInstallableCheck, 249 base::Bind(&AppBannerManager::OnDidPerformInstallableCheck,
257 GetWeakPtr())); 250 GetWeakPtr()));
258 } 251 }
259 252
260 void AppBannerManager::OnDidPerformInstallableCheck( 253 void AppBannerManager::OnDidPerformInstallableCheck(
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 was_canceled_by_page_ = false; 324 was_canceled_by_page_ = false;
332 page_requested_prompt_ = false; 325 page_requested_prompt_ = false;
333 need_to_log_status_ = false; 326 need_to_log_status_ = false;
334 validated_url_ = GURL(); 327 validated_url_ = GURL();
335 referrer_.erase(); 328 referrer_.erase();
336 } 329 }
337 330
338 void AppBannerManager::SendBannerPromptRequest() { 331 void AppBannerManager::SendBannerPromptRequest() {
339 RecordCouldShowBanner(); 332 RecordCouldShowBanner();
340 333
341 // Given all of the other checks that have been made, the only possible reason
342 // for stopping now is that the app has been added to the homescreen.
343 if (!IsDebugMode() && !CheckIfShouldShowBanner()) {
344 Stop();
345 return;
346 }
347
348 TrackBeforeInstallEvent(BEFORE_INSTALL_EVENT_CREATED); 334 TrackBeforeInstallEvent(BEFORE_INSTALL_EVENT_CREATED);
349 event_request_id_ = ++gCurrentRequestID; 335 event_request_id_ = ++gCurrentRequestID;
350 336
351 web_contents()->GetMainFrame()->GetRemoteInterfaces()->GetInterface( 337 web_contents()->GetMainFrame()->GetRemoteInterfaces()->GetInterface(
352 mojo::MakeRequest(&controller_)); 338 mojo::MakeRequest(&controller_));
353 339
354 controller_->BannerPromptRequest( 340 controller_->BannerPromptRequest(
355 binding_.CreateInterfacePtrAndBind(), mojo::MakeRequest(&event_), 341 binding_.CreateInterfacePtrAndBind(), mojo::MakeRequest(&event_),
356 {GetBannerType()}, 342 {GetBannerType()},
357 base::Bind(&AppBannerManager::OnBannerPromptReply, GetWeakPtr())); 343 base::Bind(&AppBannerManager::OnBannerPromptReply, GetWeakPtr()));
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 void AppBannerManager::RecordCouldShowBanner() { 429 void AppBannerManager::RecordCouldShowBanner() {
444 content::WebContents* contents = web_contents(); 430 content::WebContents* contents = web_contents();
445 DCHECK(contents); 431 DCHECK(contents);
446 432
447 AppBannerSettingsHelper::RecordBannerEvent( 433 AppBannerSettingsHelper::RecordBannerEvent(
448 contents, validated_url_, GetAppIdentifier(), 434 contents, validated_url_, GetAppIdentifier(),
449 AppBannerSettingsHelper::APP_BANNER_EVENT_COULD_SHOW, GetCurrentTime()); 435 AppBannerSettingsHelper::APP_BANNER_EVENT_COULD_SHOW, GetCurrentTime());
450 } 436 }
451 437
452 bool AppBannerManager::CheckIfShouldShowBanner() { 438 bool AppBannerManager::CheckIfShouldShowBanner() {
439 if (IsDebugMode())
440 return true;
441
442 // Check whether we are permitted to show the banner. If we have already
443 // added this site to homescreen, or if the banner has been shown too
444 // recently, prevent the banner from being shown.
453 content::WebContents* contents = web_contents(); 445 content::WebContents* contents = web_contents();
454 DCHECK(contents);
455
456 InstallableStatusCode code = AppBannerSettingsHelper::ShouldShowBanner( 446 InstallableStatusCode code = AppBannerSettingsHelper::ShouldShowBanner(
457 contents, validated_url_, GetAppIdentifier(), GetCurrentTime()); 447 contents, validated_url_, GetAppIdentifier(), GetCurrentTime());
458 if (code == NO_ERROR_DETECTED)
459 return true;
460 448
461 switch (code) { 449 if (code == NO_ERROR_DETECTED &&
462 case ALREADY_INSTALLED: 450 IsWebAppInstalled(contents->GetBrowserContext(), manifest_.start_url,
463 banners::TrackDisplayEvent(banners::DISPLAY_EVENT_INSTALLED_PREVIOUSLY); 451 manifest_url_)) {
464 break; 452 code = ALREADY_INSTALLED;
465 case PREVIOUSLY_BLOCKED:
466 banners::TrackDisplayEvent(banners::DISPLAY_EVENT_BLOCKED_PREVIOUSLY);
467 break;
468 case PREVIOUSLY_IGNORED:
469 banners::TrackDisplayEvent(banners::DISPLAY_EVENT_IGNORED_PREVIOUSLY);
470 break;
471 case INSUFFICIENT_ENGAGEMENT:
472 banners::TrackDisplayEvent(banners::DISPLAY_EVENT_NOT_VISITED_ENOUGH);
473 break;
474 default:
475 break;
476 } 453 }
477 454
478 // If we are in debug mode, AppBannerSettingsHelper::ShouldShowBanner must 455 if (code != NO_ERROR_DETECTED) {
479 // return NO_ERROR_DETECTED (bypass flag is set) or we must not have entered 456 switch (code) {
480 // this method. 457 case ALREADY_INSTALLED:
481 DCHECK(!IsDebugMode()); 458 banners::TrackDisplayEvent(banners::DISPLAY_EVENT_INSTALLED_PREVIOUSLY);
482 ReportStatus(web_contents(), code); 459 break;
483 return false; 460 case PREVIOUSLY_BLOCKED:
461 banners::TrackDisplayEvent(banners::DISPLAY_EVENT_BLOCKED_PREVIOUSLY);
462 break;
463 case PREVIOUSLY_IGNORED:
464 banners::TrackDisplayEvent(banners::DISPLAY_EVENT_IGNORED_PREVIOUSLY);
465 break;
466 case PACKAGE_NAME_OR_START_URL_EMPTY:
467 break;
468 default:
469 NOTREACHED();
470 }
471 ReportStatus(contents, code);
472 Stop();
473 return false;
474 }
475 return true;
484 } 476 }
485 477
486 void AppBannerManager::OnBannerPromptReply( 478 void AppBannerManager::OnBannerPromptReply(
487 blink::mojom::AppBannerPromptReply reply, 479 blink::mojom::AppBannerPromptReply reply,
488 const std::string& referrer) { 480 const std::string& referrer) {
489 // We don't need the controller any more, so reset it so the Blink-side object 481 // We don't need the controller any more, so reset it so the Blink-side object
490 // is destroyed. 482 // is destroyed.
491 controller_.reset(); 483 controller_.reset();
492 content::WebContents* contents = web_contents(); 484 content::WebContents* contents = web_contents();
493 485
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 // Simulate a non-canceled OnBannerPromptReply to show the delayed banner. 528 // Simulate a non-canceled OnBannerPromptReply to show the delayed banner.
537 // Don't reset |was_canceled_by_page_| yet for metrics purposes. 529 // Don't reset |was_canceled_by_page_| yet for metrics purposes.
538 OnBannerPromptReply(blink::mojom::AppBannerPromptReply::NONE, referrer_); 530 OnBannerPromptReply(blink::mojom::AppBannerPromptReply::NONE, referrer_);
539 } else { 531 } else {
540 // Log that the prompt request was made for when we get the prompt reply. 532 // Log that the prompt request was made for when we get the prompt reply.
541 page_requested_prompt_ = true; 533 page_requested_prompt_ = true;
542 } 534 }
543 } 535 }
544 536
545 } // namespace banners 537 } // namespace banners
OLDNEW
« no previous file with comments | « chrome/browser/banners/app_banner_manager.h ('k') | chrome/browser/banners/app_banner_settings_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698