| 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/ntp_tiles/popular_sites_impl.h" | 5 #include "components/ntp_tiles/popular_sites_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 std::unique_ptr<net::URLFetcher> free_fetcher = std::move(fetcher_); | 373 std::unique_ptr<net::URLFetcher> free_fetcher = std::move(fetcher_); |
| 374 | 374 |
| 375 std::string json_string; | 375 std::string json_string; |
| 376 if (!(source->GetStatus().is_success() && | 376 if (!(source->GetStatus().is_success() && |
| 377 source->GetResponseCode() == net::HTTP_OK && | 377 source->GetResponseCode() == net::HTTP_OK && |
| 378 source->GetResponseAsString(&json_string))) { | 378 source->GetResponseAsString(&json_string))) { |
| 379 OnDownloadFailed(); | 379 OnDownloadFailed(); |
| 380 return; | 380 return; |
| 381 } | 381 } |
| 382 | 382 |
| 383 parse_json_.Run(json_string, base::Bind(&PopularSitesImpl::OnJsonParsed, | 383 parse_json_.Run(json_string, |
| 384 weak_ptr_factory_.GetWeakPtr()), | 384 base::Bind(&PopularSitesImpl::OnJsonParsed, |
| 385 weak_ptr_factory_.GetWeakPtr()), |
| 385 base::Bind(&PopularSitesImpl::OnJsonParseFailed, | 386 base::Bind(&PopularSitesImpl::OnJsonParseFailed, |
| 386 weak_ptr_factory_.GetWeakPtr())); | 387 weak_ptr_factory_.GetWeakPtr())); |
| 387 } | 388 } |
| 388 | 389 |
| 389 void PopularSitesImpl::OnJsonParsed(std::unique_ptr<base::Value> json) { | 390 void PopularSitesImpl::OnJsonParsed(std::unique_ptr<base::Value> json) { |
| 390 std::unique_ptr<base::ListValue> list = | 391 std::unique_ptr<base::ListValue> list = |
| 391 base::ListValue::From(std::move(json)); | 392 base::ListValue::From(std::move(json)); |
| 392 if (!list) { | 393 if (!list) { |
| 393 DLOG(WARNING) << "JSON is not a list"; | 394 DLOG(WARNING) << "JSON is not a list"; |
| 394 OnDownloadFailed(); | 395 OnDownloadFailed(); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 416 pending_url_ = GetPopularSitesURL(kPopularSitesDefaultCountryCode, | 417 pending_url_ = GetPopularSitesURL(kPopularSitesDefaultCountryCode, |
| 417 kPopularSitesDefaultVersion); | 418 kPopularSitesDefaultVersion); |
| 418 FetchPopularSites(); | 419 FetchPopularSites(); |
| 419 } else { | 420 } else { |
| 420 DLOG(WARNING) << "Download fallback site list failed"; | 421 DLOG(WARNING) << "Download fallback site list failed"; |
| 421 callback_.Run(false); | 422 callback_.Run(false); |
| 422 } | 423 } |
| 423 } | 424 } |
| 424 | 425 |
| 425 } // namespace ntp_tiles | 426 } // namespace ntp_tiles |
| OLD | NEW |