| 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() { | 70 AttachmentBrokerMakeOnce() : attachment_broker_(CreateBroker()) {} |
| 71 attachment_broker_.reset(CreateBroker().release()); | |
| 72 } | |
| 73 | 71 |
| 74 private: | 72 private: |
| 75 scoped_ptr<IPC::AttachmentBrokerPrivileged> attachment_broker_; | 73 scoped_ptr<IPC::AttachmentBrokerPrivileged> attachment_broker_; |
| 76 }; | 74 }; |
| 77 | 75 |
| 78 base::LazyInstance<AttachmentBrokerMakeOnce>::Leaky | 76 base::LazyInstance<AttachmentBrokerMakeOnce>::Leaky |
| 79 g_attachment_broker_make_once = LAZY_INSTANCE_INITIALIZER; | 77 g_attachment_broker_make_once = LAZY_INSTANCE_INITIALIZER; |
| 80 | 78 |
| 81 } // namespace | 79 } // namespace |
| 82 | 80 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 } | 119 } |
| 122 | 120 |
| 123 void AttachmentBrokerPrivileged::DeregisterCommunicationChannel( | 121 void AttachmentBrokerPrivileged::DeregisterCommunicationChannel( |
| 124 Endpoint* endpoint) { | 122 Endpoint* endpoint) { |
| 125 base::AutoLock auto_lock(*get_lock()); | 123 base::AutoLock auto_lock(*get_lock()); |
| 126 auto it = std::find(endpoints_.begin(), endpoints_.end(), endpoint); | 124 auto it = std::find(endpoints_.begin(), endpoints_.end(), endpoint); |
| 127 if (it != endpoints_.end()) | 125 if (it != endpoints_.end()) |
| 128 endpoints_.erase(it); | 126 endpoints_.erase(it); |
| 129 } | 127 } |
| 130 | 128 |
| 129 bool AttachmentBrokerPrivileged::IsPrivilegedBroker() { |
| 130 return true; |
| 131 } |
| 132 |
| 131 Sender* AttachmentBrokerPrivileged::GetSenderWithProcessId(base::ProcessId id) { | 133 Sender* AttachmentBrokerPrivileged::GetSenderWithProcessId(base::ProcessId id) { |
| 132 get_lock()->AssertAcquired(); | 134 get_lock()->AssertAcquired(); |
| 133 auto it = std::find_if(endpoints_.begin(), endpoints_.end(), | 135 auto it = std::find_if(endpoints_.begin(), endpoints_.end(), |
| 134 [id](Endpoint* c) { return c->GetPeerPID() == id; }); | 136 [id](Endpoint* c) { return c->GetPeerPID() == id; }); |
| 135 if (it == endpoints_.end()) | 137 if (it == endpoints_.end()) |
| 136 return nullptr; | 138 return nullptr; |
| 137 return *it; | 139 return *it; |
| 138 } | 140 } |
| 139 | 141 |
| 140 void AttachmentBrokerPrivileged::LogError(UMAError error) { | 142 void AttachmentBrokerPrivileged::LogError(UMAError error) { |
| 141 UMA_HISTOGRAM_ENUMERATION( | 143 UMA_HISTOGRAM_ENUMERATION( |
| 142 "IPC.AttachmentBrokerPrivileged.BrokerAttachmentError", error, ERROR_MAX); | 144 "IPC.AttachmentBrokerPrivileged.BrokerAttachmentError", error, ERROR_MAX); |
| 143 } | 145 } |
| 144 | 146 |
| 145 } // namespace IPC | 147 } // namespace IPC |
| OLD | NEW |