Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/renderer/media/midi_message_filter.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "base/debug/trace_event.h" | |
| 9 #include "base/message_loop_proxy.h" | |
| 10 #include "content/common/media/midi_messages.h" | |
| 11 #include "content/renderer/render_thread_impl.h" | |
| 12 #include "ipc/ipc_logging.h" | |
| 13 | |
| 14 namespace content { | |
| 15 | |
| 16 MIDIMessageFilter* MIDIMessageFilter::g_filter = NULL; | |
| 17 | |
| 18 MIDIMessageFilter::MIDIMessageFilter( | |
| 19 const scoped_refptr<base::MessageLoopProxy>& io_message_loop) | |
| 20 : channel_(NULL), | |
| 21 io_message_loop_(io_message_loop), | |
| 22 client_(NULL), | |
| 23 message_loop_(NULL) { | |
| 24 DCHECK(!g_filter); | |
| 25 g_filter = this; | |
| 26 } | |
| 27 | |
| 28 MIDIMessageFilter::~MIDIMessageFilter() { | |
| 29 DCHECK_EQ(g_filter, this); | |
| 30 g_filter = NULL; | |
| 31 } | |
| 32 | |
| 33 // static | |
| 34 MIDIMessageFilter* MIDIMessageFilter::Get() { | |
| 35 return g_filter; | |
|
scherkus (not reviewing)
2013/06/03 22:44:59
AFAIK you can replace this global and RendererWebM
| |
| 36 } | |
| 37 | |
| 38 void MIDIMessageFilter::Send(IPC::Message* message) { | |
| 39 DCHECK(io_message_loop_->BelongsToCurrentThread()); | |
| 40 if (!channel_) { | |
| 41 delete message; | |
| 42 } else { | |
| 43 channel_->Send(message); | |
| 44 } | |
| 45 } | |
| 46 | |
| 47 bool MIDIMessageFilter::OnMessageReceived(const IPC::Message& message) { | |
| 48 DCHECK(io_message_loop_->BelongsToCurrentThread()); | |
| 49 bool handled = true; | |
| 50 IPC_BEGIN_MESSAGE_MAP(MIDIMessageFilter, message) | |
| 51 IPC_MESSAGE_HANDLER(MIDIMsg_AccessApproved, OnAccessApproved) | |
| 52 IPC_MESSAGE_HANDLER(MIDIMsg_DataReceived, OnDataReceived) | |
| 53 IPC_MESSAGE_UNHANDLED(handled = false) | |
| 54 IPC_END_MESSAGE_MAP() | |
| 55 return handled; | |
| 56 } | |
| 57 | |
| 58 void MIDIMessageFilter::OnFilterAdded(IPC::Channel* channel) { | |
| 59 DCHECK(io_message_loop_->BelongsToCurrentThread()); | |
| 60 channel_ = channel; | |
| 61 } | |
| 62 | |
| 63 void MIDIMessageFilter::OnFilterRemoved() { | |
| 64 DCHECK(io_message_loop_->BelongsToCurrentThread()); | |
| 65 | |
| 66 // Once removed, a filter will not be used again. At this time all | |
| 67 // delegates must be notified so they release their reference. | |
| 68 OnChannelClosing(); | |
| 69 } | |
| 70 | |
| 71 void MIDIMessageFilter::OnChannelClosing() { | |
| 72 DCHECK(io_message_loop_->BelongsToCurrentThread()); | |
| 73 channel_ = NULL; | |
| 74 } | |
| 75 | |
| 76 // Received from browser. | |
| 77 | |
| 78 void MIDIMessageFilter::OnAccessApproved(int access, bool success) { | |
| 79 } | |
| 80 | |
| 81 void MIDIMessageFilter::OnDataReceived(int port, | |
| 82 const std::vector<uint8>& data, | |
| 83 double timestamp) { | |
| 84 TRACE_EVENT0("midi", "MIDIMessageFilter::OnDataReceived"); | |
| 85 | |
| 86 #if 1 | |
| 87 if (message_loop_) { | |
| 88 message_loop_->PostTask(FROM_HERE, | |
| 89 base::Bind(&MIDIMessageFilter::HandleDataReceived, this, | |
| 90 port, data, timestamp | |
| 91 )); | |
| 92 } | |
| 93 #else | |
| 94 HandleDataReceived(port, data, timestamp); | |
| 95 #endif | |
| 96 } | |
| 97 | |
| 98 void MIDIMessageFilter::HandleDataReceived(int port, | |
| 99 const std::vector<uint8>& data, | |
| 100 double timestamp) { | |
| 101 TRACE_EVENT0("midi", "MIDIMessageFilter::HandleDataReceived"); | |
| 102 size_t n = data.size(); | |
| 103 // printf("MIDIMessageFilter::OnDataReceived(%d %f): ", (int)n, timestamp); | |
| 104 // for (size_t i = 0; i < n; ++i) { | |
| 105 // printf("%2x ", data[i]); | |
| 106 // } | |
| 107 // printf("\n"); | |
| 108 | |
| 109 if (client_ && message_loop_) | |
| 110 client_->receiveMIDIData(port, data.data(), n, timestamp); | |
| 111 } | |
| 112 | |
| 113 void MIDIMessageFilter::AddClient(WebKit::WebMIDIAccessor::Client* client) { | |
| 114 client_ = client; | |
| 115 message_loop_ = base::MessageLoop::current(); | |
| 116 } | |
| 117 | |
| 118 void MIDIMessageFilter::RemoveClient(WebKit::WebMIDIAccessor::Client* client) { | |
| 119 if (client == client_) | |
| 120 client_ = NULL; //????????????????? multiple clients?? | |
|
scherkus (not reviewing)
2013/06/03 22:44:59
I didn't see anything in the spec that mentioned m
| |
| 121 } | |
| 122 | |
| 123 } // namespace content | |
| OLD | NEW |