OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "mojo/system/channel.h" | 5 #include "mojo/system/channel.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 } | 268 } |
269 | 269 |
270 Channel::~Channel() { | 270 Channel::~Channel() { |
271 // The channel should have been shut down first. | 271 // The channel should have been shut down first. |
272 DCHECK(!is_running_); | 272 DCHECK(!is_running_); |
273 } | 273 } |
274 | 274 |
275 void Channel::OnReadMessage( | 275 void Channel::OnReadMessage( |
276 const MessageInTransit::View& message_view, | 276 const MessageInTransit::View& message_view, |
277 embedder::ScopedPlatformHandleVectorPtr platform_handles) { | 277 embedder::ScopedPlatformHandleVectorPtr platform_handles) { |
| 278 DCHECK(creation_thread_checker_.CalledOnValidThread()); |
| 279 |
278 switch (message_view.type()) { | 280 switch (message_view.type()) { |
279 case MessageInTransit::kTypeMessagePipeEndpoint: | 281 case MessageInTransit::kTypeMessagePipeEndpoint: |
280 case MessageInTransit::kTypeMessagePipe: | 282 case MessageInTransit::kTypeMessagePipe: |
281 OnReadMessageForDownstream(message_view, platform_handles.Pass()); | 283 OnReadMessageForDownstream(message_view, platform_handles.Pass()); |
282 break; | 284 break; |
283 case MessageInTransit::kTypeChannel: | 285 case MessageInTransit::kTypeChannel: |
284 OnReadMessageForChannel(message_view, platform_handles.Pass()); | 286 OnReadMessageForChannel(message_view, platform_handles.Pass()); |
285 break; | 287 break; |
286 default: | 288 default: |
287 HandleRemoteError( | 289 HandleRemoteError( |
288 base::StringPrintf("Received message of invalid type %u", | 290 base::StringPrintf("Received message of invalid type %u", |
289 static_cast<unsigned>(message_view.type()))); | 291 static_cast<unsigned>(message_view.type()))); |
290 break; | 292 break; |
291 } | 293 } |
292 } | 294 } |
293 | 295 |
294 void Channel::OnError(Error error) { | 296 void Channel::OnError(Error error) { |
| 297 DCHECK(creation_thread_checker_.CalledOnValidThread()); |
| 298 |
295 switch (error) { | 299 switch (error) { |
296 case ERROR_READ_SHUTDOWN: | 300 case ERROR_READ_SHUTDOWN: |
297 // The other side was cleanly closed, so this isn't actually an error. | 301 // The other side was cleanly closed, so this isn't actually an error. |
298 DVLOG(1) << "RawChannel read error (shutdown)"; | 302 DVLOG(1) << "RawChannel read error (shutdown)"; |
299 break; | 303 break; |
300 case ERROR_READ_BROKEN: { | 304 case ERROR_READ_BROKEN: { |
301 base::AutoLock locker(lock_); | 305 base::AutoLock locker(lock_); |
302 LOG_IF(ERROR, !is_shutting_down_) | 306 LOG_IF(ERROR, !is_shutting_down_) |
303 << "RawChannel read error (connection broken)"; | 307 << "RawChannel read error (connection broken)"; |
304 break; | 308 break; |
(...skipping 11 matching lines...) Expand all Loading... |
316 // normal operation (but maybe the other side crashed). | 320 // normal operation (but maybe the other side crashed). |
317 LOG(WARNING) << "RawChannel write error"; | 321 LOG(WARNING) << "RawChannel write error"; |
318 break; | 322 break; |
319 } | 323 } |
320 Shutdown(); | 324 Shutdown(); |
321 } | 325 } |
322 | 326 |
323 void Channel::OnReadMessageForDownstream( | 327 void Channel::OnReadMessageForDownstream( |
324 const MessageInTransit::View& message_view, | 328 const MessageInTransit::View& message_view, |
325 embedder::ScopedPlatformHandleVectorPtr platform_handles) { | 329 embedder::ScopedPlatformHandleVectorPtr platform_handles) { |
| 330 DCHECK(creation_thread_checker_.CalledOnValidThread()); |
326 DCHECK(message_view.type() == MessageInTransit::kTypeMessagePipeEndpoint || | 331 DCHECK(message_view.type() == MessageInTransit::kTypeMessagePipeEndpoint || |
327 message_view.type() == MessageInTransit::kTypeMessagePipe); | 332 message_view.type() == MessageInTransit::kTypeMessagePipe); |
328 | 333 |
329 MessageInTransit::EndpointId local_id = message_view.destination_id(); | 334 MessageInTransit::EndpointId local_id = message_view.destination_id(); |
330 if (local_id == MessageInTransit::kInvalidEndpointId) { | 335 if (local_id == MessageInTransit::kInvalidEndpointId) { |
331 HandleRemoteError("Received message with no destination ID"); | 336 HandleRemoteError("Received message with no destination ID"); |
332 return; | 337 return; |
333 } | 338 } |
334 | 339 |
335 ChannelEndpoint::State state = ChannelEndpoint::STATE_NORMAL; | 340 ChannelEndpoint::State state = ChannelEndpoint::STATE_NORMAL; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
395 "Failed to enqueue message to local ID %u (result %d)", | 400 "Failed to enqueue message to local ID %u (result %d)", |
396 static_cast<unsigned>(local_id), | 401 static_cast<unsigned>(local_id), |
397 static_cast<int>(result))); | 402 static_cast<int>(result))); |
398 return; | 403 return; |
399 } | 404 } |
400 } | 405 } |
401 | 406 |
402 void Channel::OnReadMessageForChannel( | 407 void Channel::OnReadMessageForChannel( |
403 const MessageInTransit::View& message_view, | 408 const MessageInTransit::View& message_view, |
404 embedder::ScopedPlatformHandleVectorPtr platform_handles) { | 409 embedder::ScopedPlatformHandleVectorPtr platform_handles) { |
| 410 DCHECK(creation_thread_checker_.CalledOnValidThread()); |
405 DCHECK_EQ(message_view.type(), MessageInTransit::kTypeChannel); | 411 DCHECK_EQ(message_view.type(), MessageInTransit::kTypeChannel); |
406 | 412 |
407 // Currently, no channel messages take platform handles. | 413 // Currently, no channel messages take platform handles. |
408 if (platform_handles) { | 414 if (platform_handles) { |
409 HandleRemoteError( | 415 HandleRemoteError( |
410 "Received invalid channel message (has platform handles)"); | 416 "Received invalid channel message (has platform handles)"); |
411 NOTREACHED(); | 417 NOTREACHED(); |
412 return; | 418 return; |
413 } | 419 } |
414 | 420 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
446 default: | 452 default: |
447 HandleRemoteError("Received invalid channel message"); | 453 HandleRemoteError("Received invalid channel message"); |
448 NOTREACHED(); | 454 NOTREACHED(); |
449 break; | 455 break; |
450 } | 456 } |
451 } | 457 } |
452 | 458 |
453 bool Channel::RemoveMessagePipeEndpoint( | 459 bool Channel::RemoveMessagePipeEndpoint( |
454 MessageInTransit::EndpointId local_id, | 460 MessageInTransit::EndpointId local_id, |
455 MessageInTransit::EndpointId remote_id) { | 461 MessageInTransit::EndpointId remote_id) { |
| 462 DCHECK(creation_thread_checker_.CalledOnValidThread()); |
| 463 |
456 scoped_refptr<MessagePipe> message_pipe; | 464 scoped_refptr<MessagePipe> message_pipe; |
457 unsigned port; | 465 unsigned port; |
458 { | 466 { |
459 base::AutoLock locker(lock_); | 467 base::AutoLock locker(lock_); |
460 | 468 |
461 IdToEndpointMap::iterator it = local_id_to_endpoint_map_.find(local_id); | 469 IdToEndpointMap::iterator it = local_id_to_endpoint_map_.find(local_id); |
462 if (it == local_id_to_endpoint_map_.end()) { | 470 if (it == local_id_to_endpoint_map_.end()) { |
463 DVLOG(2) << "Remove message pipe error: not found"; | 471 DVLOG(2) << "Remove message pipe error: not found"; |
464 return false; | 472 return false; |
465 } | 473 } |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
519 // TODO(vtl): Is this how we really want to handle this? | 527 // TODO(vtl): Is this how we really want to handle this? |
520 // Sometimes we'll want to propagate the error back to the message pipe | 528 // Sometimes we'll want to propagate the error back to the message pipe |
521 // (endpoint), and notify it that the remote is (effectively) closed. | 529 // (endpoint), and notify it that the remote is (effectively) closed. |
522 // Sometimes we'll want to kill the channel (and notify all the endpoints that | 530 // Sometimes we'll want to kill the channel (and notify all the endpoints that |
523 // their remotes are dead. | 531 // their remotes are dead. |
524 LOG(WARNING) << error_message; | 532 LOG(WARNING) << error_message; |
525 } | 533 } |
526 | 534 |
527 } // namespace system | 535 } // namespace system |
528 } // namespace mojo | 536 } // namespace mojo |
OLD | NEW |