Refactor android test results logging.
[chromium-blink-merge.git] / ppapi / proxy / plugin_message_filter.cc
blob9f178f15acc67f0c5adc8bc077460d8d44497934
1 // Copyright (c) 2011 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.
5 #include "ppapi/proxy/plugin_message_filter.h"
7 #include "ppapi/proxy/ppapi_messages.h"
9 namespace ppapi {
10 namespace proxy {
12 PluginMessageFilter::PluginMessageFilter(
13 std::set<PP_Instance>* seen_instance_ids)
14 : seen_instance_ids_(seen_instance_ids),
15 channel_(NULL) {
18 PluginMessageFilter::~PluginMessageFilter() {
21 void PluginMessageFilter::OnFilterAdded(IPC::Channel* channel) {
22 channel_ = channel;
25 void PluginMessageFilter::OnFilterRemoved() {
26 channel_ = NULL;
29 bool PluginMessageFilter::OnMessageReceived(const IPC::Message& message) {
30 bool handled = true;
31 IPC_BEGIN_MESSAGE_MAP(PluginMessageFilter, message)
32 IPC_MESSAGE_HANDLER(PpapiMsg_ReserveInstanceId, OnMsgReserveInstanceId)
33 IPC_MESSAGE_UNHANDLED(handled = false)
34 IPC_END_MESSAGE_MAP()
35 return handled;
38 bool PluginMessageFilter::Send(IPC::Message* msg) {
39 if (channel_)
40 return channel_->Send(msg);
41 delete msg;
42 return false;
45 void PluginMessageFilter::OnMsgReserveInstanceId(PP_Instance instance,
46 bool* usable) {
47 // See the message definition for how this works.
48 if (seen_instance_ids_->find(instance) != seen_instance_ids_->end()) {
49 // Instance ID already seen, reject it.
50 *usable = false;
51 return;
54 // This instance ID is new so we can return that it's usable and mark it as
55 // used for future reference.
56 seen_instance_ids_->insert(instance);
57 *usable = true;
60 } // namespace proxy
61 } // namespace ppapi