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/testing_json_parser.h" | 5 #include "components/safe_json/testing_json_parser.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
11 #include "base/json/json_reader.h" | 11 #include "base/json/json_reader.h" |
12 #include "base/location.h" | 12 #include "base/location.h" |
13 #include "base/message_loop/message_loop.h" | 13 #include "base/single_thread_task_runner.h" |
| 14 #include "base/threading/thread_task_runner_handle.h" |
14 #include "base/values.h" | 15 #include "base/values.h" |
15 | 16 |
16 namespace safe_json { | 17 namespace safe_json { |
17 | 18 |
18 namespace { | 19 namespace { |
19 | 20 |
20 SafeJsonParser* CreateTestingJsonParser( | 21 SafeJsonParser* CreateTestingJsonParser( |
21 const std::string& unsafe_json, | 22 const std::string& unsafe_json, |
22 const SafeJsonParser::SuccessCallback& success_callback, | 23 const SafeJsonParser::SuccessCallback& success_callback, |
23 const SafeJsonParser::ErrorCallback& error_callback) { | 24 const SafeJsonParser::ErrorCallback& error_callback) { |
(...skipping 20 matching lines...) Expand all Loading... |
44 TestingJsonParser::~TestingJsonParser() {} | 45 TestingJsonParser::~TestingJsonParser() {} |
45 | 46 |
46 void TestingJsonParser::Start() { | 47 void TestingJsonParser::Start() { |
47 int error_code; | 48 int error_code; |
48 std::string error; | 49 std::string error; |
49 std::unique_ptr<base::Value> value = base::JSONReader::ReadAndReturnError( | 50 std::unique_ptr<base::Value> value = base::JSONReader::ReadAndReturnError( |
50 unsafe_json_, base::JSON_PARSE_RFC, &error_code, &error); | 51 unsafe_json_, base::JSON_PARSE_RFC, &error_code, &error); |
51 | 52 |
52 // Run the callback asynchronously. Post the delete task first, so that the | 53 // Run the callback asynchronously. Post the delete task first, so that the |
53 // completion callbacks may quit the run loop without leaking |this|. | 54 // completion callbacks may quit the run loop without leaking |this|. |
54 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); | 55 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this); |
55 base::MessageLoop::current()->PostTask( | 56 base::ThreadTaskRunnerHandle::Get()->PostTask( |
56 FROM_HERE, value ? base::Bind(success_callback_, base::Passed(&value)) | 57 FROM_HERE, value ? base::Bind(success_callback_, base::Passed(&value)) |
57 : base::Bind(error_callback_, error)); | 58 : base::Bind(error_callback_, error)); |
58 } | 59 } |
59 | 60 |
60 } // namespace | 61 } // namespace |
OLD | NEW |