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/metrics/histogram_macros.h" | 8 #include "base/metrics/histogram_macros.h" |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
11 #include "components/bookmarks/browser/bookmark_model.h" | 11 #include "components/bookmarks/browser/bookmark_model.h" |
12 #include "components/favicon/core/favicon_driver_observer.h" | 12 #include "components/favicon/core/favicon_driver_observer.h" |
13 #include "components/favicon/core/favicon_handler.h" | 13 #include "components/favicon/core/favicon_handler.h" |
14 #include "components/favicon/core/favicon_service.h" | 14 #include "components/favicon/core/favicon_service.h" |
15 #include "components/favicon/core/favicon_url.h" | 15 #include "components/favicon/core/favicon_url.h" |
16 #include "components/history/core/browser/history_service.h" | 16 #include "components/history/core/browser/history_service.h" |
17 | 17 |
18 namespace favicon { | 18 namespace favicon { |
19 namespace { | 19 namespace { |
20 | 20 |
21 #if defined(OS_ANDROID) || defined(OS_IOS) | 21 #if defined(OS_ANDROID) || defined(OS_IOS) |
22 const bool kEnableTouchIcon = true; | 22 const bool kFetchLargestIcon = true; |
23 #else | 23 #else |
24 const bool kEnableTouchIcon = false; | 24 const bool kFetchLargestIcon = false; |
25 #endif | 25 #endif |
26 | 26 |
27 void RecordCandidateMetrics(const std::vector<FaviconURL>& candidates) { | 27 void RecordCandidateMetrics(const std::vector<FaviconURL>& candidates) { |
28 size_t with_defined_touch_icons = 0; | 28 size_t with_defined_touch_icons = 0; |
29 size_t with_defined_sizes = 0; | 29 size_t with_defined_sizes = 0; |
30 for (const auto& candidate : candidates) { | 30 for (const auto& candidate : candidates) { |
31 if (!candidate.icon_sizes.empty()) { | 31 if (!candidate.icon_sizes.empty()) { |
32 with_defined_sizes++; | 32 with_defined_sizes++; |
33 } | 33 } |
34 if (candidate.icon_type & | 34 if (candidate.icon_type & |
(...skipping 11 matching lines...) Expand all Loading... |
46 | 46 |
47 } // namespace | 47 } // namespace |
48 | 48 |
49 FaviconDriverImpl::FaviconDriverImpl(FaviconService* favicon_service, | 49 FaviconDriverImpl::FaviconDriverImpl(FaviconService* favicon_service, |
50 history::HistoryService* history_service, | 50 history::HistoryService* history_service, |
51 bookmarks::BookmarkModel* bookmark_model) | 51 bookmarks::BookmarkModel* bookmark_model) |
52 : favicon_service_(favicon_service), | 52 : favicon_service_(favicon_service), |
53 history_service_(history_service), | 53 history_service_(history_service), |
54 bookmark_model_(bookmark_model) { | 54 bookmark_model_(bookmark_model) { |
55 favicon_handler_.reset(new FaviconHandler( | 55 favicon_handler_.reset(new FaviconHandler( |
56 favicon_service_, this, kEnableTouchIcon | 56 favicon_service_, this, |
57 ? FaviconDriverObserver::NON_TOUCH_LARGEST | 57 kFetchLargestIcon ? FaviconDriverObserver::LARGEST |
58 : FaviconDriverObserver::NON_TOUCH_16_DIP)); | 58 : FaviconDriverObserver::NON_TOUCH_16_DIP)); |
59 if (kEnableTouchIcon) { | |
60 touch_icon_handler_.reset(new FaviconHandler( | |
61 favicon_service_, this, FaviconDriverObserver::TOUCH_LARGEST)); | |
62 } | |
63 } | 59 } |
64 | 60 |
65 FaviconDriverImpl::~FaviconDriverImpl() { | 61 FaviconDriverImpl::~FaviconDriverImpl() { |
66 } | 62 } |
67 | 63 |
68 void FaviconDriverImpl::FetchFavicon(const GURL& url) { | 64 void FaviconDriverImpl::FetchFavicon(const GURL& url) { |
69 favicon_handler_->FetchFavicon(url); | 65 favicon_handler_->FetchFavicon(url); |
70 if (touch_icon_handler_.get()) | |
71 touch_icon_handler_->FetchFavicon(url); | |
72 } | 66 } |
73 | 67 |
74 bool FaviconDriverImpl::IsBookmarked(const GURL& url) { | 68 bool FaviconDriverImpl::IsBookmarked(const GURL& url) { |
75 return bookmark_model_ && bookmark_model_->IsBookmarked(url); | 69 return bookmark_model_ && bookmark_model_->IsBookmarked(url); |
76 } | 70 } |
77 | 71 |
78 bool FaviconDriverImpl::HasPendingTasksForTest() { | 72 bool FaviconDriverImpl::HasPendingTasksForTest() { |
79 if (favicon_handler_->HasPendingTasksForTest()) | 73 return favicon_handler_->HasPendingTasksForTest(); |
80 return true; | |
81 if (touch_icon_handler_ && touch_icon_handler_->HasPendingTasksForTest()) | |
82 return true; | |
83 return false; | |
84 } | 74 } |
85 | 75 |
86 void FaviconDriverImpl::SetFaviconOutOfDateForPage(const GURL& url, | 76 void FaviconDriverImpl::SetFaviconOutOfDateForPage(const GURL& url, |
87 bool force_reload) { | 77 bool force_reload) { |
88 if (favicon_service_) { | 78 if (favicon_service_) { |
89 favicon_service_->SetFaviconOutOfDateForPage(url); | 79 favicon_service_->SetFaviconOutOfDateForPage(url); |
90 if (force_reload) | 80 if (force_reload) |
91 favicon_service_->ClearUnableToDownloadFavicons(); | 81 favicon_service_->ClearUnableToDownloadFavicons(); |
92 } | 82 } |
93 } | 83 } |
94 | 84 |
95 void FaviconDriverImpl::OnUpdateFaviconURL( | 85 void FaviconDriverImpl::OnUpdateFaviconURL( |
96 const GURL& page_url, | 86 const GURL& page_url, |
97 const std::vector<FaviconURL>& candidates) { | 87 const std::vector<FaviconURL>& candidates) { |
98 DCHECK(!candidates.empty()); | 88 DCHECK(!candidates.empty()); |
99 RecordCandidateMetrics(candidates); | 89 RecordCandidateMetrics(candidates); |
100 favicon_handler_->OnUpdateFaviconURL(page_url, candidates); | 90 favicon_handler_->OnUpdateFaviconURL(page_url, candidates); |
101 if (touch_icon_handler_.get()) | |
102 touch_icon_handler_->OnUpdateFaviconURL(page_url, candidates); | |
103 } | 91 } |
104 | 92 |
105 } // namespace favicon | 93 } // namespace favicon |
OLD | NEW |