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 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 auto it = std::find_if(observers_.begin(), observers_.end(), | 51 auto it = std::find_if(observers_.begin(), observers_.end(), |
52 [observer](const ObserverInfo& info) { | 52 [observer](const ObserverInfo& info) { |
53 return info.observer == observer; | 53 return info.observer == observer; |
54 }); | 54 }); |
55 if (it == observers_.end()) { | 55 if (it == observers_.end()) { |
56 ObserverInfo info; | 56 ObserverInfo info; |
57 info.observer = observer; | 57 info.observer = observer; |
58 info.runner = runner; | 58 info.runner = runner; |
59 info.unique_id = ++last_unique_id_; | 59 info.unique_id = ++last_unique_id_; |
60 observers_.push_back(info); | 60 observers_.push_back(info); |
| 61 |
| 62 // Give the observer a chance to handle attachments that arrived while the |
| 63 // observer was handling the message that caused it to register, but our |
| 64 // mutex was not yet locked. |
| 65 for (const auto& attachment : attachments_) { |
| 66 info.runner->PostTask( |
| 67 FROM_HERE, |
| 68 base::Bind(&AttachmentBroker::NotifyObserver, base::Unretained(this), |
| 69 info.unique_id, attachment->GetIdentifier())); |
| 70 } |
61 } | 71 } |
62 } | 72 } |
63 | 73 |
64 void AttachmentBroker::RemoveObserver(AttachmentBroker::Observer* observer) { | 74 void AttachmentBroker::RemoveObserver(AttachmentBroker::Observer* observer) { |
65 base::AutoLock auto_lock(*get_lock()); | 75 base::AutoLock auto_lock(*get_lock()); |
66 auto it = std::find_if(observers_.begin(), observers_.end(), | 76 auto it = std::find_if(observers_.begin(), observers_.end(), |
67 [observer](const ObserverInfo& info) { | 77 [observer](const ObserverInfo& info) { |
68 return info.observer == observer; | 78 return info.observer == observer; |
69 }); | 79 }); |
70 if (it != observers_.end()) | 80 if (it != observers_.end()) |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 | 146 |
137 observer->ReceivedBrokerableAttachmentWithId(id); | 147 observer->ReceivedBrokerableAttachmentWithId(id); |
138 } | 148 } |
139 | 149 |
140 AttachmentBroker::ObserverInfo::ObserverInfo() {} | 150 AttachmentBroker::ObserverInfo::ObserverInfo() {} |
141 AttachmentBroker::ObserverInfo::ObserverInfo(const ObserverInfo& other) = | 151 AttachmentBroker::ObserverInfo::ObserverInfo(const ObserverInfo& other) = |
142 default; | 152 default; |
143 AttachmentBroker::ObserverInfo::~ObserverInfo() {} | 153 AttachmentBroker::ObserverInfo::~ObserverInfo() {} |
144 | 154 |
145 } // namespace IPC | 155 } // namespace IPC |
OLD | NEW |