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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
(...skipping 30 matching lines...) Expand all Loading... | |
41 error_callback_(error_callback) {} | 41 error_callback_(error_callback) {} |
42 | 42 |
43 TestingJsonParser::~TestingJsonParser() {} | 43 TestingJsonParser::~TestingJsonParser() {} |
44 | 44 |
45 void TestingJsonParser::Start() { | 45 void TestingJsonParser::Start() { |
46 int error_code; | 46 int error_code; |
47 std::string error; | 47 std::string error; |
48 scoped_ptr<base::Value> value = base::JSONReader::ReadAndReturnError( | 48 scoped_ptr<base::Value> value = base::JSONReader::ReadAndReturnError( |
49 unsafe_json_, base::JSON_PARSE_RFC, &error_code, &error); | 49 unsafe_json_, base::JSON_PARSE_RFC, &error_code, &error); |
50 | 50 |
51 // Run the callback asynchronously. | 51 // Run the callback asynchronously. Post the delete task first, so that the |
52 // completion callbacks may quit the run loop without leaking |this|. | |
53 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); | |
52 base::MessageLoop::current()->PostTask( | 54 base::MessageLoop::current()->PostTask( |
53 FROM_HERE, value ? base::Bind(success_callback_, base::Passed(&value)) | 55 FROM_HERE, value ? base::Bind(success_callback_, base::Passed(&value)) |
54 : base::Bind(error_callback_, error)); | 56 : base::Bind(error_callback_, error)); |
55 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); | |
Bernhard Bauer
2015/12/16 08:48:00
Hm… in principle we could also delete this object
Robert Sesek
2015/12/16 15:55:48
Yeah, that's true, but there's no real difference
| |
56 } | 57 } |
57 | 58 |
58 } // namespace | 59 } // namespace |
OLD | NEW |