Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(59)

Side by Side Diff: ipc/attachment_broker.cc

Issue 1420763002: ipc: Move methods into AttachmentBroker interface. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ipc/attachment_broker.h ('k') | ipc/attachment_broker_mac_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
28 AttachmentBroker::AttachmentBroker() {} 31 AttachmentBroker::AttachmentBroker() {}
32 #endif // defined(OS_MACOSX) && !defined(OS_IOS)
33
29 AttachmentBroker::~AttachmentBroker() {} 34 AttachmentBroker::~AttachmentBroker() {}
30 35
31 bool AttachmentBroker::GetAttachmentWithId( 36 bool AttachmentBroker::GetAttachmentWithId(
32 BrokerableAttachment::AttachmentId id, 37 BrokerableAttachment::AttachmentId id,
33 scoped_refptr<BrokerableAttachment>* out_attachment) { 38 scoped_refptr<BrokerableAttachment>* out_attachment) {
34 for (AttachmentVector::iterator it = attachments_.begin(); 39 for (AttachmentVector::iterator it = attachments_.begin();
35 it != attachments_.end(); ++it) { 40 it != attachments_.end(); ++it) {
36 if ((*it)->GetIdentifier() == id) { 41 if ((*it)->GetIdentifier() == id) {
37 *out_attachment = *it; 42 *out_attachment = *it;
38 attachments_.erase(it); 43 attachments_.erase(it);
39 return true; 44 return true;
40 } 45 }
41 } 46 }
42 return false; 47 return false;
43 } 48 }
44 49
45 void AttachmentBroker::AddObserver(AttachmentBroker::Observer* observer) { 50 void AttachmentBroker::AddObserver(AttachmentBroker::Observer* observer) {
46 auto it = std::find(observers_.begin(), observers_.end(), observer); 51 auto it = std::find(observers_.begin(), observers_.end(), observer);
47 if (it == observers_.end()) 52 if (it == observers_.end())
48 observers_.push_back(observer); 53 observers_.push_back(observer);
49 } 54 }
50 55
51 void AttachmentBroker::RemoveObserver(AttachmentBroker::Observer* observer) { 56 void AttachmentBroker::RemoveObserver(AttachmentBroker::Observer* observer) {
52 auto it = std::find(observers_.begin(), observers_.end(), observer); 57 auto it = std::find(observers_.begin(), observers_.end(), observer);
53 if (it != observers_.end()) 58 if (it != observers_.end())
54 observers_.erase(it); 59 observers_.erase(it);
55 } 60 }
56 61
62 void AttachmentBroker::RegisterCommunicationChannel(Endpoint* endpoint) {
63 NOTREACHED();
64 }
65
66 void AttachmentBroker::DeregisterCommunicationChannel(Endpoint* endpoint) {
67 NOTREACHED();
68 }
69
57 void AttachmentBroker::HandleReceivedAttachment( 70 void AttachmentBroker::HandleReceivedAttachment(
58 const scoped_refptr<BrokerableAttachment>& attachment) { 71 const scoped_refptr<BrokerableAttachment>& attachment) {
59 attachments_.push_back(attachment); 72 attachments_.push_back(attachment);
60 NotifyObservers(attachment->GetIdentifier()); 73 NotifyObservers(attachment->GetIdentifier());
61 } 74 }
62 75
63 void AttachmentBroker::NotifyObservers( 76 void AttachmentBroker::NotifyObservers(
64 const BrokerableAttachment::AttachmentId& id) { 77 const BrokerableAttachment::AttachmentId& id) {
65 // Make a copy of observers_ to avoid mutations during iteration. 78 // Make a copy of observers_ to avoid mutations during iteration.
66 std::vector<Observer*> observers = observers_; 79 std::vector<Observer*> observers = observers_;
67 for (Observer* observer : observers) { 80 for (Observer* observer : observers) {
68 observer->ReceivedBrokerableAttachmentWithId(id); 81 observer->ReceivedBrokerableAttachmentWithId(id);
69 } 82 }
70 } 83 }
71 84
72 } // namespace IPC 85 } // namespace IPC
OLDNEW
« no previous file with comments | « ipc/attachment_broker.h ('k') | ipc/attachment_broker_mac_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698