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.h" | 5 #include "ipc/attachment_broker.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 namespace { | 9 namespace { |
10 IPC::AttachmentBroker* g_attachment_broker = nullptr; | 10 IPC::AttachmentBroker* g_attachment_broker = nullptr; |
11 } | 11 } |
12 | 12 |
13 namespace IPC { | 13 namespace IPC { |
14 | 14 |
15 // static | 15 // static |
16 void AttachmentBroker::SetGlobal(AttachmentBroker* broker) { | 16 void AttachmentBroker::SetGlobal(AttachmentBroker* broker) { |
17 CHECK(!g_attachment_broker || !broker) | 17 CHECK(!g_attachment_broker || !broker) |
18 << "Global attachment broker address: " << broker | 18 << "Global attachment broker address: " << broker |
19 << ". New attachment broker address: " << broker; | 19 << ". New attachment broker address: " << broker; |
20 g_attachment_broker = broker; | 20 g_attachment_broker = broker; |
21 } | 21 } |
22 | 22 |
23 // static | 23 // static |
24 AttachmentBroker* AttachmentBroker::GetGlobal() { | 24 AttachmentBroker* AttachmentBroker::GetGlobal() { |
25 return g_attachment_broker; | 25 return g_attachment_broker; |
26 } | 26 } |
27 | 27 |
28 #if defined(OS_MACOSX) && !defined(OS_IOS) | |
29 AttachmentBroker::AttachmentBroker() : port_provider_(nullptr) {} | |
30 #else | |
31 AttachmentBroker::AttachmentBroker() {} | 28 AttachmentBroker::AttachmentBroker() {} |
32 #endif // defined(OS_MACOSX) && !defined(OS_IOS) | |
33 | |
34 AttachmentBroker::~AttachmentBroker() {} | 29 AttachmentBroker::~AttachmentBroker() {} |
35 | 30 |
36 bool AttachmentBroker::GetAttachmentWithId( | 31 bool AttachmentBroker::GetAttachmentWithId( |
37 BrokerableAttachment::AttachmentId id, | 32 BrokerableAttachment::AttachmentId id, |
38 scoped_refptr<BrokerableAttachment>* out_attachment) { | 33 scoped_refptr<BrokerableAttachment>* out_attachment) { |
39 for (AttachmentVector::iterator it = attachments_.begin(); | 34 for (AttachmentVector::iterator it = attachments_.begin(); |
40 it != attachments_.end(); ++it) { | 35 it != attachments_.end(); ++it) { |
41 if ((*it)->GetIdentifier() == id) { | 36 if ((*it)->GetIdentifier() == id) { |
42 *out_attachment = *it; | 37 *out_attachment = *it; |
43 attachments_.erase(it); | 38 attachments_.erase(it); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 void AttachmentBroker::NotifyObservers( | 71 void AttachmentBroker::NotifyObservers( |
77 const BrokerableAttachment::AttachmentId& id) { | 72 const BrokerableAttachment::AttachmentId& id) { |
78 // Make a copy of observers_ to avoid mutations during iteration. | 73 // Make a copy of observers_ to avoid mutations during iteration. |
79 std::vector<Observer*> observers = observers_; | 74 std::vector<Observer*> observers = observers_; |
80 for (Observer* observer : observers) { | 75 for (Observer* observer : observers) { |
81 observer->ReceivedBrokerableAttachmentWithId(id); | 76 observer->ReceivedBrokerableAttachmentWithId(id); |
82 } | 77 } |
83 } | 78 } |
84 | 79 |
85 } // namespace IPC | 80 } // namespace IPC |
OLD | NEW |