OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "ipc/attachment_broker_privileged.h" | 5 #include "ipc/attachment_broker_privileged.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 } | 80 } |
81 #else | 81 #else |
82 // static | 82 // static |
83 void AttachmentBrokerPrivileged::CreateBrokerIfNeeded() { | 83 void AttachmentBrokerPrivileged::CreateBrokerIfNeeded() { |
84 g_attachment_broker_make_once.Get(); | 84 g_attachment_broker_make_once.Get(); |
85 } | 85 } |
86 #endif // defined(OS_MACOSX) && !defined(OS_IOS) | 86 #endif // defined(OS_MACOSX) && !defined(OS_IOS) |
87 | 87 |
88 void AttachmentBrokerPrivileged::RegisterCommunicationChannel( | 88 void AttachmentBrokerPrivileged::RegisterCommunicationChannel( |
89 Endpoint* endpoint) { | 89 Endpoint* endpoint) { |
| 90 base::AutoLock auto_lock(*get_lock()); |
90 endpoint->SetAttachmentBrokerEndpoint(true); | 91 endpoint->SetAttachmentBrokerEndpoint(true); |
91 auto it = std::find(endpoints_.begin(), endpoints_.end(), endpoint); | 92 auto it = std::find(endpoints_.begin(), endpoints_.end(), endpoint); |
92 DCHECK(endpoints_.end() == it); | 93 DCHECK(endpoints_.end() == it); |
93 endpoints_.push_back(endpoint); | 94 endpoints_.push_back(endpoint); |
94 } | 95 } |
95 | 96 |
96 void AttachmentBrokerPrivileged::DeregisterCommunicationChannel( | 97 void AttachmentBrokerPrivileged::DeregisterCommunicationChannel( |
97 Endpoint* endpoint) { | 98 Endpoint* endpoint) { |
| 99 base::AutoLock auto_lock(*get_lock()); |
98 auto it = std::find(endpoints_.begin(), endpoints_.end(), endpoint); | 100 auto it = std::find(endpoints_.begin(), endpoints_.end(), endpoint); |
99 if (it != endpoints_.end()) | 101 if (it != endpoints_.end()) |
100 endpoints_.erase(it); | 102 endpoints_.erase(it); |
101 } | 103 } |
102 | 104 |
103 Sender* AttachmentBrokerPrivileged::GetSenderWithProcessId(base::ProcessId id) { | 105 Sender* AttachmentBrokerPrivileged::GetSenderWithProcessId(base::ProcessId id) { |
| 106 base::AutoLock auto_lock(*get_lock()); |
104 auto it = std::find_if(endpoints_.begin(), endpoints_.end(), | 107 auto it = std::find_if(endpoints_.begin(), endpoints_.end(), |
105 [id](Endpoint* c) { return c->GetPeerPID() == id; }); | 108 [id](Endpoint* c) { return c->GetPeerPID() == id; }); |
106 if (it == endpoints_.end()) | 109 if (it == endpoints_.end()) |
107 return nullptr; | 110 return nullptr; |
108 return *it; | 111 return *it; |
109 } | 112 } |
110 | 113 |
111 void AttachmentBrokerPrivileged::LogError(UMAError error) { | 114 void AttachmentBrokerPrivileged::LogError(UMAError error) { |
112 UMA_HISTOGRAM_ENUMERATION( | 115 UMA_HISTOGRAM_ENUMERATION( |
113 "IPC.AttachmentBrokerPrivileged.BrokerAttachmentError", error, ERROR_MAX); | 116 "IPC.AttachmentBrokerPrivileged.BrokerAttachmentError", error, ERROR_MAX); |
114 } | 117 } |
115 | 118 |
116 } // namespace IPC | 119 } // namespace IPC |
OLD | NEW |