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

Side by Side Diff: extensions/browser/api/sockets_udp/udp_socket_event_dispatcher.cc

Issue 1201063002: Set up the infrastructure for Extension event metrics. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebaaaaase Created 5 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
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/sockets_udp/udp_socket_event_dispatcher.h" 5 #include "extensions/browser/api/sockets_udp/udp_socket_event_dispatcher.h"
6 6
7 #include "base/lazy_instance.h" 7 #include "base/lazy_instance.h"
8 #include "extensions/browser/api/socket/udp_socket.h" 8 #include "extensions/browser/api/socket/udp_socket.h"
9 #include "extensions/browser/event_router.h" 9 #include "extensions/browser/event_router.h"
10 #include "extensions/browser/extensions_browser_client.h" 10 #include "extensions/browser/extensions_browser_client.h"
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 109
110 if (bytes_read >= 0) { 110 if (bytes_read >= 0) {
111 // Dispatch "onReceive" event. 111 // Dispatch "onReceive" event.
112 sockets_udp::ReceiveInfo receive_info; 112 sockets_udp::ReceiveInfo receive_info;
113 receive_info.socket_id = params.socket_id; 113 receive_info.socket_id = params.socket_id;
114 receive_info.data.assign(io_buffer->data(), io_buffer->data() + bytes_read); 114 receive_info.data.assign(io_buffer->data(), io_buffer->data() + bytes_read);
115 receive_info.remote_address = address; 115 receive_info.remote_address = address;
116 receive_info.remote_port = port; 116 receive_info.remote_port = port;
117 scoped_ptr<base::ListValue> args = 117 scoped_ptr<base::ListValue> args =
118 sockets_udp::OnReceive::Create(receive_info); 118 sockets_udp::OnReceive::Create(receive_info);
119 scoped_ptr<Event> event( 119 scoped_ptr<Event> event(new Event(
120 new Event(sockets_udp::OnReceive::kEventName, args.Pass())); 120 events::UNKNOWN, sockets_udp::OnReceive::kEventName, args.Pass()));
121 PostEvent(params, event.Pass()); 121 PostEvent(params, event.Pass());
122 122
123 // Post a task to delay the read until the socket is available, as 123 // Post a task to delay the read until the socket is available, as
124 // calling StartReceive at this point would error with ERR_IO_PENDING. 124 // calling StartReceive at this point would error with ERR_IO_PENDING.
125 BrowserThread::PostTask( 125 BrowserThread::PostTask(
126 params.thread_id, 126 params.thread_id,
127 FROM_HERE, 127 FROM_HERE,
128 base::Bind(&UDPSocketEventDispatcher::StartReceive, params)); 128 base::Bind(&UDPSocketEventDispatcher::StartReceive, params));
129 } else if (bytes_read == net::ERR_IO_PENDING) { 129 } else if (bytes_read == net::ERR_IO_PENDING) {
130 // This happens when resuming a socket which already had an 130 // This happens when resuming a socket which already had an
131 // active "recv" callback. 131 // active "recv" callback.
132 } else { 132 } else {
133 // Dispatch "onReceiveError" event but don't start another read to avoid 133 // Dispatch "onReceiveError" event but don't start another read to avoid
134 // potential infinite reads if we have a persistent network error. 134 // potential infinite reads if we have a persistent network error.
135 sockets_udp::ReceiveErrorInfo receive_error_info; 135 sockets_udp::ReceiveErrorInfo receive_error_info;
136 receive_error_info.socket_id = params.socket_id; 136 receive_error_info.socket_id = params.socket_id;
137 receive_error_info.result_code = bytes_read; 137 receive_error_info.result_code = bytes_read;
138 scoped_ptr<base::ListValue> args = 138 scoped_ptr<base::ListValue> args =
139 sockets_udp::OnReceiveError::Create(receive_error_info); 139 sockets_udp::OnReceiveError::Create(receive_error_info);
140 scoped_ptr<Event> event( 140 scoped_ptr<Event> event(new Event(
141 new Event(sockets_udp::OnReceiveError::kEventName, args.Pass())); 141 events::UNKNOWN, sockets_udp::OnReceiveError::kEventName, args.Pass()));
142 PostEvent(params, event.Pass()); 142 PostEvent(params, event.Pass());
143 143
144 // Since we got an error, the socket is now "paused" until the application 144 // Since we got an error, the socket is now "paused" until the application
145 // "resumes" it. 145 // "resumes" it.
146 ResumableUDPSocket* socket = 146 ResumableUDPSocket* socket =
147 params.sockets->Get(params.extension_id, params.socket_id); 147 params.sockets->Get(params.extension_id, params.socket_id);
148 if (socket) { 148 if (socket) {
149 socket->set_paused(true); 149 socket->set_paused(true);
150 } 150 }
151 } 151 }
(...skipping 22 matching lines...) Expand all
174 reinterpret_cast<content::BrowserContext*>(browser_context_id); 174 reinterpret_cast<content::BrowserContext*>(browser_context_id);
175 if (!extensions::ExtensionsBrowserClient::Get()->IsValidContext(context)) 175 if (!extensions::ExtensionsBrowserClient::Get()->IsValidContext(context))
176 return; 176 return;
177 EventRouter* router = EventRouter::Get(context); 177 EventRouter* router = EventRouter::Get(context);
178 if (router) 178 if (router)
179 router->DispatchEventToExtension(extension_id, event.Pass()); 179 router->DispatchEventToExtension(extension_id, event.Pass());
180 } 180 }
181 181
182 } // namespace core_api 182 } // namespace core_api
183 } // namespace extensions 183 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698