OLD | NEW |
---|---|
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 Loading... | |
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) { |
52 LOG(ERROR) << "APIResourceEventNotifier::OnConnectComplete()" << result_code; | |
miket_OOO
2012/04/24 20:49:06
Leftover?
Peng
2012/04/24 21:13:47
Done.
| |
50 SendEventWithResultCode(API_RESOURCE_EVENT_CONNECT_COMPLETE, result_code); | 53 SendEventWithResultCode(API_RESOURCE_EVENT_CONNECT_COMPLETE, result_code); |
51 } | 54 } |
52 | 55 |
53 void APIResourceEventNotifier::OnDataRead(int result_code, | 56 void APIResourceEventNotifier::OnDataRead(int result_code, |
54 base::ListValue* data) { | 57 base::ListValue* data, |
58 const std::string& address, | |
59 int port) { | |
55 // Do we have a destination for this event? There will be one if a source id | 60 // 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 | 61 // 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 | 62 // schema_generated_bindings.js, which will in turn be the case if the caller |
58 // of the create method provided an onEvent closure. | 63 // of the create method provided an onEvent closure. |
59 if (src_id_ < 0) { | 64 if (src_id_ < 0) { |
60 delete data; | 65 delete data; |
61 return; | 66 return; |
62 } | 67 } |
63 | 68 |
64 DictionaryValue* event = CreateAPIResourceEvent( | 69 DictionaryValue* event = CreateAPIResourceEvent( |
65 API_RESOURCE_EVENT_DATA_READ); | 70 API_RESOURCE_EVENT_DATA_READ); |
66 event->SetInteger(kResultCodeKey, result_code); | 71 event->SetInteger(kResultCodeKey, result_code); |
67 event->Set(kDataKey, data); | 72 event->Set(kDataKey, data); |
73 event->SetString(kAddressKey, address); | |
74 event->SetInteger(kPortKey, port); | |
68 DispatchEvent(event); | 75 DispatchEvent(event); |
69 } | 76 } |
70 | 77 |
71 void APIResourceEventNotifier::OnWriteComplete(int result_code) { | 78 void APIResourceEventNotifier::OnWriteComplete(int result_code) { |
72 SendEventWithResultCode(API_RESOURCE_EVENT_WRITE_COMPLETE, result_code); | 79 SendEventWithResultCode(API_RESOURCE_EVENT_WRITE_COMPLETE, result_code); |
73 } | 80 } |
74 | 81 |
75 void APIResourceEventNotifier::SendEventWithResultCode( | 82 void APIResourceEventNotifier::SendEventWithResultCode( |
76 APIResourceEventType event_type, | 83 APIResourceEventType event_type, |
77 int result_code) { | 84 int result_code) { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
129 return kEventTypeDataRead; | 136 return kEventTypeDataRead; |
130 case API_RESOURCE_EVENT_WRITE_COMPLETE: | 137 case API_RESOURCE_EVENT_WRITE_COMPLETE: |
131 return kEventTypeWriteComplete; | 138 return kEventTypeWriteComplete; |
132 } | 139 } |
133 | 140 |
134 NOTREACHED(); | 141 NOTREACHED(); |
135 return std::string(); | 142 return std::string(); |
136 } | 143 } |
137 | 144 |
138 } // namespace extensions | 145 } // namespace extensions |
OLD | NEW |