| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/ntp_tiles/icon_cacher_impl.h" | 5 #include "components/ntp_tiles/icon_cacher_impl.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "components/favicon/core/favicon_service.h" | 10 #include "components/favicon/core/favicon_service.h" |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 if (!HasResultDefaultBackgroundColor(result)) { | 209 if (!HasResultDefaultBackgroundColor(result)) { |
| 210 // We should only fetch for default "gray" tiles so that we never overrite | 210 // We should only fetch for default "gray" tiles so that we never overrite |
| 211 // any favicon of any size. | 211 // any favicon of any size. |
| 212 FinishRequestAndNotifyIconAvailable(page_url, /*newly_available=*/false); | 212 FinishRequestAndNotifyIconAvailable(page_url, /*newly_available=*/false); |
| 213 return; | 213 return; |
| 214 } | 214 } |
| 215 | 215 |
| 216 large_icon_service_ | 216 large_icon_service_ |
| 217 ->GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache( | 217 ->GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache( |
| 218 page_url, kTileIconMinSizePx, kTileIconDesiredSizePx, | 218 page_url, kTileIconMinSizePx, kTileIconDesiredSizePx, |
| 219 /*may_page_url_be_private=*/true, |
| 219 base::Bind(&IconCacherImpl::FinishRequestAndNotifyIconAvailable, | 220 base::Bind(&IconCacherImpl::FinishRequestAndNotifyIconAvailable, |
| 220 weak_ptr_factory_.GetWeakPtr(), page_url)); | 221 weak_ptr_factory_.GetWeakPtr(), page_url)); |
| 221 } | 222 } |
| 222 | 223 |
| 223 bool IconCacherImpl::StartRequest(const GURL& request_url, | 224 bool IconCacherImpl::StartRequest(const GURL& request_url, |
| 224 const base::Closure& icon_available) { | 225 const base::Closure& icon_available) { |
| 225 bool in_flight = in_flight_requests_.count(request_url) > 0; | 226 bool in_flight = in_flight_requests_.count(request_url) > 0; |
| 226 in_flight_requests_[request_url].push_back(icon_available); | 227 in_flight_requests_[request_url].push_back(icon_available); |
| 227 return !in_flight; | 228 return !in_flight; |
| 228 } | 229 } |
| 229 | 230 |
| 230 void IconCacherImpl::FinishRequestAndNotifyIconAvailable( | 231 void IconCacherImpl::FinishRequestAndNotifyIconAvailable( |
| 231 const GURL& request_url, | 232 const GURL& request_url, |
| 232 bool newly_available) { | 233 bool newly_available) { |
| 233 std::vector<base::Closure> callbacks = | 234 std::vector<base::Closure> callbacks = |
| 234 std::move(in_flight_requests_[request_url]); | 235 std::move(in_flight_requests_[request_url]); |
| 235 in_flight_requests_.erase(request_url); | 236 in_flight_requests_.erase(request_url); |
| 236 if (!newly_available) { | 237 if (!newly_available) { |
| 237 return; | 238 return; |
| 238 } | 239 } |
| 239 for (const base::Closure& callback : callbacks) { | 240 for (const base::Closure& callback : callbacks) { |
| 240 if (callback) { | 241 if (callback) { |
| 241 callback.Run(); | 242 callback.Run(); |
| 242 } | 243 } |
| 243 } | 244 } |
| 244 } | 245 } |
| 245 | 246 |
| 246 } // namespace ntp_tiles | 247 } // namespace ntp_tiles |
| OLD | NEW |