OLD | NEW |
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/safe_json_parser_android.h" | 5 #include "components/safe_json/safe_json_parser_android.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 unsafe_json_, | 28 unsafe_json_, |
29 base::Bind(&SafeJsonParserAndroid::OnSanitizationSuccess, | 29 base::Bind(&SafeJsonParserAndroid::OnSanitizationSuccess, |
30 base::Unretained(this)), | 30 base::Unretained(this)), |
31 base::Bind(&SafeJsonParserAndroid::OnSanitizationError, | 31 base::Bind(&SafeJsonParserAndroid::OnSanitizationError, |
32 base::Unretained(this))); | 32 base::Unretained(this))); |
33 } | 33 } |
34 | 34 |
35 void SafeJsonParserAndroid::OnSanitizationSuccess( | 35 void SafeJsonParserAndroid::OnSanitizationSuccess( |
36 const std::string& sanitized_json) { | 36 const std::string& sanitized_json) { |
37 // Self-destruct at the end of this method. | 37 // Self-destruct at the end of this method. |
38 scoped_ptr<SafeJsonParserAndroid> deleter(this); | 38 std::unique_ptr<SafeJsonParserAndroid> deleter(this); |
39 | 39 |
40 int error_code; | 40 int error_code; |
41 std::string error; | 41 std::string error; |
42 scoped_ptr<base::Value> value = base::JSONReader::ReadAndReturnError( | 42 std::unique_ptr<base::Value> value = base::JSONReader::ReadAndReturnError( |
43 sanitized_json, base::JSON_PARSE_RFC, &error_code, &error); | 43 sanitized_json, base::JSON_PARSE_RFC, &error_code, &error); |
44 | 44 |
45 if (!value) { | 45 if (!value) { |
46 error_callback_.Run(error); | 46 error_callback_.Run(error); |
47 return; | 47 return; |
48 } | 48 } |
49 | 49 |
50 success_callback_.Run(std::move(value)); | 50 success_callback_.Run(std::move(value)); |
51 } | 51 } |
52 | 52 |
53 void SafeJsonParserAndroid::OnSanitizationError(const std::string& error) { | 53 void SafeJsonParserAndroid::OnSanitizationError(const std::string& error) { |
54 error_callback_.Run(error); | 54 error_callback_.Run(error); |
55 delete this; | 55 delete this; |
56 } | 56 } |
57 | 57 |
58 } // namespace safe_json | 58 } // namespace safe_json |
OLD | NEW |