| 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/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 size_t Channel::GetSerializedPlatformHandleSize() const { | 266 size_t Channel::GetSerializedPlatformHandleSize() const { |
| 267 return raw_channel_->GetSerializedPlatformHandleSize(); | 267 return raw_channel_->GetSerializedPlatformHandleSize(); |
| 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_no_lock()); | 272 DCHECK(!is_running_no_lock()); |
| 273 } | 273 } |
| 274 | 274 |
| 275 void Channel::OnReadMessage(const MessageInTransit::View& message_view) { | 275 void Channel::OnReadMessage(const MessageInTransit::View& message_view) { |
| 276 // Note: |ValidateReadMessage()| will call |HandleRemoteError()| if necessary. | |
| 277 if (!ValidateReadMessage(message_view)) | |
| 278 return; | |
| 279 | |
| 280 switch (message_view.type()) { | 276 switch (message_view.type()) { |
| 281 case MessageInTransit::kTypeMessagePipeEndpoint: | 277 case MessageInTransit::kTypeMessagePipeEndpoint: |
| 282 case MessageInTransit::kTypeMessagePipe: | 278 case MessageInTransit::kTypeMessagePipe: |
| 283 OnReadMessageForDownstream(message_view); | 279 OnReadMessageForDownstream(message_view); |
| 284 break; | 280 break; |
| 285 case MessageInTransit::kTypeChannel: | 281 case MessageInTransit::kTypeChannel: |
| 286 OnReadMessageForChannel(message_view); | 282 OnReadMessageForChannel(message_view); |
| 287 break; | 283 break; |
| 288 default: | 284 default: |
| 289 HandleRemoteError(base::StringPrintf( | 285 HandleRemoteError(base::StringPrintf( |
| 290 "Received message of invalid type %u", | 286 "Received message of invalid type %u", |
| 291 static_cast<unsigned>(message_view.type()))); | 287 static_cast<unsigned>(message_view.type()))); |
| 292 break; | 288 break; |
| 293 } | 289 } |
| 294 } | 290 } |
| 295 | 291 |
| 296 void Channel::OnFatalError(FatalError fatal_error) { | 292 void Channel::OnFatalError(FatalError fatal_error) { |
| 297 LOG(ERROR) << "RawChannel fatal error (type " << fatal_error << ")"; | 293 LOG(ERROR) << "RawChannel fatal error (type " << fatal_error << ")"; |
| 298 Shutdown(); | 294 Shutdown(); |
| 299 } | 295 } |
| 300 | 296 |
| 301 bool Channel::ValidateReadMessage(const MessageInTransit::View& message_view) { | |
| 302 const char* error_message = NULL; | |
| 303 if (!message_view.IsValid(&error_message)) { | |
| 304 DCHECK(error_message); | |
| 305 HandleRemoteError(error_message); | |
| 306 return false; | |
| 307 } | |
| 308 | |
| 309 return true; | |
| 310 } | |
| 311 | |
| 312 void Channel::OnReadMessageForDownstream( | 297 void Channel::OnReadMessageForDownstream( |
| 313 const MessageInTransit::View& message_view) { | 298 const MessageInTransit::View& message_view) { |
| 314 DCHECK(message_view.type() == MessageInTransit::kTypeMessagePipeEndpoint || | 299 DCHECK(message_view.type() == MessageInTransit::kTypeMessagePipeEndpoint || |
| 315 message_view.type() == MessageInTransit::kTypeMessagePipe); | 300 message_view.type() == MessageInTransit::kTypeMessagePipe); |
| 316 | 301 |
| 317 MessageInTransit::EndpointId local_id = message_view.destination_id(); | 302 MessageInTransit::EndpointId local_id = message_view.destination_id(); |
| 318 if (local_id == MessageInTransit::kInvalidEndpointId) { | 303 if (local_id == MessageInTransit::kInvalidEndpointId) { |
| 319 HandleRemoteError("Received message with no destination ID"); | 304 HandleRemoteError("Received message with no destination ID"); |
| 320 return; | 305 return; |
| 321 } | 306 } |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 486 // TODO(vtl): Is this how we really want to handle this? | 471 // TODO(vtl): Is this how we really want to handle this? |
| 487 // Sometimes we'll want to propagate the error back to the message pipe | 472 // Sometimes we'll want to propagate the error back to the message pipe |
| 488 // (endpoint), and notify it that the remote is (effectively) closed. | 473 // (endpoint), and notify it that the remote is (effectively) closed. |
| 489 // Sometimes we'll want to kill the channel (and notify all the endpoints that | 474 // Sometimes we'll want to kill the channel (and notify all the endpoints that |
| 490 // their remotes are dead. | 475 // their remotes are dead. |
| 491 LOG(WARNING) << error_message; | 476 LOG(WARNING) << error_message; |
| 492 } | 477 } |
| 493 | 478 |
| 494 } // namespace system | 479 } // namespace system |
| 495 } // namespace mojo | 480 } // namespace mojo |
| OLD | NEW |