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

Side by Side Diff: extensions/browser/api/copresence_endpoints/copresence_endpoints_api.cc

Issue 820673004: json_schema_compiler: Use std::vector<char> for binary values. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@simplify_json_schema
Patch Set: Fix merge error. Created 5 years, 11 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "extensions/browser/api/copresence_endpoints/copresence_endpoints_api.h " 5 #include "extensions/browser/api/copresence_endpoints/copresence_endpoints_api.h "
6 6
7 #include "base/base64.h" 7 #include "base/base64.h"
8 #include "base/json/json_reader.h" 8 #include "base/json/json_reader.h"
9 #include "base/json/json_writer.h" 9 #include "base/json/json_writer.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 43
44 std::string Base64EncodeWithoutPadding(const std::string& data) { 44 std::string Base64EncodeWithoutPadding(const std::string& data) {
45 std::string ret = data; 45 std::string ret = data;
46 base::Base64Encode(ret, &ret); 46 base::Base64Encode(ret, &ret);
47 while (*(ret.end() - 1) == '=') 47 while (*(ret.end() - 1) == '=')
48 ret.erase(ret.end() - 1); 48 ret.erase(ret.end() - 1);
49 return ret; 49 return ret;
50 } 50 }
51 51
52 // Create a message to send to another endpoint. 52 // Create a message to send to another endpoint.
53 std::string CreateMessage(const std::string& data, 53 std::string CreateMessage(const std::vector<char>& data,
54 const std::string& local_endpoint_locator, 54 const std::string& local_endpoint_locator,
55 int remote_endpoint_id) { 55 int remote_endpoint_id) {
56 base::DictionaryValue dict; 56 base::DictionaryValue dict;
57 dict.SetString(kToField, base::IntToString(remote_endpoint_id)); 57 dict.SetString(kToField, base::IntToString(remote_endpoint_id));
58 dict.SetString(kDataField, Base64EncodeWithoutPadding(data)); 58 dict.SetString(kDataField, Base64EncodeWithoutPadding(
59 std::string(data.begin(), data.end())));
59 dict.SetString(kReplyToField, 60 dict.SetString(kReplyToField,
60 Base64EncodeWithoutPadding(local_endpoint_locator)); 61 Base64EncodeWithoutPadding(local_endpoint_locator));
61 62
62 std::string json; 63 std::string json;
63 base::JSONWriter::Write(&dict, &json); 64 base::JSONWriter::Write(&dict, &json);
64 65
65 std::string message; 66 std::string message;
66 message.push_back(static_cast<unsigned char>(json.size() & 0xff)); 67 message.push_back(static_cast<unsigned char>(json.size() & 0xff));
67 message.push_back(static_cast<unsigned char>(json.size() >> 8)); 68 message.push_back(static_cast<unsigned char>(json.size() >> 8));
68 69
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 } 229 }
229 } 230 }
230 231
231 void CopresenceEndpointFunction::DispatchOnReceiveEvent( 232 void CopresenceEndpointFunction::DispatchOnReceiveEvent(
232 int local_endpoint_id, 233 int local_endpoint_id,
233 int remote_endpoint_id, 234 int remote_endpoint_id,
234 const std::string& data) { 235 const std::string& data) {
235 core_api::copresence_endpoints::ReceiveInfo info; 236 core_api::copresence_endpoints::ReceiveInfo info;
236 info.local_endpoint_id = local_endpoint_id; 237 info.local_endpoint_id = local_endpoint_id;
237 info.remote_endpoint_id = remote_endpoint_id; 238 info.remote_endpoint_id = remote_endpoint_id;
238 info.data = data; 239 info.data.assign(data.begin(), data.end());
239 // Send the data to the client app. 240 // Send the data to the client app.
240 scoped_ptr<Event> event( 241 scoped_ptr<Event> event(
241 new Event(core_api::copresence_endpoints::OnReceive::kEventName, 242 new Event(core_api::copresence_endpoints::OnReceive::kEventName,
242 core_api::copresence_endpoints::OnReceive::Create(info), 243 core_api::copresence_endpoints::OnReceive::Create(info),
243 browser_context())); 244 browser_context()));
244 EventRouter::Get(browser_context()) 245 EventRouter::Get(browser_context())
245 ->DispatchEventToExtension(extension_id(), event.Pass()); 246 ->DispatchEventToExtension(extension_id(), event.Pass());
246 VLOG(2) << "Dispatched OnReceive event: localEndpointId = " 247 VLOG(2) << "Dispatched OnReceive event: localEndpointId = "
247 << local_endpoint_id << ", remoteEndpointId = " << remote_endpoint_id 248 << local_endpoint_id << ", remoteEndpointId = " << remote_endpoint_id
248 << " and data = " << data; 249 << " and data = " << data;
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 << std::string((message.c_str() + 2), message.size() - 2); 327 << std::string((message.c_str() + 2), message.size() - 2);
327 328
328 endpoint->endpoint()->Send(new net::StringIOBuffer(message), message.size()); 329 endpoint->endpoint()->Send(new net::StringIOBuffer(message), message.size());
329 330
330 return RespondNow( 331 return RespondNow(
331 ArgumentList(core_api::copresence_endpoints::Send::Results::Create( 332 ArgumentList(core_api::copresence_endpoints::Send::Results::Create(
332 core_api::copresence_endpoints::ENDPOINT_STATUS_NO_ERROR))); 333 core_api::copresence_endpoints::ENDPOINT_STATUS_NO_ERROR)));
333 } 334 }
334 335
335 } // namespace extensions 336 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/api/bluetooth_socket/bluetooth_socket_event_dispatcher.cc ('k') | extensions/browser/api/hid/hid_api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698