Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(253)

Side by Side Diff: components/safe_json/safe_json_parser.cc

Issue 1203083002: Add a JSON sanitizer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: build files Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 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/safe_json/safe_json_parser.h" 5 #include "components/safe_json/safe_json_parser.h"
6 6
7 #if defined(OS_ANDROID)
8 #include "components/safe_json/safe_json_parser_android.h"
9 #else
7 #include "components/safe_json/safe_json_parser_impl.h" 10 #include "components/safe_json/safe_json_parser_impl.h"
11 #endif
8 12
9 namespace safe_json { 13 namespace safe_json {
10 14
11 namespace { 15 namespace {
12 16
13 SafeJsonParser::Factory g_factory = nullptr; 17 SafeJsonParser::Factory g_factory = nullptr;
14 18
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);
24
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
31 }
32
15 } // namespace 33 } // namespace
16 34
17 // static 35 // static
18 void SafeJsonParser::SetFactoryForTesting(Factory factory) { 36 void SafeJsonParser::SetFactoryForTesting(Factory factory) {
19 g_factory = factory; 37 g_factory = factory;
20 } 38 }
21 39
22 // static 40 // static
23 void SafeJsonParser::Parse(const std::string& unsafe_json, 41 void SafeJsonParser::Parse(const std::string& unsafe_json,
24 const SuccessCallback& success_callback, 42 const SuccessCallback& success_callback,
25 const ErrorCallback& error_callback) { 43 const ErrorCallback& error_callback) {
26 SafeJsonParser* parser = 44 SafeJsonParser* parser =
27 g_factory ? g_factory(unsafe_json, success_callback, error_callback) 45 Create(unsafe_json, success_callback, error_callback);
28 : new SafeJsonParserImpl(unsafe_json, success_callback,
29 error_callback);
30 parser->Start(); 46 parser->Start();
31 } 47 }
32 48
33 } // namespace safe_json 49 } // namespace safe_json
OLDNEW
« no previous file with comments | « components/safe_json/json_sanitizer_unittest.cc ('k') | components/safe_json/safe_json_parser_android.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698