summaryrefslogtreecommitdiffstats
path: root/ipc/attachment_broker_privileged.cc
blob: 1fe3a75e73ec2381ea4e063bab5e5925103db465 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ipc/attachment_broker_privileged.h"

#include <algorithm>

#include "ipc/ipc_channel.h"

namespace IPC {

AttachmentBrokerPrivileged::AttachmentBrokerPrivileged() {}

AttachmentBrokerPrivileged::~AttachmentBrokerPrivileged() {}

void AttachmentBrokerPrivileged::RegisterCommunicationChannel(
    Channel* channel) {
  channel->set_attachment_broker_endpoint(true);
  auto it = std::find(channels_.begin(), channels_.end(), channel);
  DCHECK(channels_.end() == it);
  channels_.push_back(channel);
}

void AttachmentBrokerPrivileged::DeregisterCommunicationChannel(
    Channel* channel) {
  auto it = std::find(channels_.begin(), channels_.end(), channel);
  if (it != channels_.end())
    channels_.erase(it);
}

Channel* AttachmentBrokerPrivileged::GetChannelWithProcessId(
    base::ProcessId id) {
  auto it = std::find_if(channels_.begin(), channels_.end(),
                         [id](Channel* c) { return c->GetPeerPID() == id; });
  if (it == channels_.end())
    return nullptr;
  return *it;
}

}  // namespace IPC