| OLD | NEW |
| 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 "components/favicon/core/favicon_driver_impl.h" | 5 #include "components/favicon/core/favicon_driver_impl.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "base/metrics/histogram_macros.h" | 9 #include "base/metrics/histogram_macros.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| 11 #include "build/build_config.h" | 11 #include "build/build_config.h" |
| 12 #include "components/bookmarks/browser/bookmark_model.h" | |
| 13 #include "components/favicon/core/favicon_driver_observer.h" | 12 #include "components/favicon/core/favicon_driver_observer.h" |
| 14 #include "components/favicon/core/favicon_handler.h" | 13 #include "components/favicon/core/favicon_handler.h" |
| 15 #include "components/favicon/core/favicon_service.h" | 14 #include "components/favicon/core/favicon_service.h" |
| 16 #include "components/favicon/core/favicon_url.h" | 15 #include "components/favicon/core/favicon_url.h" |
| 17 #include "components/history/core/browser/history_service.h" | 16 #include "components/history/core/browser/history_service.h" |
| 18 | 17 |
| 19 namespace favicon { | 18 namespace favicon { |
| 20 namespace { | 19 namespace { |
| 21 | 20 |
| 22 #if defined(OS_ANDROID) || defined(OS_IOS) | 21 #if defined(OS_ANDROID) || defined(OS_IOS) |
| (...skipping 18 matching lines...) Expand all Loading... |
| 41 UMA_HISTOGRAM_COUNTS_100("Favicons.CandidatesCount", candidates.size()); | 40 UMA_HISTOGRAM_COUNTS_100("Favicons.CandidatesCount", candidates.size()); |
| 42 UMA_HISTOGRAM_COUNTS_100("Favicons.CandidatesWithDefinedSizesCount", | 41 UMA_HISTOGRAM_COUNTS_100("Favicons.CandidatesWithDefinedSizesCount", |
| 43 with_defined_sizes); | 42 with_defined_sizes); |
| 44 UMA_HISTOGRAM_COUNTS_100("Favicons.CandidatesWithTouchIconsCount", | 43 UMA_HISTOGRAM_COUNTS_100("Favicons.CandidatesWithTouchIconsCount", |
| 45 with_defined_touch_icons); | 44 with_defined_touch_icons); |
| 46 } | 45 } |
| 47 | 46 |
| 48 } // namespace | 47 } // namespace |
| 49 | 48 |
| 50 FaviconDriverImpl::FaviconDriverImpl(FaviconService* favicon_service, | 49 FaviconDriverImpl::FaviconDriverImpl(FaviconService* favicon_service, |
| 51 history::HistoryService* history_service, | 50 history::HistoryService* history_service) |
| 52 bookmarks::BookmarkModel* bookmark_model) | 51 : favicon_service_(favicon_service), history_service_(history_service) { |
| 53 : favicon_service_(favicon_service), | |
| 54 history_service_(history_service), | |
| 55 bookmark_model_(bookmark_model) { | |
| 56 if (!favicon_service_) | 52 if (!favicon_service_) |
| 57 return; | 53 return; |
| 58 | 54 |
| 59 if (kEnableTouchIcon) { | 55 if (kEnableTouchIcon) { |
| 60 handlers_.push_back(base::MakeUnique<FaviconHandler>( | 56 handlers_.push_back(base::MakeUnique<FaviconHandler>( |
| 61 favicon_service_, this, FaviconDriverObserver::NON_TOUCH_LARGEST)); | 57 favicon_service_, this, FaviconDriverObserver::NON_TOUCH_LARGEST)); |
| 62 handlers_.push_back(base::MakeUnique<FaviconHandler>( | 58 handlers_.push_back(base::MakeUnique<FaviconHandler>( |
| 63 favicon_service_, this, FaviconDriverObserver::TOUCH_LARGEST)); | 59 favicon_service_, this, FaviconDriverObserver::TOUCH_LARGEST)); |
| 64 } else { | 60 } else { |
| 65 handlers_.push_back(base::MakeUnique<FaviconHandler>( | 61 handlers_.push_back(base::MakeUnique<FaviconHandler>( |
| 66 favicon_service_, this, FaviconDriverObserver::NON_TOUCH_16_DIP)); | 62 favicon_service_, this, FaviconDriverObserver::NON_TOUCH_16_DIP)); |
| 67 } | 63 } |
| 68 } | 64 } |
| 69 | 65 |
| 70 FaviconDriverImpl::~FaviconDriverImpl() { | 66 FaviconDriverImpl::~FaviconDriverImpl() { |
| 71 } | 67 } |
| 72 | 68 |
| 73 void FaviconDriverImpl::FetchFavicon(const GURL& page_url, | 69 void FaviconDriverImpl::FetchFavicon(const GURL& page_url, |
| 74 bool is_same_document) { | 70 bool is_same_document) { |
| 75 for (const std::unique_ptr<FaviconHandler>& handler : handlers_) | 71 for (const std::unique_ptr<FaviconHandler>& handler : handlers_) |
| 76 handler->FetchFavicon(page_url, is_same_document); | 72 handler->FetchFavicon(page_url, is_same_document); |
| 77 } | 73 } |
| 78 | 74 |
| 79 bool FaviconDriverImpl::IsBookmarked(const GURL& url) { | |
| 80 return bookmark_model_ && bookmark_model_->IsBookmarked(url); | |
| 81 } | |
| 82 | |
| 83 bool FaviconDriverImpl::HasPendingTasksForTest() { | 75 bool FaviconDriverImpl::HasPendingTasksForTest() { |
| 84 for (const std::unique_ptr<FaviconHandler>& handler : handlers_) { | 76 for (const std::unique_ptr<FaviconHandler>& handler : handlers_) { |
| 85 if (handler->HasPendingTasksForTest()) | 77 if (handler->HasPendingTasksForTest()) |
| 86 return true; | 78 return true; |
| 87 } | 79 } |
| 88 return false; | 80 return false; |
| 89 } | 81 } |
| 90 | 82 |
| 91 void FaviconDriverImpl::SetFaviconOutOfDateForPage(const GURL& url, | 83 void FaviconDriverImpl::SetFaviconOutOfDateForPage(const GURL& url, |
| 92 bool force_reload) { | 84 bool force_reload) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 108 // icons override inline touch icons). | 100 // icons override inline touch icons). |
| 109 handler->OnUpdateCandidates( | 101 handler->OnUpdateCandidates( |
| 110 page_url, candidates, | 102 page_url, candidates, |
| 111 handler->icon_types() & favicon_base::WEB_MANIFEST_ICON | 103 handler->icon_types() & favicon_base::WEB_MANIFEST_ICON |
| 112 ? manifest_url | 104 ? manifest_url |
| 113 : GURL::EmptyGURL()); | 105 : GURL::EmptyGURL()); |
| 114 } | 106 } |
| 115 } | 107 } |
| 116 | 108 |
| 117 } // namespace favicon | 109 } // namespace favicon |
| OLD | NEW |