| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "components/favicon/core/favicon_handler.h" | 5 #include "components/favicon/core/favicon_handler.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 const GURL& page_url, | 257 const GURL& page_url, |
| 258 int icon_types, | 258 int icon_types, |
| 259 int desired_size_in_dip, | 259 int desired_size_in_dip, |
| 260 const favicon_base::FaviconResultsCallback& callback, | 260 const favicon_base::FaviconResultsCallback& callback, |
| 261 base::CancelableTaskTracker* tracker) { | 261 base::CancelableTaskTracker* tracker) { |
| 262 return GetFaviconForPageOrIconURL(page_url, callback, tracker); | 262 return GetFaviconForPageOrIconURL(page_url, callback, tracker); |
| 263 } | 263 } |
| 264 | 264 |
| 265 base::CancelableTaskTracker::TaskId UpdateFaviconMappingsAndFetch( | 265 base::CancelableTaskTracker::TaskId UpdateFaviconMappingsAndFetch( |
| 266 const GURL& page_url, | 266 const GURL& page_url, |
| 267 const std::vector<GURL>& icon_urls, | 267 const GURL& icon_url, |
| 268 int icon_types, | 268 favicon_base::IconType icon_type, |
| 269 int desired_size_in_dip, | 269 int desired_size_in_dip, |
| 270 const favicon_base::FaviconResultsCallback& callback, | 270 const favicon_base::FaviconResultsCallback& callback, |
| 271 base::CancelableTaskTracker* tracker) { | 271 base::CancelableTaskTracker* tracker) { |
| 272 CHECK_EQ(1U, icon_urls.size()) << "Multi-icon lookup not implemented"; | 272 return GetFaviconForPageOrIconURL(icon_url, callback, tracker); |
| 273 return GetFaviconForPageOrIconURL(icon_urls.front(), callback, tracker); | |
| 274 } | 273 } |
| 275 | 274 |
| 276 private: | 275 private: |
| 277 base::CancelableTaskTracker::TaskId GetFaviconForPageOrIconURL( | 276 base::CancelableTaskTracker::TaskId GetFaviconForPageOrIconURL( |
| 278 const GURL& page_or_icon_url, | 277 const GURL& page_or_icon_url, |
| 279 const favicon_base::FaviconResultsCallback& callback, | 278 const favicon_base::FaviconResultsCallback& callback, |
| 280 base::CancelableTaskTracker* tracker) { | 279 base::CancelableTaskTracker* tracker) { |
| 281 db_requests_.push_back(page_or_icon_url); | 280 db_requests_.push_back(page_or_icon_url); |
| 282 | 281 |
| 283 return tracker->PostTask(base::ThreadTaskRunnerHandle::Get().get(), | 282 return tracker->PostTask(base::ThreadTaskRunnerHandle::Get().get(), |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 histogram_tester.GetAllSamples("Favicons.DownloadAttempts.LargeIcons"), | 400 histogram_tester.GetAllSamples("Favicons.DownloadAttempts.LargeIcons"), |
| 402 IsEmpty()); | 401 IsEmpty()); |
| 403 EXPECT_THAT( | 402 EXPECT_THAT( |
| 404 histogram_tester.GetAllSamples("Favicons.DownloadAttempts.Favicons"), | 403 histogram_tester.GetAllSamples("Favicons.DownloadAttempts.Favicons"), |
| 405 IsEmpty()); | 404 IsEmpty()); |
| 406 } | 405 } |
| 407 | 406 |
| 408 // Test that UpdateFaviconsAndFetch() is called with the appropriate parameters | 407 // Test that UpdateFaviconsAndFetch() is called with the appropriate parameters |
| 409 // when there is data in the database for neither the page URL nor the icon URL. | 408 // when there is data in the database for neither the page URL nor the icon URL. |
| 410 TEST_F(FaviconHandlerTest, UpdateFaviconMappingsAndFetch) { | 409 TEST_F(FaviconHandlerTest, UpdateFaviconMappingsAndFetch) { |
| 411 EXPECT_CALL(favicon_service_, UpdateFaviconMappingsAndFetch( | 410 EXPECT_CALL(favicon_service_, |
| 412 kPageURL, URLVector{kIconURL16x16}, FAVICON, | 411 UpdateFaviconMappingsAndFetch(kPageURL, kIconURL16x16, FAVICON, |
| 413 /*desired_size_in_dip=*/16, _, _)); | 412 /*desired_size_in_dip=*/16, _, _)); |
| 414 | 413 |
| 415 RunHandlerWithSimpleFaviconCandidates({kIconURL16x16}); | 414 RunHandlerWithSimpleFaviconCandidates({kIconURL16x16}); |
| 416 } | 415 } |
| 417 | 416 |
| 418 // Test that the FaviconHandler process finishes when: | 417 // Test that the FaviconHandler process finishes when: |
| 419 // - There is data in the database for neither the page URL nor the icon URL. | 418 // - There is data in the database for neither the page URL nor the icon URL. |
| 420 // AND | 419 // AND |
| 421 // - FaviconService::GetFaviconForPageURL() callback returns before | 420 // - FaviconService::GetFaviconForPageURL() callback returns before |
| 422 // FaviconHandler::OnUpdateFaviconURL() is called. | 421 // FaviconHandler::OnUpdateFaviconURL() is called. |
| 423 TEST_F(FaviconHandlerTest, DownloadUnknownFaviconIfCandidatesSlower) { | 422 TEST_F(FaviconHandlerTest, DownloadUnknownFaviconIfCandidatesSlower) { |
| (...skipping 763 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1187 RunHandlerWithSimpleFaviconCandidates({k404IconURL}); | 1186 RunHandlerWithSimpleFaviconCandidates({k404IconURL}); |
| 1188 | 1187 |
| 1189 EXPECT_THAT( | 1188 EXPECT_THAT( |
| 1190 histogram_tester.GetAllSamples("Favicons.DownloadOutcome"), | 1189 histogram_tester.GetAllSamples("Favicons.DownloadOutcome"), |
| 1191 ElementsAre(base::Bucket(static_cast<int>(DownloadOutcome::SKIPPED), | 1190 ElementsAre(base::Bucket(static_cast<int>(DownloadOutcome::SKIPPED), |
| 1192 /*expected_count=*/1))); | 1191 /*expected_count=*/1))); |
| 1193 } | 1192 } |
| 1194 | 1193 |
| 1195 } // namespace | 1194 } // namespace |
| 1196 } // namespace favicon | 1195 } // namespace favicon |
| OLD | NEW |