sfiera | 6e6e541 | 2016-11-18 20:13:19 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef COMPONENTS_NTP_TILES_JSON_UNSAFE_PARSER_H_ |
| 6 | #define COMPONENTS_NTP_TILES_JSON_UNSAFE_PARSER_H_ |
| 7 | |
| 8 | #include <memory> |
| 9 | #include <string> |
| 10 | |
| 11 | #include "base/callback_forward.h" |
| 12 | |
| 13 | namespace base { |
| 14 | class Value; |
| 15 | } |
| 16 | |
| 17 | namespace ntp_tiles { |
| 18 | |
| 19 | // Mimics SafeJsonParser, but parses unsafely. |
| 20 | // |
| 21 | // Do not use this class, unless you can't help it. On most platforms, |
| 22 | // SafeJsonParser is available and is safer. If it is not available (e.g. on |
| 23 | // iOS), then this class mimics its API without its safety. |
| 24 | class JsonUnsafeParser { |
| 25 | public: |
| 26 | using SuccessCallback = base::Callback<void(std::unique_ptr<base::Value>)>; |
| 27 | using ErrorCallback = base::Callback<void(const std::string&)>; |
| 28 | |
| 29 | // As with SafeJsonParser, runs either success_callback or error_callback on |
| 30 | // the calling thread, but not before the call returns. |
| 31 | static void Parse(const std::string& unsafe_json, |
| 32 | const SuccessCallback& success_callback, |
| 33 | const ErrorCallback& error_callback); |
| 34 | |
| 35 | JsonUnsafeParser() = delete; |
| 36 | }; |
| 37 | |
| 38 | } // namespace ntp_tiles |
| 39 | |
| 40 | #endif // COMPONENTS_NTP_TILES_POPULAR_SITES_H_ |