OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/service/service_ipc_server.h" | 5 #include "chrome/service/service_ipc_server.h" |
6 | 6 |
7 #include <algorithm> | |
8 | |
7 #include "base/metrics/histogram_delta_serialization.h" | 9 #include "base/metrics/histogram_delta_serialization.h" |
8 #include "build/build_config.h" | 10 #include "build/build_config.h" |
9 #include "chrome/common/service_messages.h" | 11 #include "chrome/common/service_messages.h" |
10 #include "ipc/ipc_channel_mojo.h" | 12 #include "ipc/ipc_channel_mojo.h" |
11 #include "ipc/ipc_logging.h" | 13 #include "ipc/ipc_logging.h" |
12 | 14 |
13 ServiceIPCServer::ServiceIPCServer( | 15 ServiceIPCServer::ServiceIPCServer( |
14 Client* client, | 16 Client* client, |
15 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner, | 17 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner, |
16 base::WaitableEvent* shutdown_event) | 18 base::WaitableEvent* shutdown_event) |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
68 if (!channel_.get()) { | 70 if (!channel_.get()) { |
69 delete msg; | 71 delete msg; |
70 return false; | 72 return false; |
71 } | 73 } |
72 | 74 |
73 return channel_->Send(msg); | 75 return channel_->Send(msg); |
74 } | 76 } |
75 | 77 |
76 void ServiceIPCServer::AddMessageHandler( | 78 void ServiceIPCServer::AddMessageHandler( |
77 std::unique_ptr<MessageHandler> handler) { | 79 std::unique_ptr<MessageHandler> handler) { |
78 message_handlers_.push_back(handler.release()); | 80 message_handlers_.push_back(std::move(handler)); |
79 } | 81 } |
80 | 82 |
81 bool ServiceIPCServer::OnMessageReceived(const IPC::Message& msg) { | 83 bool ServiceIPCServer::OnMessageReceived(const IPC::Message& msg) { |
82 DCHECK(ipc_client_connected_); | 84 DCHECK(ipc_client_connected_); |
83 bool handled = true; | 85 bool handled = true; |
84 IPC_BEGIN_MESSAGE_MAP(ServiceIPCServer, msg) | 86 IPC_BEGIN_MESSAGE_MAP(ServiceIPCServer, msg) |
85 IPC_MESSAGE_HANDLER(ServiceMsg_GetHistograms, OnGetHistograms) | 87 IPC_MESSAGE_HANDLER(ServiceMsg_GetHistograms, OnGetHistograms) |
86 IPC_MESSAGE_HANDLER(ServiceMsg_Shutdown, OnShutdown); | 88 IPC_MESSAGE_HANDLER(ServiceMsg_Shutdown, OnShutdown); |
87 IPC_MESSAGE_HANDLER(ServiceMsg_UpdateAvailable, OnUpdateAvailable); | 89 IPC_MESSAGE_HANDLER(ServiceMsg_UpdateAvailable, OnUpdateAvailable); |
88 IPC_MESSAGE_UNHANDLED(handled = false) | 90 IPC_MESSAGE_UNHANDLED(handled = false) |
89 IPC_END_MESSAGE_MAP() | 91 IPC_END_MESSAGE_MAP() |
90 | 92 |
91 if (!handled) { | 93 if (!handled) { |
92 // Make a copy of the handlers to prevent modification during iteration. | 94 // Make a copy of the handlers to prevent modification during iteration. |
93 std::vector<MessageHandler*> temp_handlers = message_handlers_.get(); | 95 std::vector<MessageHandler*> temp_handlers(message_handlers_.size()); |
sky
2017/04/07 14:42:14
You've used a for loop for this functionality in o
leonhsl(Using Gerrit)
2017/04/10 08:33:06
Done.
Sorry for this! I was writing such codes bef
| |
96 std::transform( | |
97 message_handlers_.cbegin(), message_handlers_.cend(), | |
98 temp_handlers.begin(), | |
99 [](const std::unique_ptr<MessageHandler>& item) { return item.get(); }); | |
94 for (auto* handler : temp_handlers) { | 100 for (auto* handler : temp_handlers) { |
95 handled = handler->HandleMessage(msg); | 101 handled = handler->HandleMessage(msg); |
96 if (handled) | 102 if (handled) |
97 break; | 103 break; |
98 } | 104 } |
99 } | 105 } |
100 | 106 |
101 return handled; | 107 return handled; |
102 } | 108 } |
103 | 109 |
(...skipping 10 matching lines...) Expand all Loading... | |
114 channel_->Send(new ServiceHostMsg_Histograms(deltas)); | 120 channel_->Send(new ServiceHostMsg_Histograms(deltas)); |
115 } | 121 } |
116 | 122 |
117 void ServiceIPCServer::OnShutdown() { | 123 void ServiceIPCServer::OnShutdown() { |
118 client_->OnShutdown(); | 124 client_->OnShutdown(); |
119 } | 125 } |
120 | 126 |
121 void ServiceIPCServer::OnUpdateAvailable() { | 127 void ServiceIPCServer::OnUpdateAvailable() { |
122 client_->OnUpdateAvailable(); | 128 client_->OnUpdateAvailable(); |
123 } | 129 } |
OLD | NEW |