| 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.h" | 5 #include "components/ntp_tiles/popular_sites.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 12 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
| 13 #include "base/files/important_file_writer.h" | 13 #include "base/files/important_file_writer.h" |
| 14 #include "base/json/json_reader.h" | 14 #include "base/json/json_reader.h" |
| 15 #include "base/json/json_writer.h" | 15 #include "base/json/json_writer.h" |
| 16 #include "base/path_service.h" | 16 #include "base/path_service.h" |
| 17 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
| 18 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
| 19 #include "base/task_runner_util.h" | 19 #include "base/task_runner_util.h" |
| 20 #include "base/time/time.h" | 20 #include "base/time/time.h" |
| 21 #include "base/values.h" | 21 #include "base/values.h" |
| 22 #include "components/google/core/browser/google_util.h" | 22 #include "components/google/core/browser/google_util.h" |
| 23 #include "components/ntp_tiles/pref_names.h" | 23 #include "components/ntp_tiles/pref_names.h" |
| 24 #include "components/ntp_tiles/switches.h" | 24 #include "components/ntp_tiles/switches.h" |
| 25 #include "components/pref_registry/pref_registry_syncable.h" | 25 #include "components/pref_registry/pref_registry_syncable.h" |
| 26 #include "components/prefs/pref_service.h" | 26 #include "components/prefs/pref_service.h" |
| 27 #include "components/safe_json/safe_json_parser.h" | 27 #include "components/safe_json/safe_json_parser.h" |
| 28 #include "components/search_engines/search_engine_type.h" | 28 #include "components/search_engines/search_engine_type.h" |
| 29 #include "components/search_engines/template_url_prepopulate_data.h" | |
| 30 #include "components/search_engines/template_url_service.h" | 29 #include "components/search_engines/template_url_service.h" |
| 31 #include "components/variations/service/variations_service.h" | 30 #include "components/variations/service/variations_service.h" |
| 32 #include "net/base/load_flags.h" | 31 #include "net/base/load_flags.h" |
| 33 #include "net/http/http_status_code.h" | 32 #include "net/http/http_status_code.h" |
| 34 | 33 |
| 35 using net::URLFetcher; | 34 using net::URLFetcher; |
| 36 using variations::VariationsService; | 35 using variations::VariationsService; |
| 37 | 36 |
| 38 namespace { | 37 namespace { |
| 39 | 38 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 58 if (!cmd_line->HasSwitch( | 57 if (!cmd_line->HasSwitch( |
| 59 ntp_tiles::switches::kEnableNTPSearchEngineCountryDetection)) | 58 ntp_tiles::switches::kEnableNTPSearchEngineCountryDetection)) |
| 60 return std::string(); | 59 return std::string(); |
| 61 | 60 |
| 62 const TemplateURL* default_provider = | 61 const TemplateURL* default_provider = |
| 63 template_url_service->GetDefaultSearchProvider(); | 62 template_url_service->GetDefaultSearchProvider(); |
| 64 // It's possible to not have a default provider in the case that the default | 63 // It's possible to not have a default provider in the case that the default |
| 65 // search engine is defined by policy. | 64 // search engine is defined by policy. |
| 66 if (default_provider) { | 65 if (default_provider) { |
| 67 bool is_google_search_engine = | 66 bool is_google_search_engine = |
| 68 TemplateURLPrepopulateData::GetEngineType( | 67 default_provider->GetEngineType( |
| 69 *default_provider, template_url_service->search_terms_data()) == | 68 template_url_service->search_terms_data()) == |
| 70 SearchEngineType::SEARCH_ENGINE_GOOGLE; | 69 SearchEngineType::SEARCH_ENGINE_GOOGLE; |
| 71 | 70 |
| 72 if (is_google_search_engine) { | 71 if (is_google_search_engine) { |
| 73 GURL search_url = default_provider->GenerateSearchURL( | 72 GURL search_url = default_provider->GenerateSearchURL( |
| 74 template_url_service->search_terms_data()); | 73 template_url_service->search_terms_data()); |
| 75 return google_util::GetGoogleCountryCode(search_url); | 74 return google_util::GetGoogleCountryCode(search_url); |
| 76 } | 75 } |
| 77 } | 76 } |
| 78 | 77 |
| 79 return std::string(); | 78 return std::string(); |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 DLOG(WARNING) << "Download country site list failed"; | 392 DLOG(WARNING) << "Download country site list failed"; |
| 394 is_fallback_ = true; | 393 is_fallback_ = true; |
| 395 pending_country_ = kPopularSitesDefaultCountryCode; | 394 pending_country_ = kPopularSitesDefaultCountryCode; |
| 396 pending_version_ = kPopularSitesDefaultVersion; | 395 pending_version_ = kPopularSitesDefaultVersion; |
| 397 FetchPopularSites(GetPopularSitesURL()); | 396 FetchPopularSites(GetPopularSitesURL()); |
| 398 } else { | 397 } else { |
| 399 DLOG(WARNING) << "Download fallback site list failed"; | 398 DLOG(WARNING) << "Download fallback site list failed"; |
| 400 callback_.Run(false); | 399 callback_.Run(false); |
| 401 } | 400 } |
| 402 } | 401 } |
| OLD | NEW |