Roll src/third_party/skia 10b371c:c71239b
[chromium-blink-merge.git] / components / safe_json / safe_json_parser.cc
blob653800e0d0586a8384b1b5c4d98b3b791e07c8ee
1 // Copyright 2013 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.
5 #include "components/safe_json/safe_json_parser.h"
7 #if defined(OS_ANDROID)
8 #include "components/safe_json/safe_json_parser_android.h"
9 #else
10 #include "components/safe_json/safe_json_parser_impl.h"
11 #endif
13 namespace safe_json {
15 namespace {
17 SafeJsonParser::Factory g_factory = nullptr;
19 SafeJsonParser* Create(const std::string& unsafe_json,
20 const SafeJsonParser::SuccessCallback& success_callback,
21 const SafeJsonParser::ErrorCallback& error_callback) {
22 if (g_factory)
23 return g_factory(unsafe_json, success_callback, error_callback);
25 #if defined(OS_ANDROID)
26 return new SafeJsonParserAndroid(unsafe_json, success_callback,
27 error_callback);
28 #else
29 return new SafeJsonParserImpl(unsafe_json, success_callback, error_callback);
30 #endif
33 } // namespace
35 // static
36 void SafeJsonParser::SetFactoryForTesting(Factory factory) {
37 g_factory = factory;
40 // static
41 void SafeJsonParser::Parse(const std::string& unsafe_json,
42 const SuccessCallback& success_callback,
43 const ErrorCallback& error_callback) {
44 SafeJsonParser* parser =
45 Create(unsafe_json, success_callback, error_callback);
46 parser->Start();
49 } // namespace safe_json