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

Side by Side Diff: chrome/browser/extensions/api/messaging/native_message_port.cc

Issue 16226004: Replace JSON (de)serialization of extension messages with direct Value pickling. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/extensions/api/messaging/native_message_port.h" 5 #include "chrome/browser/extensions/api/messaging/native_message_port.h"
6 6
7 #include "base/bind.h"
8 #include "base/json/json_writer.h"
7 #include "chrome/browser/extensions/api/messaging/native_message_process_host.h" 9 #include "chrome/browser/extensions/api/messaging/native_message_process_host.h"
8 #include "content/public/browser/browser_thread.h" 10 #include "content/public/browser/browser_thread.h"
9 11
10 namespace extensions { 12 namespace extensions {
11 13
12 NativeMessagePort::NativeMessagePort(NativeMessageProcessHost* native_process) 14 NativeMessagePort::NativeMessagePort(NativeMessageProcessHost* native_process)
13 : native_process_(native_process) { 15 : native_process_(native_process) {
14 } 16 }
15 17
16 NativeMessagePort::~NativeMessagePort() { 18 NativeMessagePort::~NativeMessagePort() {
17 content::BrowserThread::DeleteSoon( 19 content::BrowserThread::DeleteSoon(
18 content::BrowserThread::IO, FROM_HERE, native_process_); 20 content::BrowserThread::IO, FROM_HERE, native_process_);
19 } 21 }
20 22
21 void NativeMessagePort::DispatchOnMessage(const std::string& message, 23 void NativeMessagePort::DispatchOnMessage(scoped_ptr<base::ListValue> message,
22 int target_port_id) { 24 int target_port_id) {
25 std::string message_as_json;
26 if (!message->empty()) {
27 DCHECK_EQ(1u, message->GetSize());
28 base::Value* value = NULL;
29 message->Get(0, &value);
30 base::JSONWriter::Write(value, &message_as_json);
31 }
23 content::BrowserThread::PostTask( 32 content::BrowserThread::PostTask(
24 content::BrowserThread::IO, FROM_HERE, 33 content::BrowserThread::IO, FROM_HERE,
25 base::Bind(&NativeMessageProcessHost::Send, 34 base::Bind(&NativeMessageProcessHost::Send,
26 base::Unretained(native_process_), message)); 35 base::Unretained(native_process_),
36 message_as_json));
27 } 37 }
28 38
29 } // namespace extensions 39 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698