Chromium Code Reviews| Index: chrome/browser/android/ntp/popular_sites.cc |
| diff --git a/chrome/browser/android/ntp/popular_sites.cc b/chrome/browser/android/ntp/popular_sites.cc |
| index 0adb9328d825d70a5c95e63f3122fdaa519e6a1f..83cfe3ccddd0d87ce922d45df56452ea660939ba 100644 |
| --- a/chrome/browser/android/ntp/popular_sites.cc |
| +++ b/chrome/browser/android/ntp/popular_sites.cc |
| @@ -25,7 +25,9 @@ |
| #include "components/ntp_tiles/switches.h" |
| #include "components/pref_registry/pref_registry_syncable.h" |
| #include "components/prefs/pref_service.h" |
| +#if !defined(OS_IOS) |
|
Marc Treib
2016/06/07 09:03:07
This should go in a separate block, below the non-
sfiera
2016/06/07 12:43:52
Done.
|
| #include "components/safe_json/safe_json_parser.h" |
| +#endif |
| #include "components/search_engines/search_engine_type.h" |
| #include "components/search_engines/template_url_prepopulate_data.h" |
| #include "components/search_engines/template_url_service.h" |
| @@ -136,6 +138,44 @@ bool WriteJsonToFile(const base::FilePath& local_path, |
| json_string); |
| } |
| +#if defined(OS_IOS) |
| +// Mimics SafeJsonParser API, but parses unsafely for iOS. |
| +class JsonUnsafeParser { |
| + public: |
| + using SuccessCallback = base::Callback<void(std::unique_ptr<base::Value>)>; |
| + using ErrorCallback = base::Callback<void(const std::string&)>; |
| + |
| + // As with SafeJsonParser, runs either success_callback or error_callback on |
| + // the calling thread, but not before the call returns. |
| + static void Parse(const std::string& unsafe_json, |
| + const SuccessCallback& success_callback, |
| + const ErrorCallback& error_callback) { |
| + base::ThreadTaskRunnerHandle::Get()->PostTask( |
| + FROM_HERE, |
| + base::Bind(DoParse, unsafe_json, success_callback, error_callback)); |
| + } |
| + |
| + JsonUnsafeParser() = delete; |
| + |
| + private: |
| + static void DoParse(const std::string& unsafe_json, |
| + const SuccessCallback& success_callback, |
| + const ErrorCallback& error_callback) { |
| + auto value = |
|
Marc Treib
2016/06/07 09:03:07
Use the actual type please
sfiera
2016/06/07 12:43:52
Done.
|
| + base::JSONReader::Read(unsafe_json, base::JSON_ALLOW_TRAILING_COMMAS); |
| + if (value) { |
| + success_callback.Run(std::move(value)); |
| + } else { |
| + error_callback.Run("JSON parsing failed"); |
|
Marc Treib
2016/06/07 09:03:07
JSONReader has a ReadAndReturnError, maybe use tha
sfiera
2016/06/07 12:43:52
Done.
|
| + } |
| + } |
| +}; |
| + |
| +using UntrustedJsonParser = JsonUnsafeParser; |
| +#else |
| +using UntrustedJsonParser = safe_json::SafeJsonParser; |
| +#endif |
| + |
| } // namespace |
| base::FilePath ChromePopularSites::GetDirectory() { |
| @@ -325,7 +365,7 @@ void PopularSites::OnURLFetchComplete(const net::URLFetcher* source) { |
| return; |
| } |
| - safe_json::SafeJsonParser::Parse( |
| + UntrustedJsonParser::Parse( |
| json_string, |
| base::Bind(&PopularSites::OnJsonParsed, weak_ptr_factory_.GetWeakPtr()), |
| base::Bind(&PopularSites::OnJsonParseFailed, |