Commit 001b10de authored by sdefresne's avatar sdefresne Committed by Commit bot

Componentize conversion of content::FaviconURL to favicon::FaviconURL

In preparation of componentization of FaviconTabHelper, introduce a
new target //components/favicon/content (as favicon is a layered
component) and move the function to convert from content::FaviconURL
to favicon::FaviconURL there.

BUG=374281

Review URL: https://codereview.chromium.org/1020213002

Cr-Commit-Position: refs/heads/master@{#321606}
parent 36d057d7
......@@ -93,8 +93,8 @@ static_library("browser") {
"//components/device_event_log",
"//components/domain_reliability",
"//components/enhanced_bookmarks",
"//components/favicon_base",
"//components/favicon/core",
"//components/favicon_base",
"//components/gcm_driver",
"//components/google/core/browser",
"//components/handoff",
......@@ -234,6 +234,7 @@ static_library("browser") {
"//components/autofill/content/browser",
"//components/data_reduction_proxy/content/browser",
"//components/dom_distiller/content",
"//components/favicon/content",
"//components/history/content/browser",
"//components/keyed_service/content",
"//components/navigation_interception",
......
......@@ -15,6 +15,7 @@
#include "chrome/browser/search/search.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/url_constants.h"
#include "components/favicon/content/favicon_url_util.h"
#include "components/favicon/core/favicon_handler.h"
#include "components/favicon/core/favicon_service.h"
#include "components/favicon/core/favicon_tab_helper_observer.h"
......@@ -283,37 +284,12 @@ void FaviconTabHelper::DidNavigateMainFrame(
FetchFavicon(url);
}
// Returns favicon_base::IconType the given icon_type corresponds to.
// TODO(jif): Move function to /components/favicon_base/content/
// crbug.com/374281.
favicon_base::IconType ToChromeIconType(
content::FaviconURL::IconType icon_type) {
switch (icon_type) {
case content::FaviconURL::FAVICON:
return favicon_base::FAVICON;
case content::FaviconURL::TOUCH_ICON:
return favicon_base::TOUCH_ICON;
case content::FaviconURL::TOUCH_PRECOMPOSED_ICON:
return favicon_base::TOUCH_PRECOMPOSED_ICON;
case content::FaviconURL::INVALID_ICON:
return favicon_base::INVALID_ICON;
}
NOTREACHED();
return favicon_base::INVALID_ICON;
}
void FaviconTabHelper::DidUpdateFaviconURL(
const std::vector<content::FaviconURL>& candidates) {
DCHECK(!candidates.empty());
favicon_urls_ = candidates;
std::vector<favicon::FaviconURL> favicon_urls;
for (size_t i = 0; i < candidates.size(); i++) {
const content::FaviconURL& candidate = candidates[i];
favicon_urls.push_back(
favicon::FaviconURL(candidate.icon_url,
ToChromeIconType(candidate.icon_type),
candidate.icon_sizes));
}
std::vector<favicon::FaviconURL> favicon_urls =
favicon::FaviconURLsFromContentFaviconURLs(candidates);
favicon_handler_->OnUpdateFaviconURL(favicon_urls);
if (touch_icon_handler_.get())
touch_icon_handler_->OnUpdateFaviconURL(favicon_urls);
......
......@@ -3027,6 +3027,7 @@
'../components/components.gyp:autofill_content_browser',
'../components/components.gyp:data_reduction_proxy_content_browser',
'../components/components.gyp:dom_distiller_content',
'../components/components.gyp:favicon_content',
'../components/components.gyp:history_content_browser',
'../components/components.gyp:keyed_service_content',
'../components/components.gyp:navigation_interception',
......
......@@ -34,4 +34,29 @@
],
},
],
'conditions': [
['OS!="ios"', {
'targets': [
{
# GN version: //components/favicon/content
'target_name': 'favicon_content',
'type': 'static_library',
'dependencies': [
'../content/content.gyp:content_browser',
'../content/content.gyp:content_common',
'favicon_base',
'favicon_core',
],
'sources': [
# Note: sources list duplicated in GN build.
'favicon/content/favicon_url_util.h',
'favicon/content/favicon_url_util.cc',
],
'include_dirs': [
'..',
],
},
],
}],
],
}
# Copyright 2015 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
static_library("content") {
sources = [
"favicon_url_util.cc",
"favicon_url_util.h",
]
deps = [
"//components/favicon/core",
"//components/favicon_base",
"//content/public/browser",
"//content/public/common",
]
}
include_rules = [
"+content/public",
]
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/favicon/content/favicon_url_util.h"
#include <algorithm>
#include <iterator>
#include "components/favicon/core/favicon_url.h"
#include "components/favicon_base/favicon_types.h"
#include "content/public/common/favicon_url.h"
namespace favicon {
namespace {
favicon_base::IconType IconTypeFromContentIconType(
content::FaviconURL::IconType icon_type) {
switch (icon_type) {
case content::FaviconURL::FAVICON:
return favicon_base::FAVICON;
case content::FaviconURL::TOUCH_ICON:
return favicon_base::TOUCH_ICON;
case content::FaviconURL::TOUCH_PRECOMPOSED_ICON:
return favicon_base::TOUCH_PRECOMPOSED_ICON;
case content::FaviconURL::INVALID_ICON:
return favicon_base::INVALID_ICON;
}
NOTREACHED();
return favicon_base::INVALID_ICON;
}
} // namespace
FaviconURL FaviconURLFromContentFaviconURL(
const content::FaviconURL& favicon_url) {
return FaviconURL(favicon_url.icon_url,
IconTypeFromContentIconType(favicon_url.icon_type),
favicon_url.icon_sizes);
}
std::vector<FaviconURL> FaviconURLsFromContentFaviconURLs(
const std::vector<content::FaviconURL>& favicon_urls) {
std::vector<FaviconURL> result;
result.reserve(favicon_urls.size());
std::transform(favicon_urls.begin(), favicon_urls.end(),
std::back_inserter(result), FaviconURLFromContentFaviconURL);
return result;
}
} // namespace favicon
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_FAVICON_CONTENT_FAVICON_URL_UTIL_H_
#define COMPONENTS_FAVICON_CONTENT_FAVICON_URL_UTIL_H_
#include <vector>
namespace content {
struct FaviconURL;
}
namespace favicon {
struct FaviconURL;
// Creates a favicon::FaviconURL from a content::FaviconURL.
FaviconURL FaviconURLFromContentFaviconURL(
const content::FaviconURL& favicon_url);
// Creates favicon::FaviconURLs from content::FaviconURLs.
std::vector<FaviconURL> FaviconURLsFromContentFaviconURLs(
const std::vector<content::FaviconURL>& favicon_urls);
} // namespace favicon
#endif // COMPONENTS_FAVICON_CONTENT_FAVICON_URL_UTIL_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment