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

Side by Side Diff: chrome/browser/installable/installable_manager.cc

Issue 2662103002: Refactor ManifestIconSelector and update it for Manifest.icon.purpose (Closed)
Patch Set: Addressing comments Created 3 years, 10 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/installable/installable_manager.h" 5 #include "chrome/browser/installable/installable_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
dominickn 2017/01/31 18:13:03 This is unused now?
F 2017/01/31 18:42:50 Done.
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
11 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
12 #include "chrome/browser/manifest/manifest_icon_downloader.h" 12 #include "chrome/browser/manifest/manifest_icon_downloader.h"
13 #include "chrome/browser/manifest/manifest_icon_selector.h" 13 #include "chrome/browser/manifest/manifest_icon_selector.h"
14 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/ssl/security_state_tab_helper.h" 15 #include "chrome/browser/ssl/security_state_tab_helper.h"
16 #include "components/security_state/core/security_state.h" 16 #include "components/security_state/core/security_state.h"
17 #include "content/public/browser/browser_context.h" 17 #include "content/public/browser/browser_context.h"
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 void InstallableManager::CheckAndFetchBestIcon(const IconParams& params) { 432 void InstallableManager::CheckAndFetchBestIcon(const IconParams& params) {
433 DCHECK(!manifest().IsEmpty()); 433 DCHECK(!manifest().IsEmpty());
434 434
435 int ideal_icon_size_in_px = std::get<0>(params); 435 int ideal_icon_size_in_px = std::get<0>(params);
436 int minimum_icon_size_in_px = std::get<1>(params); 436 int minimum_icon_size_in_px = std::get<1>(params);
437 IconPurpose icon_purpose = std::get<2>(params); 437 IconPurpose icon_purpose = std::get<2>(params);
438 438
439 IconProperty& icon = icons_[params]; 439 IconProperty& icon = icons_[params];
440 icon.fetched = true; 440 icon.fetched = true;
441 441
442 // Filter by icon purpose.
443 std::vector<content::Manifest::Icon> filtered_icons;
444 std::copy_if(manifest().icons.begin(), manifest().icons.end(),
445 std::back_inserter(filtered_icons),
446 [icon_purpose](const content::Manifest::Icon& icon) {
447 return base::ContainsValue(icon.purpose, icon_purpose);
448 });
449
450 GURL icon_url = ManifestIconSelector::FindBestMatchingIcon( 442 GURL icon_url = ManifestIconSelector::FindBestMatchingIcon(
451 filtered_icons, ideal_icon_size_in_px, minimum_icon_size_in_px); 443 manifest().icons, ideal_icon_size_in_px, minimum_icon_size_in_px,
444 icon_purpose);
452 445
453 if (icon_url.is_empty()) { 446 if (icon_url.is_empty()) {
454 icon.error = NO_ACCEPTABLE_ICON; 447 icon.error = NO_ACCEPTABLE_ICON;
455 } else { 448 } else {
456 bool can_download_icon = ManifestIconDownloader::Download( 449 bool can_download_icon = ManifestIconDownloader::Download(
457 GetWebContents(), icon_url, ideal_icon_size_in_px, 450 GetWebContents(), icon_url, ideal_icon_size_in_px,
458 minimum_icon_size_in_px, 451 minimum_icon_size_in_px,
459 base::Bind(&InstallableManager::OnIconFetched, 452 base::Bind(&InstallableManager::OnIconFetched,
460 weak_factory_.GetWeakPtr(), icon_url, params)); 453 weak_factory_.GetWeakPtr(), icon_url, params));
461 if (can_download_icon) 454 if (can_download_icon)
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 return manifest_->url; 493 return manifest_->url;
501 } 494 }
502 495
503 const content::Manifest& InstallableManager::manifest() const { 496 const content::Manifest& InstallableManager::manifest() const {
504 return manifest_->manifest; 497 return manifest_->manifest;
505 } 498 }
506 499
507 bool InstallableManager::is_installable() const { 500 bool InstallableManager::is_installable() const {
508 return installable_->installable; 501 return installable_->installable;
509 } 502 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698