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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 #else | 60 #else |
61 return nullptr; | 61 return nullptr; |
62 #endif | 62 #endif |
63 } | 63 } |
64 | 64 |
65 // This class is wrapped in a LazyInstance to ensure that its constructor is | 65 // This class is wrapped in a LazyInstance to ensure that its constructor is |
66 // only called once. The constructor creates an attachment broker and sets it as | 66 // only called once. The constructor creates an attachment broker and sets it as |
67 // the global broker. | 67 // the global broker. |
68 class AttachmentBrokerMakeOnce { | 68 class AttachmentBrokerMakeOnce { |
69 public: | 69 public: |
70 AttachmentBrokerMakeOnce() : attachment_broker_(CreateBroker()) {} | 70 AttachmentBrokerMakeOnce() { |
| 71 attachment_broker_.reset(CreateBroker().release()); |
| 72 } |
71 | 73 |
72 private: | 74 private: |
73 scoped_ptr<IPC::AttachmentBrokerPrivileged> attachment_broker_; | 75 scoped_ptr<IPC::AttachmentBrokerPrivileged> attachment_broker_; |
74 }; | 76 }; |
75 | 77 |
76 base::LazyInstance<AttachmentBrokerMakeOnce>::Leaky | 78 base::LazyInstance<AttachmentBrokerMakeOnce>::Leaky |
77 g_attachment_broker_make_once = LAZY_INSTANCE_INITIALIZER; | 79 g_attachment_broker_make_once = LAZY_INSTANCE_INITIALIZER; |
78 | 80 |
79 } // namespace | 81 } // namespace |
80 | 82 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 } | 121 } |
120 | 122 |
121 void AttachmentBrokerPrivileged::DeregisterCommunicationChannel( | 123 void AttachmentBrokerPrivileged::DeregisterCommunicationChannel( |
122 Endpoint* endpoint) { | 124 Endpoint* endpoint) { |
123 base::AutoLock auto_lock(*get_lock()); | 125 base::AutoLock auto_lock(*get_lock()); |
124 auto it = std::find(endpoints_.begin(), endpoints_.end(), endpoint); | 126 auto it = std::find(endpoints_.begin(), endpoints_.end(), endpoint); |
125 if (it != endpoints_.end()) | 127 if (it != endpoints_.end()) |
126 endpoints_.erase(it); | 128 endpoints_.erase(it); |
127 } | 129 } |
128 | 130 |
129 bool AttachmentBrokerPrivileged::IsPrivilegedBroker() { | |
130 return true; | |
131 } | |
132 | |
133 Sender* AttachmentBrokerPrivileged::GetSenderWithProcessId(base::ProcessId id) { | 131 Sender* AttachmentBrokerPrivileged::GetSenderWithProcessId(base::ProcessId id) { |
134 get_lock()->AssertAcquired(); | 132 get_lock()->AssertAcquired(); |
135 auto it = std::find_if(endpoints_.begin(), endpoints_.end(), | 133 auto it = std::find_if(endpoints_.begin(), endpoints_.end(), |
136 [id](Endpoint* c) { return c->GetPeerPID() == id; }); | 134 [id](Endpoint* c) { return c->GetPeerPID() == id; }); |
137 if (it == endpoints_.end()) | 135 if (it == endpoints_.end()) |
138 return nullptr; | 136 return nullptr; |
139 return *it; | 137 return *it; |
140 } | 138 } |
141 | 139 |
142 void AttachmentBrokerPrivileged::LogError(UMAError error) { | 140 void AttachmentBrokerPrivileged::LogError(UMAError error) { |
143 UMA_HISTOGRAM_ENUMERATION( | 141 UMA_HISTOGRAM_ENUMERATION( |
144 "IPC.AttachmentBrokerPrivileged.BrokerAttachmentError", error, ERROR_MAX); | 142 "IPC.AttachmentBrokerPrivileged.BrokerAttachmentError", error, ERROR_MAX); |
145 } | 143 } |
146 | 144 |
147 } // namespace IPC | 145 } // namespace IPC |
OLD | NEW |