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

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

Issue 10134008: Add bind(), recvFrom(), sendTo() for UDP socket. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Update Created 8 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
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 "base/values.h"
10 #include "chrome/browser/extensions/extension_event_router.h" 10 #include "chrome/browser/extensions/extension_event_router.h"
(...skipping 13 matching lines...) Expand all
24 const char kEventTypeKey[] = "type"; 24 const char kEventTypeKey[] = "type";
25 const char kEventTypeConnectComplete[] = "connectComplete"; 25 const char kEventTypeConnectComplete[] = "connectComplete";
26 const char kEventTypeDataRead[] = "dataRead"; 26 const char kEventTypeDataRead[] = "dataRead";
27 const char kEventTypeWriteComplete[] = "writeComplete"; 27 const char kEventTypeWriteComplete[] = "writeComplete";
28 28
29 const char kSrcIdKey[] = "srcId"; 29 const char kSrcIdKey[] = "srcId";
30 const char kIsFinalEventKey[] = "isFinalEvent"; 30 const char kIsFinalEventKey[] = "isFinalEvent";
31 31
32 const char kResultCodeKey[] = "resultCode"; 32 const char kResultCodeKey[] = "resultCode";
33 const char kDataKey[] = "data"; 33 const char kDataKey[] = "data";
34 const char kAddressKey[] = "address";
35 const char kPortKey[] = "port";
34 36
35 APIResourceEventNotifier::APIResourceEventNotifier( 37 APIResourceEventNotifier::APIResourceEventNotifier(
36 ExtensionEventRouter* router, 38 ExtensionEventRouter* router,
37 Profile* profile, 39 Profile* profile,
38 const std::string& src_extension_id, 40 const std::string& src_extension_id,
39 int src_id, 41 int src_id,
40 const GURL& src_url) 42 const GURL& src_url)
41 : router_(router), 43 : router_(router),
42 profile_(profile), 44 profile_(profile),
43 src_extension_id_(src_extension_id), 45 src_extension_id_(src_extension_id),
44 src_id_(src_id), 46 src_id_(src_id),
45 src_url_(src_url) {} 47 src_url_(src_url) {}
46 48
47 APIResourceEventNotifier::~APIResourceEventNotifier() {} 49 APIResourceEventNotifier::~APIResourceEventNotifier() {}
48 50
49 void APIResourceEventNotifier::OnConnectComplete(int result_code) { 51 void APIResourceEventNotifier::OnConnectComplete(int result_code) {
50 SendEventWithResultCode(API_RESOURCE_EVENT_CONNECT_COMPLETE, result_code); 52 SendEventWithResultCode(API_RESOURCE_EVENT_CONNECT_COMPLETE, result_code);
51 } 53 }
52 54
53 void APIResourceEventNotifier::OnDataRead(int result_code, 55 void APIResourceEventNotifier::OnDataRead(int result_code,
54 base::ListValue* data) { 56 base::ListValue* data,
57 const std::string& address,
58 int port) {
55 // Do we have a destination for this event? There will be one if a source id 59 // Do we have a destination for this event? There will be one if a source id
56 // was injected by the request handler for the resource's create method in 60 // was injected by the request handler for the resource's create method in
57 // schema_generated_bindings.js, which will in turn be the case if the caller 61 // schema_generated_bindings.js, which will in turn be the case if the caller
58 // of the create method provided an onEvent closure. 62 // of the create method provided an onEvent closure.
59 if (src_id_ < 0) { 63 if (src_id_ < 0) {
60 delete data; 64 delete data;
61 return; 65 return;
62 } 66 }
63 67
64 DictionaryValue* event = CreateAPIResourceEvent( 68 DictionaryValue* event = CreateAPIResourceEvent(
65 API_RESOURCE_EVENT_DATA_READ); 69 API_RESOURCE_EVENT_DATA_READ);
66 event->SetInteger(kResultCodeKey, result_code); 70 event->SetInteger(kResultCodeKey, result_code);
67 event->Set(kDataKey, data); 71 event->Set(kDataKey, data);
72 event->SetString(kAddressKey, address);
73 event->SetInteger(kPortKey, port);
68 DispatchEvent(event); 74 DispatchEvent(event);
69 } 75 }
70 76
71 void APIResourceEventNotifier::OnWriteComplete(int result_code) { 77 void APIResourceEventNotifier::OnWriteComplete(int result_code) {
72 SendEventWithResultCode(API_RESOURCE_EVENT_WRITE_COMPLETE, result_code); 78 SendEventWithResultCode(API_RESOURCE_EVENT_WRITE_COMPLETE, result_code);
73 } 79 }
74 80
75 void APIResourceEventNotifier::SendEventWithResultCode( 81 void APIResourceEventNotifier::SendEventWithResultCode(
76 APIResourceEventType event_type, 82 APIResourceEventType event_type,
77 int result_code) { 83 int result_code) {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 return kEventTypeDataRead; 135 return kEventTypeDataRead;
130 case API_RESOURCE_EVENT_WRITE_COMPLETE: 136 case API_RESOURCE_EVENT_WRITE_COMPLETE:
131 return kEventTypeWriteComplete; 137 return kEventTypeWriteComplete;
132 } 138 }
133 139
134 NOTREACHED(); 140 NOTREACHED();
135 return std::string(); 141 return std::string();
136 } 142 }
137 143
138 } // namespace extensions 144 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/api_resource_event_notifier.h ('k') | chrome/browser/extensions/api/socket/socket.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698