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

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

Issue 2130173002: Add metrics for app banner preventDefault() and prompt(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2785
Patch Set: Created 4 years, 5 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/banners/app_banner_metrics.h » ('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 #include "chrome/browser/banners/app_banner_data_fetcher.h" 5 #include "chrome/browser/banners/app_banner_data_fetcher.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 referrer_.erase(); 108 referrer_.erase();
109 web_contents->HasManifest( 109 web_contents->HasManifest(
110 base::Bind(&AppBannerDataFetcher::OnDidHasManifest, this)); 110 base::Bind(&AppBannerDataFetcher::OnDidHasManifest, this));
111 } 111 }
112 112
113 void AppBannerDataFetcher::Cancel() { 113 void AppBannerDataFetcher::Cancel() {
114 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 114 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
115 if (is_active_) { 115 if (is_active_) {
116 FOR_EACH_OBSERVER(Observer, observer_list_, 116 FOR_EACH_OBSERVER(Observer, observer_list_,
117 OnDecidedWhetherToShow(this, false)); 117 OnDecidedWhetherToShow(this, false));
118 if (was_canceled_by_page_ && !page_requested_prompt_) {
119 TrackBeforeInstallEvent(
120 BEFORE_INSTALL_EVENT_PROMPT_NOT_CALLED_AFTER_PREVENT_DEFAULT);
121 }
122
118 is_active_ = false; 123 is_active_ = false;
119 was_canceled_by_page_ = false; 124 was_canceled_by_page_ = false;
120 page_requested_prompt_ = false; 125 page_requested_prompt_ = false;
121 referrer_.erase(); 126 referrer_.erase();
122 } 127 }
123 } 128 }
124 129
125 void AppBannerDataFetcher::ReplaceWebContents( 130 void AppBannerDataFetcher::ReplaceWebContents(
126 content::WebContents* web_contents) { 131 content::WebContents* web_contents) {
127 Observe(web_contents); 132 Observe(web_contents);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 // called if a redisplay isn't asked for. 186 // called if a redisplay isn't asked for.
182 // 187 //
183 // The redisplay request may be received before the Cancel prompt reply 188 // The redisplay request may be received before the Cancel prompt reply
184 // *after* if it is made before the beforeinstallprompt event handler 189 // *after* if it is made before the beforeinstallprompt event handler
185 // concludes (e.g. in the event handler itself), so allow the pipeline 190 // concludes (e.g. in the event handler itself), so allow the pipeline
186 // to continue in this case. 191 // to continue in this case.
187 // 192 //
188 // Stash the referrer for the case where the banner is redisplayed. 193 // Stash the referrer for the case where the banner is redisplayed.
189 if (reply == blink::WebAppBannerPromptReply::Cancel && 194 if (reply == blink::WebAppBannerPromptReply::Cancel &&
190 !page_requested_prompt_) { 195 !page_requested_prompt_) {
196 TrackBeforeInstallEvent(BEFORE_INSTALL_EVENT_PREVENT_DEFAULT_CALLED);
191 was_canceled_by_page_ = true; 197 was_canceled_by_page_ = true;
192 referrer_ = referrer; 198 referrer_ = referrer;
193 OutputDeveloperNotShownMessage(web_contents, kRendererRequestCancel, 199 OutputDeveloperNotShownMessage(web_contents, kRendererRequestCancel,
194 is_debug_mode_); 200 is_debug_mode_);
195 return; 201 return;
196 } 202 }
197 203
204 // If we haven't yet returned, but either of |was_canceled_by_page_| or
205 // |page_requested_prompt_| is true, the page has requested a delayed showing
206 // of the prompt. Otherwise, the prompt was never canceled by the page.
207 if (was_canceled_by_page_ || page_requested_prompt_) {
208 TrackBeforeInstallEvent(
209 BEFORE_INSTALL_EVENT_PROMPT_CALLED_AFTER_PREVENT_DEFAULT);
210 was_canceled_by_page_ = false;
211 } else {
212 TrackBeforeInstallEvent(BEFORE_INSTALL_EVENT_NO_ACTION);
213 }
214
198 AppBannerSettingsHelper::RecordMinutesFromFirstVisitToShow( 215 AppBannerSettingsHelper::RecordMinutesFromFirstVisitToShow(
199 web_contents, validated_url_, GetAppIdentifier(), GetCurrentTime()); 216 web_contents, validated_url_, GetAppIdentifier(), GetCurrentTime());
200 217
201 // Definitely going to show the banner now. 218 // Definitely going to show the banner now.
202 FOR_EACH_OBSERVER(Observer, observer_list_, 219 FOR_EACH_OBSERVER(Observer, observer_list_,
203 OnDecidedWhetherToShow(this, true)); 220 OnDecidedWhetherToShow(this, true));
204 221
222 TrackBeforeInstallEvent(BEFORE_INSTALL_EVENT_COMPLETE);
205 ShowBanner(app_icon_.get(), app_title_, referrer); 223 ShowBanner(app_icon_.get(), app_title_, referrer);
206 is_active_ = false; 224 is_active_ = false;
207 } 225 }
208 226
209 void AppBannerDataFetcher::OnRequestShowAppBanner( 227 void AppBannerDataFetcher::OnRequestShowAppBanner(
210 content::RenderFrameHost* render_frame_host, 228 content::RenderFrameHost* render_frame_host,
211 int request_id) { 229 int request_id) {
212 if (was_canceled_by_page_) { 230 if (was_canceled_by_page_) {
213 // Simulate an "OK" from the website to restart the banner display pipeline. 231 // Simulate an "OK" from the website to restart the banner display pipeline.
214 was_canceled_by_page_ = false; 232 // Don't reset |was_canceled_by_page_| yet for metrics purposes.
215 OnBannerPromptReply(render_frame_host, request_id, 233 OnBannerPromptReply(render_frame_host, request_id,
216 blink::WebAppBannerPromptReply::None, referrer_); 234 blink::WebAppBannerPromptReply::None, referrer_);
217 } else { 235 } else {
218 // Log that the prompt request was made for when we get the prompt reply. 236 // Log that the prompt request was made for when we get the prompt reply.
219 page_requested_prompt_ = true; 237 page_requested_prompt_ = true;
220 } 238 }
221 } 239 }
222 240
223 AppBannerDataFetcher::~AppBannerDataFetcher() { 241 AppBannerDataFetcher::~AppBannerDataFetcher() {
224 FOR_EACH_OBSERVER(Observer, observer_list_, OnFetcherDestroyed(this)); 242 FOR_EACH_OBSERVER(Observer, observer_list_, OnFetcherDestroyed(this));
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 RecordCouldShowBanner(); 414 RecordCouldShowBanner();
397 if (!is_debug_mode_ && !CheckIfShouldShowBanner()) { 415 if (!is_debug_mode_ && !CheckIfShouldShowBanner()) {
398 // At this point, the only possible case is that the banner has been added 416 // At this point, the only possible case is that the banner has been added
399 // to the homescreen, given all of the other checks that have been made. 417 // to the homescreen, given all of the other checks that have been made.
400 Cancel(); 418 Cancel();
401 return; 419 return;
402 } 420 }
403 421
404 app_icon_.reset(new SkBitmap(bitmap)); 422 app_icon_.reset(new SkBitmap(bitmap));
405 event_request_id_ = ++gCurrentRequestID; 423 event_request_id_ = ++gCurrentRequestID;
424
425 TrackBeforeInstallEvent(BEFORE_INSTALL_EVENT_CREATED);
406 web_contents->GetMainFrame()->Send( 426 web_contents->GetMainFrame()->Send(
407 new ChromeViewMsg_AppBannerPromptRequest( 427 new ChromeViewMsg_AppBannerPromptRequest(
408 web_contents->GetMainFrame()->GetRoutingID(), 428 web_contents->GetMainFrame()->GetRoutingID(),
409 event_request_id_, 429 event_request_id_,
410 GetBannerType())); 430 GetBannerType()));
411 } 431 }
412 432
413 bool AppBannerDataFetcher::IsWebAppInstalled( 433 bool AppBannerDataFetcher::IsWebAppInstalled(
414 content::BrowserContext* browser_context, 434 content::BrowserContext* browser_context,
415 const GURL& start_url) { 435 const GURL& start_url) {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 499
480 if (!DoesManifestContainRequiredIcon(manifest)) { 500 if (!DoesManifestContainRequiredIcon(manifest)) {
481 OutputDeveloperNotShownMessage(web_contents, kManifestMissingSuitableIcon, 501 OutputDeveloperNotShownMessage(web_contents, kManifestMissingSuitableIcon,
482 is_debug_mode); 502 is_debug_mode);
483 return false; 503 return false;
484 } 504 }
485 return true; 505 return true;
486 } 506 }
487 507
488 } // namespace banners 508 } // namespace banners
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/banners/app_banner_metrics.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698