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

Side by Side Diff: chrome/browser/extensions/api/api_resource_event_notifier.cc

Issue 10095020: Allow socket API to send binary data. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Jeremy's judgments. Antonits. Created 8 years, 8 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/api_resource_event_notifier.h" 5 #include "chrome/browser/extensions/api/api_resource_event_notifier.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/json/json_writer.h" 8 #include "base/json/json_writer.h"
9 #include "base/values.h"
9 #include "chrome/browser/extensions/extension_event_router.h" 10 #include "chrome/browser/extensions/extension_event_router.h"
10 #include "chrome/browser/profiles/profile.h" 11 #include "chrome/browser/profiles/profile.h"
11 #include "content/public/browser/browser_thread.h" 12 #include "content/public/browser/browser_thread.h"
12 13
13 using content::BrowserThread; 14 using content::BrowserThread;
14 15
15 namespace events { 16 namespace events {
16 // TODO(miket): This should be generic, but at the moment only socket sends 17 // TODO(miket): This should be generic, but at the moment only socket sends
17 // onEvent events. We'll fix this when serial becomes nonblocking. 18 // onEvent events. We'll fix this when serial becomes nonblocking.
18 const char kOnAPIResourceEvent[] = "experimental.socket.onEvent"; 19 const char kOnAPIResourceEvent[] = "experimental.socket.onEvent";
(...skipping 24 matching lines...) Expand all
43 src_id_(src_id), 44 src_id_(src_id),
44 src_url_(src_url) {} 45 src_url_(src_url) {}
45 46
46 APIResourceEventNotifier::~APIResourceEventNotifier() {} 47 APIResourceEventNotifier::~APIResourceEventNotifier() {}
47 48
48 void APIResourceEventNotifier::OnConnectComplete(int result_code) { 49 void APIResourceEventNotifier::OnConnectComplete(int result_code) {
49 SendEventWithResultCode(API_RESOURCE_EVENT_CONNECT_COMPLETE, result_code); 50 SendEventWithResultCode(API_RESOURCE_EVENT_CONNECT_COMPLETE, result_code);
50 } 51 }
51 52
52 void APIResourceEventNotifier::OnDataRead(int result_code, 53 void APIResourceEventNotifier::OnDataRead(int result_code,
53 const std::string& data) { 54 base::ListValue* data) {
54 // Do we have a destination for this event? There will be one if a source id 55 // Do we have a destination for this event? There will be one if a source id
55 // was injected by the request handler for the resource's create method in 56 // was injected by the request handler for the resource's create method in
56 // schema_generated_bindings.js, which will in turn be the case if the caller 57 // schema_generated_bindings.js, which will in turn be the case if the caller
57 // of the create method provided an onEvent closure. 58 // of the create method provided an onEvent closure.
58 if (src_id_ < 0) 59 if (src_id_ < 0) {
60 delete data;
59 return; 61 return;
62 }
60 63
61 DictionaryValue* event = CreateAPIResourceEvent( 64 DictionaryValue* event = CreateAPIResourceEvent(
62 API_RESOURCE_EVENT_DATA_READ); 65 API_RESOURCE_EVENT_DATA_READ);
63 event->SetInteger(kResultCodeKey, result_code); 66 event->SetInteger(kResultCodeKey, result_code);
64 event->SetString(kDataKey, data); 67 event->Set(kDataKey, data);
65 DispatchEvent(event); 68 DispatchEvent(event);
66 } 69 }
67 70
68 void APIResourceEventNotifier::OnWriteComplete(int result_code) { 71 void APIResourceEventNotifier::OnWriteComplete(int result_code) {
69 SendEventWithResultCode(API_RESOURCE_EVENT_WRITE_COMPLETE, result_code); 72 SendEventWithResultCode(API_RESOURCE_EVENT_WRITE_COMPLETE, result_code);
70 } 73 }
71 74
72 void APIResourceEventNotifier::SendEventWithResultCode( 75 void APIResourceEventNotifier::SendEventWithResultCode(
73 APIResourceEventType event_type, 76 APIResourceEventType event_type,
74 int result_code) { 77 int result_code) {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 return kEventTypeDataRead; 129 return kEventTypeDataRead;
127 case API_RESOURCE_EVENT_WRITE_COMPLETE: 130 case API_RESOURCE_EVENT_WRITE_COMPLETE:
128 return kEventTypeWriteComplete; 131 return kEventTypeWriteComplete;
129 } 132 }
130 133
131 NOTREACHED(); 134 NOTREACHED();
132 return std::string(); 135 return std::string();
133 } 136 }
134 137
135 } // namespace extensions 138 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/api_resource_event_notifier.h ('k') | chrome/browser/extensions/api/serial/serial_api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698