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

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

Issue 1308533006: webapps: allow callers of icon downloader/selector to specify a minimum size (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@webapps-splashscreen-icon
Patch Set: Address review comments Created 5 years, 3 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/command_line.h" 8 #include "base/command_line.h"
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 } 67 }
68 68
69 // static 69 // static
70 void AppBannerDataFetcher::SetTimeDeltaForTesting(int days) { 70 void AppBannerDataFetcher::SetTimeDeltaForTesting(int days) {
71 gTimeDeltaForTesting = base::TimeDelta::FromDays(days); 71 gTimeDeltaForTesting = base::TimeDelta::FromDays(days);
72 } 72 }
73 73
74 AppBannerDataFetcher::AppBannerDataFetcher( 74 AppBannerDataFetcher::AppBannerDataFetcher(
75 content::WebContents* web_contents, 75 content::WebContents* web_contents,
76 base::WeakPtr<Delegate> delegate, 76 base::WeakPtr<Delegate> delegate,
77 int ideal_icon_size_in_dp) 77 int ideal_icon_size_in_dp,
78 int minimum_icon_size_in_dp)
78 : WebContentsObserver(web_contents), 79 : WebContentsObserver(web_contents),
80 weak_delegate_(delegate),
79 ideal_icon_size_in_dp_(ideal_icon_size_in_dp), 81 ideal_icon_size_in_dp_(ideal_icon_size_in_dp),
80 weak_delegate_(delegate), 82 minimum_icon_size_in_dp_(minimum_icon_size_in_dp),
81 is_active_(false), 83 is_active_(false),
82 was_canceled_by_page_(false), 84 was_canceled_by_page_(false),
83 page_requested_prompt_(false), 85 page_requested_prompt_(false),
84 event_request_id_(-1) { 86 event_request_id_(-1) {
85 } 87 }
86 88
87 void AppBannerDataFetcher::Start(const GURL& validated_url, 89 void AppBannerDataFetcher::Start(const GURL& validated_url,
88 ui::PageTransition transition_type) { 90 ui::PageTransition transition_type) {
89 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 91 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
90 92
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 315
314 OnHasServiceWorker(web_contents); 316 OnHasServiceWorker(web_contents);
315 } 317 }
316 318
317 void AppBannerDataFetcher::OnHasServiceWorker( 319 void AppBannerDataFetcher::OnHasServiceWorker(
318 content::WebContents* web_contents) { 320 content::WebContents* web_contents) {
319 GURL icon_url = 321 GURL icon_url =
320 ManifestIconSelector::FindBestMatchingIcon( 322 ManifestIconSelector::FindBestMatchingIcon(
321 web_app_data_.icons, 323 web_app_data_.icons,
322 ideal_icon_size_in_dp_, 324 ideal_icon_size_in_dp_,
325 minimum_icon_size_in_dp_,
323 gfx::Screen::GetScreenFor(web_contents->GetNativeView())); 326 gfx::Screen::GetScreenFor(web_contents->GetNativeView()));
324 327
325 if (!FetchAppIcon(web_contents, icon_url)) { 328 if (!FetchAppIcon(web_contents, icon_url)) {
326 OutputDeveloperNotShownMessage(web_contents, kCannotDetermineBestIcon); 329 OutputDeveloperNotShownMessage(web_contents, kCannotDetermineBestIcon);
327 Cancel(); 330 Cancel();
328 } 331 }
329 } 332 }
330 333
331 bool AppBannerDataFetcher::FetchAppIcon(content::WebContents* web_contents, 334 bool AppBannerDataFetcher::FetchAppIcon(content::WebContents* web_contents,
332 const GURL& icon_url) { 335 const GURL& icon_url) {
333 return ManifestIconDownloader::Download( 336 return ManifestIconDownloader::Download(
334 web_contents, 337 web_contents,
335 icon_url, 338 icon_url,
336 ideal_icon_size_in_dp_, 339 ideal_icon_size_in_dp_,
340 minimum_icon_size_in_dp_,
337 base::Bind(&AppBannerDataFetcher::OnAppIconFetched, 341 base::Bind(&AppBannerDataFetcher::OnAppIconFetched,
338 this)); 342 this));
339 } 343 }
340 344
341 void AppBannerDataFetcher::OnAppIconFetched(const SkBitmap& bitmap) { 345 void AppBannerDataFetcher::OnAppIconFetched(const SkBitmap& bitmap) {
342 if (!is_active_) return; 346 if (!is_active_) return;
343 347
344 content::WebContents* web_contents = GetWebContents(); 348 content::WebContents* web_contents = GetWebContents();
345 if (!CheckFetcherIsStillAlive(web_contents)) { 349 if (!CheckFetcherIsStillAlive(web_contents)) {
346 Cancel(); 350 Cancel();
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 return false; 428 return false;
425 } 429 }
426 if (!DoesManifestContainRequiredIcon(manifest)) { 430 if (!DoesManifestContainRequiredIcon(manifest)) {
427 OutputDeveloperNotShownMessage(web_contents, kManifestMissingSuitableIcon); 431 OutputDeveloperNotShownMessage(web_contents, kManifestMissingSuitableIcon);
428 return false; 432 return false;
429 } 433 }
430 return true; 434 return true;
431 } 435 }
432 436
433 } // namespace banners 437 } // namespace banners
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698