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

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: Fix test failure 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) {
87 DCHECK(minimum_icon_size_in_dp <= ideal_icon_size_in_dp);
85 } 88 }
86 89
87 void AppBannerDataFetcher::Start(const GURL& validated_url, 90 void AppBannerDataFetcher::Start(const GURL& validated_url,
88 ui::PageTransition transition_type) { 91 ui::PageTransition transition_type) {
89 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 92 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
90 93
91 content::WebContents* web_contents = GetWebContents(); 94 content::WebContents* web_contents = GetWebContents();
92 DCHECK(web_contents); 95 DCHECK(web_contents);
93 96
94 is_active_ = true; 97 is_active_ = true;
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 316
314 OnHasServiceWorker(web_contents); 317 OnHasServiceWorker(web_contents);
315 } 318 }
316 319
317 void AppBannerDataFetcher::OnHasServiceWorker( 320 void AppBannerDataFetcher::OnHasServiceWorker(
318 content::WebContents* web_contents) { 321 content::WebContents* web_contents) {
319 GURL icon_url = 322 GURL icon_url =
320 ManifestIconSelector::FindBestMatchingIcon( 323 ManifestIconSelector::FindBestMatchingIcon(
321 web_app_data_.icons, 324 web_app_data_.icons,
322 ideal_icon_size_in_dp_, 325 ideal_icon_size_in_dp_,
326 minimum_icon_size_in_dp_,
323 gfx::Screen::GetScreenFor(web_contents->GetNativeView())); 327 gfx::Screen::GetScreenFor(web_contents->GetNativeView()));
324 328
325 if (!FetchAppIcon(web_contents, icon_url)) { 329 if (!FetchAppIcon(web_contents, icon_url)) {
326 OutputDeveloperNotShownMessage(web_contents, kCannotDetermineBestIcon); 330 OutputDeveloperNotShownMessage(web_contents, kCannotDetermineBestIcon);
327 Cancel(); 331 Cancel();
328 } 332 }
329 } 333 }
330 334
331 bool AppBannerDataFetcher::FetchAppIcon(content::WebContents* web_contents, 335 bool AppBannerDataFetcher::FetchAppIcon(content::WebContents* web_contents,
332 const GURL& icon_url) { 336 const GURL& icon_url) {
333 return ManifestIconDownloader::Download( 337 return ManifestIconDownloader::Download(
334 web_contents, 338 web_contents,
335 icon_url, 339 icon_url,
336 ideal_icon_size_in_dp_, 340 ideal_icon_size_in_dp_,
341 minimum_icon_size_in_dp_,
337 base::Bind(&AppBannerDataFetcher::OnAppIconFetched, 342 base::Bind(&AppBannerDataFetcher::OnAppIconFetched,
338 this)); 343 this));
339 } 344 }
340 345
341 void AppBannerDataFetcher::OnAppIconFetched(const SkBitmap& bitmap) { 346 void AppBannerDataFetcher::OnAppIconFetched(const SkBitmap& bitmap) {
342 if (!is_active_) return; 347 if (!is_active_) return;
343 348
344 content::WebContents* web_contents = GetWebContents(); 349 content::WebContents* web_contents = GetWebContents();
345 if (!CheckFetcherIsStillAlive(web_contents)) { 350 if (!CheckFetcherIsStillAlive(web_contents)) {
346 Cancel(); 351 Cancel();
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 return false; 429 return false;
425 } 430 }
426 if (!DoesManifestContainRequiredIcon(manifest)) { 431 if (!DoesManifestContainRequiredIcon(manifest)) {
427 OutputDeveloperNotShownMessage(web_contents, kManifestMissingSuitableIcon); 432 OutputDeveloperNotShownMessage(web_contents, kManifestMissingSuitableIcon);
428 return false; 433 return false;
429 } 434 }
430 return true; 435 return true;
431 } 436 }
432 437
433 } // namespace banners 438 } // namespace banners
OLDNEW
« no previous file with comments | « chrome/browser/banners/app_banner_data_fetcher.h ('k') | chrome/browser/banners/app_banner_data_fetcher_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698