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

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

Issue 2539363004: Make base::Value::TYPE a scoped enum. (Closed)
Patch Set: Rebase Created 4 years 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/json_sanitizer.h" 5 #include "components/safe_json/json_sanitizer.h"
6 6
7 #if defined(OS_ANDROID) 7 #if defined(OS_ANDROID)
8 #error Build json_sanitizer_android.cc instead of this file on Android. 8 #error Build json_sanitizer_android.cc instead of this file on Android.
9 #endif 9 #endif
10 10
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 base::Unretained(this))); 54 base::Unretained(this)));
55 } 55 }
56 56
57 void OopJsonSanitizer::OnParseSuccess(std::unique_ptr<base::Value> value) { 57 void OopJsonSanitizer::OnParseSuccess(std::unique_ptr<base::Value> value) {
58 // Self-destruct at the end of this method. 58 // Self-destruct at the end of this method.
59 std::unique_ptr<OopJsonSanitizer> deleter(this); 59 std::unique_ptr<OopJsonSanitizer> deleter(this);
60 60
61 // A valid JSON document may only have a dictionary or list as its top-level 61 // A valid JSON document may only have a dictionary or list as its top-level
62 // type, but the JSON parser also accepts other types, so we filter them out. 62 // type, but the JSON parser also accepts other types, so we filter them out.
63 base::Value::Type type = value->GetType(); 63 base::Value::Type type = value->GetType();
64 if (type != base::Value::TYPE_DICTIONARY && type != base::Value::TYPE_LIST) { 64 if (type != base::Value::Type::DICTIONARY &&
65 type != base::Value::Type::LIST) {
65 error_callback_.Run("Invalid top-level type"); 66 error_callback_.Run("Invalid top-level type");
66 return; 67 return;
67 } 68 }
68 69
69 std::string json; 70 std::string json;
70 if (!base::JSONWriter::Write(*value, &json)) { 71 if (!base::JSONWriter::Write(*value, &json)) {
71 error_callback_.Run("Encoding error"); 72 error_callback_.Run("Encoding error");
72 return; 73 return;
73 } 74 }
74 75
75 success_callback_.Run(json); 76 success_callback_.Run(json);
76 } 77 }
77 78
78 void OopJsonSanitizer::OnParseError(const std::string& error) { 79 void OopJsonSanitizer::OnParseError(const std::string& error) {
79 error_callback_.Run("Parse error: " + error); 80 error_callback_.Run("Parse error: " + error);
80 delete this; 81 delete this;
81 } 82 }
82 83
83 } // namespace 84 } // namespace
84 85
85 // static 86 // static
86 void JsonSanitizer::Sanitize(const std::string& unsafe_json, 87 void JsonSanitizer::Sanitize(const std::string& unsafe_json,
87 const StringCallback& success_callback, 88 const StringCallback& success_callback,
88 const StringCallback& error_callback) { 89 const StringCallback& error_callback) {
89 // OopJsonSanitizer destroys itself when it is finished. 90 // OopJsonSanitizer destroys itself when it is finished.
90 new OopJsonSanitizer(unsafe_json, success_callback, error_callback); 91 new OopJsonSanitizer(unsafe_json, success_callback, error_callback);
91 } 92 }
92 93
93 } // namespace safe_json 94 } // namespace safe_json
OLDNEW
« no previous file with comments | « components/safe_browsing_db/safe_browsing_api_handler_util.cc ('k') | components/safe_json/testing_json_parser_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698