| 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/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 #endif | 40 #endif |
| 41 | 41 |
| 42 } // namespace | 42 } // namespace |
| 43 | 43 |
| 44 FaviconDriverImpl::FaviconDriverImpl(FaviconService* favicon_service, | 44 FaviconDriverImpl::FaviconDriverImpl(FaviconService* favicon_service, |
| 45 history::HistoryService* history_service, | 45 history::HistoryService* history_service, |
| 46 bookmarks::BookmarkModel* bookmark_model) | 46 bookmarks::BookmarkModel* bookmark_model) |
| 47 : favicon_service_(favicon_service), | 47 : favicon_service_(favicon_service), |
| 48 history_service_(history_service), | 48 history_service_(history_service), |
| 49 bookmark_model_(bookmark_model) { | 49 bookmark_model_(bookmark_model) { |
| 50 bool download_large_icons = kEnableTouchIcon || IsIconNTPEnabled(); |
| 50 favicon_handler_.reset(new FaviconHandler( | 51 favicon_handler_.reset(new FaviconHandler( |
| 51 favicon_service_, this, FaviconHandler::FAVICON, kEnableTouchIcon)); | 52 favicon_service_, this, FaviconHandler::FAVICON, download_large_icons)); |
| 52 if (kEnableTouchIcon) { | 53 if (download_large_icons) { |
| 53 touch_icon_handler_.reset(new FaviconHandler(favicon_service_, this, | 54 touch_icon_handler_.reset(new FaviconHandler(favicon_service_, this, |
| 54 FaviconHandler::TOUCH, true)); | 55 FaviconHandler::TOUCH, true)); |
| 55 } | 56 } |
| 56 if (IsIconNTPEnabled()) { | |
| 57 large_icon_handler_.reset(new FaviconHandler(favicon_service_, this, | |
| 58 FaviconHandler::LARGE, true)); | |
| 59 } | |
| 60 } | 57 } |
| 61 | 58 |
| 62 FaviconDriverImpl::~FaviconDriverImpl() { | 59 FaviconDriverImpl::~FaviconDriverImpl() { |
| 63 } | 60 } |
| 64 | 61 |
| 65 void FaviconDriverImpl::FetchFavicon(const GURL& url) { | 62 void FaviconDriverImpl::FetchFavicon(const GURL& url) { |
| 66 favicon_handler_->FetchFavicon(url); | 63 favicon_handler_->FetchFavicon(url); |
| 67 if (touch_icon_handler_.get()) | 64 if (touch_icon_handler_.get()) |
| 68 touch_icon_handler_->FetchFavicon(url); | 65 touch_icon_handler_->FetchFavicon(url); |
| 69 if (large_icon_handler_.get()) | |
| 70 large_icon_handler_->FetchFavicon(url); | |
| 71 } | 66 } |
| 72 | 67 |
| 73 void FaviconDriverImpl::SaveFavicon() { | 68 void FaviconDriverImpl::SaveFavicon() { |
| 74 GURL active_url = GetActiveURL(); | 69 GURL active_url = GetActiveURL(); |
| 75 if (active_url.is_empty()) | 70 if (active_url.is_empty()) |
| 76 return; | 71 return; |
| 77 | 72 |
| 78 // Make sure the page is in history, otherwise adding the favicon does | 73 // Make sure the page is in history, otherwise adding the favicon does |
| 79 // nothing. | 74 // nothing. |
| 80 if (!history_service_) | 75 if (!history_service_) |
| (...skipping 25 matching lines...) Expand all Loading... |
| 106 if (favicon_service_) | 101 if (favicon_service_) |
| 107 favicon_service_->UnableToDownloadFavicon(image_url); | 102 favicon_service_->UnableToDownloadFavicon(image_url); |
| 108 } | 103 } |
| 109 | 104 |
| 110 favicon_handler_->OnDidDownloadFavicon(id, image_url, bitmaps, | 105 favicon_handler_->OnDidDownloadFavicon(id, image_url, bitmaps, |
| 111 original_bitmap_sizes); | 106 original_bitmap_sizes); |
| 112 if (touch_icon_handler_.get()) { | 107 if (touch_icon_handler_.get()) { |
| 113 touch_icon_handler_->OnDidDownloadFavicon(id, image_url, bitmaps, | 108 touch_icon_handler_->OnDidDownloadFavicon(id, image_url, bitmaps, |
| 114 original_bitmap_sizes); | 109 original_bitmap_sizes); |
| 115 } | 110 } |
| 116 if (large_icon_handler_.get()) { | |
| 117 large_icon_handler_->OnDidDownloadFavicon(id, image_url, bitmaps, | |
| 118 original_bitmap_sizes); | |
| 119 } | |
| 120 } | 111 } |
| 121 | 112 |
| 122 bool FaviconDriverImpl::IsBookmarked(const GURL& url) { | 113 bool FaviconDriverImpl::IsBookmarked(const GURL& url) { |
| 123 return bookmark_model_ && bookmark_model_->IsBookmarked(url); | 114 return bookmark_model_ && bookmark_model_->IsBookmarked(url); |
| 124 } | 115 } |
| 125 | 116 |
| 126 void FaviconDriverImpl::OnFaviconAvailable(const gfx::Image& image, | 117 void FaviconDriverImpl::OnFaviconAvailable(const gfx::Image& image, |
| 127 const GURL& icon_url, | 118 const GURL& icon_url, |
| 128 bool is_active_favicon) { | 119 bool is_active_favicon) { |
| 129 if (is_active_favicon) { | 120 if (is_active_favicon) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 140 } | 131 } |
| 141 if (!image.IsEmpty()) | 132 if (!image.IsEmpty()) |
| 142 NotifyFaviconAvailable(image); | 133 NotifyFaviconAvailable(image); |
| 143 } | 134 } |
| 144 | 135 |
| 145 bool FaviconDriverImpl::HasPendingTasksForTest() { | 136 bool FaviconDriverImpl::HasPendingTasksForTest() { |
| 146 if (favicon_handler_->HasPendingTasksForTest()) | 137 if (favicon_handler_->HasPendingTasksForTest()) |
| 147 return true; | 138 return true; |
| 148 if (touch_icon_handler_ && touch_icon_handler_->HasPendingTasksForTest()) | 139 if (touch_icon_handler_ && touch_icon_handler_->HasPendingTasksForTest()) |
| 149 return true; | 140 return true; |
| 150 if (large_icon_handler_ && large_icon_handler_->HasPendingTasksForTest()) | |
| 151 return true; | |
| 152 return false; | 141 return false; |
| 153 } | 142 } |
| 154 | 143 |
| 155 bool FaviconDriverImpl::WasUnableToDownloadFavicon(const GURL& url) { | 144 bool FaviconDriverImpl::WasUnableToDownloadFavicon(const GURL& url) { |
| 156 return favicon_service_ && favicon_service_->WasUnableToDownloadFavicon(url); | 145 return favicon_service_ && favicon_service_->WasUnableToDownloadFavicon(url); |
| 157 } | 146 } |
| 158 | 147 |
| 159 void FaviconDriverImpl::SetFaviconOutOfDateForPage(const GURL& url, | 148 void FaviconDriverImpl::SetFaviconOutOfDateForPage(const GURL& url, |
| 160 bool force_reload) { | 149 bool force_reload) { |
| 161 if (favicon_service_) { | 150 if (favicon_service_) { |
| 162 favicon_service_->SetFaviconOutOfDateForPage(url); | 151 favicon_service_->SetFaviconOutOfDateForPage(url); |
| 163 if (force_reload) | 152 if (force_reload) |
| 164 favicon_service_->ClearUnableToDownloadFavicons(); | 153 favicon_service_->ClearUnableToDownloadFavicons(); |
| 165 } | 154 } |
| 166 } | 155 } |
| 167 | 156 |
| 168 void FaviconDriverImpl::OnUpdateFaviconURL( | 157 void FaviconDriverImpl::OnUpdateFaviconURL( |
| 169 const std::vector<FaviconURL>& candidates) { | 158 const std::vector<FaviconURL>& candidates) { |
| 170 DCHECK(!candidates.empty()); | 159 DCHECK(!candidates.empty()); |
| 171 favicon_handler_->OnUpdateFaviconURL(candidates); | 160 favicon_handler_->OnUpdateFaviconURL(candidates); |
| 172 if (touch_icon_handler_.get()) | 161 if (touch_icon_handler_.get()) |
| 173 touch_icon_handler_->OnUpdateFaviconURL(candidates); | 162 touch_icon_handler_->OnUpdateFaviconURL(candidates); |
| 174 if (large_icon_handler_.get()) | |
| 175 large_icon_handler_->OnUpdateFaviconURL(candidates); | |
| 176 } | 163 } |
| 177 | 164 |
| 178 } // namespace favicon | 165 } // namespace favicon |
| OLD | NEW |