summaryrefslogtreecommitdiffstats
path: root/components/safe_json/safe_json_parser.cc
blob: 7d2bbfdd1302e503e4c8ba5f011bd9a3c0944e89 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/safe_json/safe_json_parser.h"

#include "build/build_config.h"

#if defined(OS_ANDROID)
#include "components/safe_json/safe_json_parser_android.h"
#else
#include "components/safe_json/safe_json_parser_impl.h"
#endif

namespace safe_json {

namespace {

SafeJsonParser::Factory g_factory = nullptr;

SafeJsonParser* Create(const std::string& unsafe_json,
                       const SafeJsonParser::SuccessCallback& success_callback,
                       const SafeJsonParser::ErrorCallback& error_callback) {
  if (g_factory)
    return g_factory(unsafe_json, success_callback, error_callback);

#if defined(OS_ANDROID)
  return new SafeJsonParserAndroid(unsafe_json, success_callback,
                                   error_callback);
#else
  return new SafeJsonParserImpl(unsafe_json, success_callback, error_callback);
#endif
}

}  // namespace

// static
void SafeJsonParser::SetFactoryForTesting(Factory factory) {
  g_factory = factory;
}

// static
void SafeJsonParser::Parse(const std::string& unsafe_json,
                           const SuccessCallback& success_callback,
                           const ErrorCallback& error_callback) {
  SafeJsonParser* parser =
      Create(unsafe_json, success_callback, error_callback);
  parser->Start();
}

}  // namespace safe_json