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

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

Issue 1129103003: Log messages regarding why app banners aren't displayed to the console (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Factoring out log messages into constants 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
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/strings/string_util.h" 8 #include "base/strings/string_util.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/banners/app_banner_debug_log.h"
10 #include "chrome/browser/banners/app_banner_metrics.h" 11 #include "chrome/browser/banners/app_banner_metrics.h"
11 #include "chrome/browser/banners/app_banner_settings_helper.h" 12 #include "chrome/browser/banners/app_banner_settings_helper.h"
12 #include "chrome/browser/bitmap_fetcher/bitmap_fetcher.h" 13 #include "chrome/browser/bitmap_fetcher/bitmap_fetcher.h"
13 #include "chrome/browser/browser_process.h" 14 #include "chrome/browser/browser_process.h"
14 #include "chrome/browser/infobars/infobar_service.h" 15 #include "chrome/browser/infobars/infobar_service.h"
15 #include "chrome/browser/manifest/manifest_icon_selector.h" 16 #include "chrome/browser/manifest/manifest_icon_selector.h"
16 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/common/render_messages.h" 18 #include "chrome/common/render_messages.h"
18 #include "components/infobars/core/infobar.h" 19 #include "components/infobars/core/infobar.h"
19 #include "components/rappor/rappor_utils.h" 20 #include "components/rappor/rappor_utils.h"
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 IPC_END_MESSAGE_MAP() 134 IPC_END_MESSAGE_MAP()
134 135
135 return handled; 136 return handled;
136 } 137 }
137 138
138 void AppBannerDataFetcher::OnBannerPromptReply( 139 void AppBannerDataFetcher::OnBannerPromptReply(
139 content::RenderFrameHost* render_frame_host, 140 content::RenderFrameHost* render_frame_host,
140 int request_id, 141 int request_id,
141 blink::WebAppBannerPromptReply reply) { 142 blink::WebAppBannerPromptReply reply) {
142 content::WebContents* web_contents = GetWebContents(); 143 content::WebContents* web_contents = GetWebContents();
143 if (!is_active_ || !web_contents || request_id != event_request_id_) { 144 if (!CheckFetcherIsStillAlive(web_contents) ||
145 request_id != event_request_id_) {
144 Cancel(); 146 Cancel();
145 return; 147 return;
146 } 148 }
147 149
148 // The renderer might have requested the prompt to be canceled. 150 // The renderer might have requested the prompt to be canceled.
149 if (reply == blink::WebAppBannerPromptReply::Cancel) { 151 if (reply == blink::WebAppBannerPromptReply::Cancel) {
152 OutputDeveloperNotShownMessage(web_contents, kRendererRequestCancel);
150 Cancel(); 153 Cancel();
151 return; 154 return;
152 } 155 }
153 156
154 // Definitely going to show the banner now. 157 // Definitely going to show the banner now.
155 FOR_EACH_OBSERVER(Observer, observer_list_, 158 FOR_EACH_OBSERVER(Observer, observer_list_,
156 OnDecidedWhetherToShow(this, true)); 159 OnDecidedWhetherToShow(this, true));
157 160
158 infobars::InfoBar* infobar = CreateBanner(app_icon_.get(), app_title_); 161 infobars::InfoBar* infobar = CreateBanner(app_icon_.get(), app_title_);
159 if (infobar) { 162 if (infobar) {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 GetCurrentTime()); 227 GetCurrentTime());
225 rappor::SampleDomainAndRegistryFromGURL(g_browser_process->rappor_service(), 228 rappor::SampleDomainAndRegistryFromGURL(g_browser_process->rappor_service(),
226 event_name, 229 event_name,
227 web_contents->GetURL()); 230 web_contents->GetURL());
228 banners::TrackDisplayEvent(DISPLAY_EVENT_CREATED); 231 banners::TrackDisplayEvent(DISPLAY_EVENT_CREATED);
229 } 232 }
230 233
231 void AppBannerDataFetcher::OnDidGetManifest( 234 void AppBannerDataFetcher::OnDidGetManifest(
232 const content::Manifest& manifest) { 235 const content::Manifest& manifest) {
233 content::WebContents* web_contents = GetWebContents(); 236 content::WebContents* web_contents = GetWebContents();
234 if (!is_active_ || !web_contents || manifest.IsEmpty()) { 237 if (!CheckFetcherIsStillAlive(web_contents)) {
238 Cancel();
239 return;
240 } else if (manifest.IsEmpty()) {
benwells 2015/05/13 02:55:20 Nit: no else after return.
dominickn (DO NOT USE) 2015/05/13 03:08:06 Done.
241 OutputDeveloperNotShownMessage(web_contents, kManifestEmpty);
235 Cancel(); 242 Cancel();
236 return; 243 return;
237 } 244 }
238 245
239 if (manifest.prefer_related_applications && 246 if (manifest.prefer_related_applications &&
240 manifest.related_applications.size()) { 247 manifest.related_applications.size()) {
241 for (const auto& application : manifest.related_applications) { 248 for (const auto& application : manifest.related_applications) {
242 std::string platform = base::UTF16ToUTF8(application.platform.string()); 249 std::string platform = base::UTF16ToUTF8(application.platform.string());
243 std::string id = base::UTF16ToUTF8(application.id.string()); 250 std::string id = base::UTF16ToUTF8(application.id.string());
244 if (weak_delegate_->HandleNonWebApp(platform, application.url, id)) 251 if (weak_delegate_->HandleNonWebApp(platform, application.url, id))
245 return; 252 return;
246 } 253 }
247 } 254 }
248 255
249 if (!IsManifestValidForWebApp(manifest)) { 256 if (!IsManifestValidForWebApp(manifest, web_contents)) {
250 Cancel(); 257 Cancel();
251 return; 258 return;
252 } 259 }
253 260
254 banners::TrackDisplayEvent(DISPLAY_EVENT_BANNER_REQUESTED); 261 banners::TrackDisplayEvent(DISPLAY_EVENT_BANNER_REQUESTED);
255 262
256 web_app_data_ = manifest; 263 web_app_data_ = manifest;
257 app_title_ = web_app_data_.name.string(); 264 app_title_ = web_app_data_.name.string();
258 265
259 // Check to see if there is a single service worker controlling this page 266 // Check to see if there is a single service worker controlling this page
260 // and the manifest's start url. 267 // and the manifest's start url.
261 Profile* profile = 268 Profile* profile =
262 Profile::FromBrowserContext(web_contents->GetBrowserContext()); 269 Profile::FromBrowserContext(web_contents->GetBrowserContext());
263 content::StoragePartition* storage_partition = 270 content::StoragePartition* storage_partition =
264 content::BrowserContext::GetStoragePartition( 271 content::BrowserContext::GetStoragePartition(
265 profile, web_contents->GetSiteInstance()); 272 profile, web_contents->GetSiteInstance());
266 DCHECK(storage_partition); 273 DCHECK(storage_partition);
267 274
268 storage_partition->GetServiceWorkerContext()->CheckHasServiceWorker( 275 storage_partition->GetServiceWorkerContext()->CheckHasServiceWorker(
269 validated_url_, manifest.start_url, 276 validated_url_, manifest.start_url,
270 base::Bind(&AppBannerDataFetcher::OnDidCheckHasServiceWorker, 277 base::Bind(&AppBannerDataFetcher::OnDidCheckHasServiceWorker,
271 this)); 278 this));
272 } 279 }
273 280
274 void AppBannerDataFetcher::OnDidCheckHasServiceWorker( 281 void AppBannerDataFetcher::OnDidCheckHasServiceWorker(
275 bool has_service_worker) { 282 bool has_service_worker) {
276 content::WebContents* web_contents = GetWebContents(); 283 content::WebContents* web_contents = GetWebContents();
277 if (!is_active_ || !web_contents) { 284 if (!CheckFetcherIsStillAlive(web_contents)) {
278 Cancel(); 285 Cancel();
279 return; 286 return;
280 } 287 }
281 288
282 if (has_service_worker) { 289 if (has_service_worker) {
283 // Create an infobar to promote the manifest's app. 290 // Create an infobar to promote the manifest's app.
284 GURL icon_url = 291 GURL icon_url =
285 ManifestIconSelector::FindBestMatchingIcon( 292 ManifestIconSelector::FindBestMatchingIcon(
286 web_app_data_.icons, 293 web_app_data_.icons,
287 ideal_icon_size_, 294 ideal_icon_size_,
288 gfx::Screen::GetScreenFor(web_contents->GetNativeView())); 295 gfx::Screen::GetScreenFor(web_contents->GetNativeView()));
289 if (!icon_url.is_empty()) { 296 if (!icon_url.is_empty()) {
290 FetchIcon(icon_url); 297 FetchIcon(icon_url);
291 return; 298 return;
292 } 299 }
300 OutputDeveloperNotShownMessage(web_contents, kCannotDetermineBestIcon);
293 } else { 301 } else {
294 TrackDisplayEvent(DISPLAY_EVENT_LACKS_SERVICE_WORKER); 302 TrackDisplayEvent(DISPLAY_EVENT_LACKS_SERVICE_WORKER);
303 OutputDeveloperNotShownMessage(web_contents, kNoMatchingServiceWorker);
295 } 304 }
296 305
297 Cancel(); 306 Cancel();
298 } 307 }
299 308
300 void AppBannerDataFetcher::OnFetchComplete(const GURL& url, 309 void AppBannerDataFetcher::OnFetchComplete(const GURL& url,
301 const SkBitmap* icon) { 310 const SkBitmap* icon) {
302 if (is_active_) 311 if (is_active_)
303 ShowBanner(icon); 312 ShowBanner(icon);
304 313
305 Release(); 314 Release();
306 } 315 }
307 316
308 void AppBannerDataFetcher::ShowBanner(const SkBitmap* icon) { 317 void AppBannerDataFetcher::ShowBanner(const SkBitmap* icon) {
309 content::WebContents* web_contents = GetWebContents(); 318 content::WebContents* web_contents = GetWebContents();
310 if (!is_active_ || !web_contents || !icon) { 319 if (!CheckFetcherIsStillAlive(web_contents)) {
320 Cancel();
321 return;
322 } else if (!icon) {
benwells 2015/05/13 02:55:20 Nit: no else after return.
dominickn (DO NOT USE) 2015/05/13 03:08:06 Done.
323 OutputDeveloperNotShownMessage(web_contents, kNoIconAvailable);
311 Cancel(); 324 Cancel();
312 return; 325 return;
313 } 326 }
314 327
315 RecordCouldShowBanner(); 328 RecordCouldShowBanner();
316 if (!CheckIfShouldShowBanner()) { 329 if (!CheckIfShouldShowBanner()) {
330 // At this point, the only possible case is that the banner has been added
331 // to the homescreen, given all of the other checks that have been made.
332 OutputDeveloperNotShownMessage(web_contents, kBannerAlreadyAdded);
317 Cancel(); 333 Cancel();
318 return; 334 return;
319 } 335 }
320 336
321 app_icon_.reset(new SkBitmap(*icon)); 337 app_icon_.reset(new SkBitmap(*icon));
322 event_request_id_ = ++gCurrentRequestID; 338 event_request_id_ = ++gCurrentRequestID;
323 web_contents->GetMainFrame()->Send( 339 web_contents->GetMainFrame()->Send(
324 new ChromeViewMsg_AppBannerPromptRequest( 340 new ChromeViewMsg_AppBannerPromptRequest(
325 web_contents->GetMainFrame()->GetRoutingID(), 341 web_contents->GetMainFrame()->GetRoutingID(),
326 event_request_id_, 342 event_request_id_,
(...skipping 11 matching lines...) Expand all
338 } 354 }
339 355
340 bool AppBannerDataFetcher::CheckIfShouldShowBanner() { 356 bool AppBannerDataFetcher::CheckIfShouldShowBanner() {
341 content::WebContents* web_contents = GetWebContents(); 357 content::WebContents* web_contents = GetWebContents();
342 DCHECK(web_contents); 358 DCHECK(web_contents);
343 359
344 return AppBannerSettingsHelper::ShouldShowBanner( 360 return AppBannerSettingsHelper::ShouldShowBanner(
345 web_contents, validated_url_, GetAppIdentifier(), GetCurrentTime()); 361 web_contents, validated_url_, GetAppIdentifier(), GetCurrentTime());
346 } 362 }
347 363
364 bool AppBannerDataFetcher::CheckFetcherIsStillAlive(
365 content::WebContents* web_contents) {
366 if (!is_active_) {
367 OutputDeveloperNotShownMessage(web_contents,
368 kUserNavigatedBeforeBannerShown);
369 return false;
370 }
371 if (!web_contents) {
372 return false; // We cannot show a message if web_contents is null
373 }
374 return true;
375 }
376
348 // static 377 // static
349 bool AppBannerDataFetcher::IsManifestValidForWebApp( 378 bool AppBannerDataFetcher::IsManifestValidForWebApp(
350 const content::Manifest& manifest) { 379 const content::Manifest& manifest,
351 if (manifest.IsEmpty()) 380 content::WebContents* web_contents) {
381 if (manifest.IsEmpty()) {
382 OutputDeveloperNotShownMessage(web_contents, kManifestEmpty);
352 return false; 383 return false;
353 if (!manifest.start_url.is_valid()) 384 }
385 if (!manifest.start_url.is_valid()) {
386 OutputDeveloperNotShownMessage(web_contents, kStartURLNotValid);
354 return false; 387 return false;
355 if (manifest.name.is_null() && manifest.short_name.is_null()) 388 }
389 if (manifest.name.is_null() && manifest.short_name.is_null()) {
390 OutputDeveloperNotShownMessage(web_contents,
391 kManifestMissingNameOrShortName);
356 return false; 392 return false;
357 if (!DoesManifestContainRequiredIcon(manifest)) 393 }
394 if (!DoesManifestContainRequiredIcon(manifest)) {
395 OutputDeveloperNotShownMessage(web_contents, kManifestMissingSuitableIcon);
358 return false; 396 return false;
397 }
359 return true; 398 return true;
360 } 399 }
361 400
362 } // namespace banners 401 } // namespace banners
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698