| 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_message_filter.h" | 5 #include "components/safe_json/safe_json_parser_message_filter.h" |
| 6 | 6 |
| 7 #include <utility> |
| 8 |
| 7 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
| 8 #include "base/values.h" | 10 #include "base/values.h" |
| 9 #include "components/safe_json/safe_json_parser_messages.h" | 11 #include "components/safe_json/safe_json_parser_messages.h" |
| 10 #include "content/public/utility/utility_thread.h" | 12 #include "content/public/utility/utility_thread.h" |
| 11 #include "ipc/ipc_message.h" | 13 #include "ipc/ipc_message.h" |
| 12 | 14 |
| 13 namespace { | 15 namespace { |
| 14 | 16 |
| 15 bool Send(IPC::Message* message) { | 17 bool Send(IPC::Message* message) { |
| 16 return content::UtilityThread::Get()->Send(message); | 18 return content::UtilityThread::Get()->Send(message); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 36 return handled; | 38 return handled; |
| 37 } | 39 } |
| 38 | 40 |
| 39 void SafeJsonParserMessageFilter::OnParseJSON(const std::string& json) { | 41 void SafeJsonParserMessageFilter::OnParseJSON(const std::string& json) { |
| 40 int error_code; | 42 int error_code; |
| 41 std::string error; | 43 std::string error; |
| 42 scoped_ptr<base::Value> value = base::JSONReader::ReadAndReturnError( | 44 scoped_ptr<base::Value> value = base::JSONReader::ReadAndReturnError( |
| 43 json, base::JSON_PARSE_RFC, &error_code, &error); | 45 json, base::JSON_PARSE_RFC, &error_code, &error); |
| 44 if (value) { | 46 if (value) { |
| 45 base::ListValue wrapper; | 47 base::ListValue wrapper; |
| 46 wrapper.Append(value.Pass()); | 48 wrapper.Append(std::move(value)); |
| 47 Send(new SafeJsonParserHostMsg_ParseJSON_Succeeded(wrapper)); | 49 Send(new SafeJsonParserHostMsg_ParseJSON_Succeeded(wrapper)); |
| 48 } else { | 50 } else { |
| 49 Send(new SafeJsonParserHostMsg_ParseJSON_Failed(error)); | 51 Send(new SafeJsonParserHostMsg_ParseJSON_Failed(error)); |
| 50 } | 52 } |
| 51 | 53 |
| 52 content::UtilityThread::Get()->ReleaseProcessIfNeeded(); | 54 content::UtilityThread::Get()->ReleaseProcessIfNeeded(); |
| 53 } | 55 } |
| 54 | 56 |
| 55 } // namespace safe_json | 57 } // namespace safe_json |
| OLD | NEW |