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 "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/message_loop/message_loop.h" | |
12 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
13 #include "mojo/system/message_pipe_endpoint.h" | 12 #include "mojo/system/message_pipe_endpoint.h" |
14 | 13 |
15 namespace mojo { | 14 namespace mojo { |
16 namespace system { | 15 namespace system { |
17 | 16 |
18 COMPILE_ASSERT(Channel::kBootstrapEndpointId != | 17 COMPILE_ASSERT(Channel::kBootstrapEndpointId != |
19 MessageInTransit::kInvalidEndpointId, | 18 MessageInTransit::kInvalidEndpointId, |
20 kBootstrapEndpointId_is_invalid); | 19 kBootstrapEndpointId_is_invalid); |
21 | 20 |
22 STATIC_CONST_MEMBER_DEFINITION const MessageInTransit::EndpointId | 21 STATIC_CONST_MEMBER_DEFINITION const MessageInTransit::EndpointId |
23 Channel::kBootstrapEndpointId; | 22 Channel::kBootstrapEndpointId; |
24 | 23 |
25 Channel::EndpointInfo::EndpointInfo() { | 24 Channel::EndpointInfo::EndpointInfo() { |
26 } | 25 } |
27 | 26 |
28 Channel::EndpointInfo::EndpointInfo(scoped_refptr<MessagePipe> message_pipe, | 27 Channel::EndpointInfo::EndpointInfo(scoped_refptr<MessagePipe> message_pipe, |
29 unsigned port) | 28 unsigned port) |
30 : message_pipe(message_pipe), | 29 : message_pipe(message_pipe), |
31 port(port) { | 30 port(port) { |
32 } | 31 } |
33 | 32 |
34 Channel::EndpointInfo::~EndpointInfo() { | 33 Channel::EndpointInfo::~EndpointInfo() { |
35 } | 34 } |
36 | 35 |
37 Channel::Channel() | 36 Channel::Channel() |
38 : next_local_id_(kBootstrapEndpointId) { | 37 : next_local_id_(kBootstrapEndpointId) { |
39 } | 38 } |
40 | 39 |
41 bool Channel::Init(embedder::ScopedPlatformHandle handle) { | 40 bool Channel::Init(scoped_ptr<RawChannel> raw_channel) { |
42 DCHECK(creation_thread_checker_.CalledOnValidThread()); | 41 DCHECK(creation_thread_checker_.CalledOnValidThread()); |
| 42 DCHECK(raw_channel); |
43 | 43 |
44 // No need to take |lock_|, since this must be called before this object | 44 // No need to take |lock_|, since this must be called before this object |
45 // becomes thread-safe. | 45 // becomes thread-safe. |
46 DCHECK(!raw_channel_.get()); | 46 DCHECK(!raw_channel_); |
| 47 raw_channel_ = raw_channel.Pass(); |
47 | 48 |
48 CHECK_EQ(base::MessageLoop::current()->type(), base::MessageLoop::TYPE_IO); | 49 if (!raw_channel_->Init(this)) { |
49 raw_channel_.reset(RawChannel::Create(handle.Pass(), this, | |
50 static_cast<base::MessageLoopForIO*>( | |
51 base::MessageLoop::current()))); | |
52 if (!raw_channel_->Init()) { | |
53 raw_channel_.reset(); | 50 raw_channel_.reset(); |
54 return false; | 51 return false; |
55 } | 52 } |
56 | 53 |
57 return true; | 54 return true; |
58 } | 55 } |
59 | 56 |
60 void Channel::Shutdown() { | 57 void Channel::Shutdown() { |
61 DCHECK(creation_thread_checker_.CalledOnValidThread()); | 58 DCHECK(creation_thread_checker_.CalledOnValidThread()); |
62 | 59 |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 LOG(WARNING) << error_message; | 283 LOG(WARNING) << error_message; |
287 } | 284 } |
288 | 285 |
289 void Channel::HandleLocalError(const base::StringPiece& error_message) { | 286 void Channel::HandleLocalError(const base::StringPiece& error_message) { |
290 // TODO(vtl): Is this how we really want to handle this? | 287 // TODO(vtl): Is this how we really want to handle this? |
291 LOG(WARNING) << error_message; | 288 LOG(WARNING) << error_message; |
292 } | 289 } |
293 | 290 |
294 } // namespace system | 291 } // namespace system |
295 } // namespace mojo | 292 } // namespace mojo |
OLD | NEW |