| 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 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 std::unique_ptr<net::URLFetcher> free_fetcher = std::move(fetcher_); | 369 std::unique_ptr<net::URLFetcher> free_fetcher = std::move(fetcher_); |
| 370 | 370 |
| 371 std::string json_string; | 371 std::string json_string; |
| 372 if (!(source->GetStatus().is_success() && | 372 if (!(source->GetStatus().is_success() && |
| 373 source->GetResponseCode() == net::HTTP_OK && | 373 source->GetResponseCode() == net::HTTP_OK && |
| 374 source->GetResponseAsString(&json_string))) { | 374 source->GetResponseAsString(&json_string))) { |
| 375 OnDownloadFailed(); | 375 OnDownloadFailed(); |
| 376 return; | 376 return; |
| 377 } | 377 } |
| 378 | 378 |
| 379 parse_json_.Run(json_string, base::Bind(&PopularSitesImpl::OnJsonParsed, | 379 parse_json_.Run(json_string, |
| 380 weak_ptr_factory_.GetWeakPtr()), | 380 base::Bind(&PopularSitesImpl::OnJsonParsed, |
| 381 weak_ptr_factory_.GetWeakPtr()), |
| 381 base::Bind(&PopularSitesImpl::OnJsonParseFailed, | 382 base::Bind(&PopularSitesImpl::OnJsonParseFailed, |
| 382 weak_ptr_factory_.GetWeakPtr())); | 383 weak_ptr_factory_.GetWeakPtr())); |
| 383 } | 384 } |
| 384 | 385 |
| 385 void PopularSitesImpl::OnJsonParsed(std::unique_ptr<base::Value> json) { | 386 void PopularSitesImpl::OnJsonParsed(std::unique_ptr<base::Value> json) { |
| 386 std::unique_ptr<base::ListValue> list = | 387 std::unique_ptr<base::ListValue> list = |
| 387 base::ListValue::From(std::move(json)); | 388 base::ListValue::From(std::move(json)); |
| 388 if (!list) { | 389 if (!list) { |
| 389 DLOG(WARNING) << "JSON is not a list"; | 390 DLOG(WARNING) << "JSON is not a list"; |
| 390 OnDownloadFailed(); | 391 OnDownloadFailed(); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 412 pending_url_ = GetPopularSitesURL(kPopularSitesDefaultCountryCode, | 413 pending_url_ = GetPopularSitesURL(kPopularSitesDefaultCountryCode, |
| 413 kPopularSitesDefaultVersion); | 414 kPopularSitesDefaultVersion); |
| 414 FetchPopularSites(); | 415 FetchPopularSites(); |
| 415 } else { | 416 } else { |
| 416 DLOG(WARNING) << "Download fallback site list failed"; | 417 DLOG(WARNING) << "Download fallback site list failed"; |
| 417 callback_.Run(false); | 418 callback_.Run(false); |
| 418 } | 419 } |
| 419 } | 420 } |
| 420 | 421 |
| 421 } // namespace ntp_tiles | 422 } // namespace ntp_tiles |
| OLD | NEW |