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

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

Issue 1527063002: Fix a leak in TestingJsonParser. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: With fix Created 5 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
« no previous file with comments | « components/components_tests.gyp ('k') | components/safe_json/testing_json_parser_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/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
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
OLDNEW
« no previous file with comments | « components/components_tests.gyp ('k') | components/safe_json/testing_json_parser_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698