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

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

Issue 1948303002: Re-land: Convert the utility process JSON parser into a Mojo service. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "components/safe_json/safe_json_parser_message_filter.h"
6
7 #include <memory>
8 #include <utility>
9
10 #include "base/json/json_reader.h"
11 #include "base/values.h"
12 #include "components/safe_json/safe_json_parser_messages.h"
13 #include "content/public/utility/utility_thread.h"
14 #include "ipc/ipc_message.h"
15
16 namespace {
17
18 bool Send(IPC::Message* message) {
19 return content::UtilityThread::Get()->Send(message);
20 }
21
22 } // namespace
23
24 namespace safe_json {
25
26 SafeJsonParserMessageFilter::SafeJsonParserMessageFilter() {
27 }
28 SafeJsonParserMessageFilter::~SafeJsonParserMessageFilter() {
29 }
30
31 bool SafeJsonParserMessageFilter::OnMessageReceived(
32 const IPC::Message& message) {
33 bool handled = true;
34 IPC_BEGIN_MESSAGE_MAP(SafeJsonParserMessageFilter, message)
35 IPC_MESSAGE_HANDLER(SafeJsonParserMsg_ParseJSON, OnParseJSON)
36 IPC_MESSAGE_UNHANDLED(handled = false)
37 IPC_END_MESSAGE_MAP()
38
39 return handled;
40 }
41
42 void SafeJsonParserMessageFilter::OnParseJSON(const std::string& json) {
43 int error_code;
44 std::string error;
45 std::unique_ptr<base::Value> value = base::JSONReader::ReadAndReturnError(
46 json, base::JSON_PARSE_RFC, &error_code, &error);
47 if (value) {
48 base::ListValue wrapper;
49 wrapper.Append(std::move(value));
50 Send(new SafeJsonParserHostMsg_ParseJSON_Succeeded(wrapper));
51 } else {
52 Send(new SafeJsonParserHostMsg_ParseJSON_Failed(error));
53 }
54
55 content::UtilityThread::Get()->ReleaseProcessIfNeeded();
56 }
57
58 } // namespace safe_json
OLDNEW
« no previous file with comments | « components/safe_json/safe_json_parser_message_filter.h ('k') | components/safe_json/safe_json_parser_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698