OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "blimp/client/core/blimp_client_context_impl.h" | 5 #include "blimp/client/core/blimp_client_context_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/threading/sequenced_task_runner_handle.h" | 10 #include "base/threading/sequenced_task_runner_handle.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
42 #endif // defined(OS_ANDROID) | 42 #endif // defined(OS_ANDROID) |
43 } | 43 } |
44 | 44 |
45 BlimpClientContextImpl::BlimpClientContextImpl( | 45 BlimpClientContextImpl::BlimpClientContextImpl( |
46 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner, | 46 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner, |
47 scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner) | 47 scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner) |
48 : BlimpClientContext(), | 48 : BlimpClientContext(), |
49 io_thread_task_runner_(io_thread_task_runner), | 49 io_thread_task_runner_(io_thread_task_runner), |
50 file_thread_task_runner_(file_thread_task_runner), | 50 file_thread_task_runner_(file_thread_task_runner), |
51 blimp_contents_manager_(new BlimpContentsManager), | 51 blimp_contents_manager_(new BlimpContentsManager), |
52 tab_control_feature_(new TabControlFeature), | |
52 weak_factory_(this) { | 53 weak_factory_(this) { |
53 net_components_.reset(new ClientNetworkComponents( | 54 net_components_.reset(new ClientNetworkComponents( |
54 base::MakeUnique<CrossThreadNetworkEventObserver>( | 55 base::MakeUnique<CrossThreadNetworkEventObserver>( |
55 weak_factory_.GetWeakPtr(), base::SequencedTaskRunnerHandle::Get()))); | 56 weak_factory_.GetWeakPtr(), base::SequencedTaskRunnerHandle::Get()))); |
56 | 57 |
57 // The |thread_pipe_manager_| must be set up correctly before features are | 58 // The |thread_pipe_manager_| must be set up correctly before features are |
58 // registered. | 59 // registered. |
59 thread_pipe_manager_ = base::MakeUnique<ThreadPipeManager>( | 60 thread_pipe_manager_ = base::MakeUnique<ThreadPipeManager>( |
60 io_thread_task_runner_, net_components_->GetBrowserConnectionHandler()); | 61 io_thread_task_runner_, net_components_->GetBrowserConnectionHandler()); |
61 | 62 |
63 RegisterFeatures(); | |
64 | |
62 // Initialize must only be posted after the calls features have been | 65 // Initialize must only be posted after the calls features have been |
63 // registered. | 66 // registered. |
64 io_thread_task_runner_->PostTask( | 67 io_thread_task_runner_->PostTask( |
65 FROM_HERE, base::Bind(&ClientNetworkComponents::Initialize, | 68 FROM_HERE, base::Bind(&ClientNetworkComponents::Initialize, |
66 base::Unretained(net_components_.get()))); | 69 base::Unretained(net_components_.get()))); |
67 } | 70 } |
68 | 71 |
69 BlimpClientContextImpl::~BlimpClientContextImpl() { | 72 BlimpClientContextImpl::~BlimpClientContextImpl() { |
70 io_thread_task_runner_->DeleteSoon(FROM_HERE, net_components_.release()); | 73 io_thread_task_runner_->DeleteSoon(FROM_HERE, net_components_.release()); |
71 } | 74 } |
72 | 75 |
73 void BlimpClientContextImpl::SetDelegate(BlimpClientContextDelegate* delegate) { | 76 void BlimpClientContextImpl::SetDelegate(BlimpClientContextDelegate* delegate) { |
74 delegate_ = delegate; | 77 delegate_ = delegate; |
75 } | 78 } |
76 | 79 |
77 std::unique_ptr<BlimpContents> BlimpClientContextImpl::CreateBlimpContents() { | 80 std::unique_ptr<BlimpContents> BlimpClientContextImpl::CreateBlimpContents() { |
78 std::unique_ptr<BlimpContents> blimp_contents = | 81 std::unique_ptr<BlimpContents> blimp_contents = |
79 blimp_contents_manager_->CreateBlimpContents(); | 82 blimp_contents_manager_->CreateBlimpContents(); |
80 delegate_->AttachBlimpContentsHelpers(blimp_contents.get()); | 83 delegate_->AttachBlimpContentsHelpers(blimp_contents.get()); |
84 | |
85 BlimpContentsImpl* blimp_contents_impl = | |
86 static_cast<BlimpContentsImpl*>(blimp_contents.get()); | |
87 blimp_contents_impl->SetTabControlFeature(tab_control_feature_.get()); | |
nyquist
2016/08/16 20:41:04
Did you consider doing this in the constructor ins
Menglin
2016/08/16 21:10:09
Do you mean BlimpContentsImpl::BlimpContentsImpl(i
nyquist
2016/08/16 21:41:40
Yes, that's what I meant. I don't feel strongly ab
Menglin
2016/08/17 19:48:46
Done.
| |
88 | |
81 return blimp_contents; | 89 return blimp_contents; |
82 } | 90 } |
83 | 91 |
84 void BlimpClientContextImpl::Connect(const std::string& client_auth_token) { | 92 void BlimpClientContextImpl::Connect(const std::string& client_auth_token) { |
85 if (!assignment_source_) { | 93 if (!assignment_source_) { |
86 assignment_source_.reset(new AssignmentSource( | 94 assignment_source_.reset(new AssignmentSource( |
87 GetAssignerURL(), io_thread_task_runner_, file_thread_task_runner_)); | 95 GetAssignerURL(), io_thread_task_runner_, file_thread_task_runner_)); |
88 } | 96 } |
89 | 97 |
90 VLOG(1) << "Trying to get assignment."; | 98 VLOG(1) << "Trying to get assignment."; |
91 assignment_source_->GetAssignment( | 99 assignment_source_->GetAssignment( |
92 client_auth_token, | 100 client_auth_token, |
93 base::Bind(&BlimpClientContextImpl::ConnectWithAssignment, | 101 base::Bind(&BlimpClientContextImpl::ConnectWithAssignment, |
94 weak_factory_.GetWeakPtr())); | 102 weak_factory_.GetWeakPtr())); |
95 } | 103 } |
96 | 104 |
97 void BlimpClientContextImpl::OnConnected() {} | 105 void BlimpClientContextImpl::OnConnected() {} |
98 | 106 |
99 void BlimpClientContextImpl::OnDisconnected(int result) {} | 107 void BlimpClientContextImpl::OnDisconnected(int result) {} |
100 | 108 |
109 TabControlFeature* BlimpClientContextImpl::GetTabControlFeature() const { | |
110 return tab_control_feature_.get(); | |
111 } | |
112 | |
101 GURL BlimpClientContextImpl::GetAssignerURL() { | 113 GURL BlimpClientContextImpl::GetAssignerURL() { |
102 return GURL(kDefaultAssignerUrl); | 114 return GURL(kDefaultAssignerUrl); |
103 } | 115 } |
104 | 116 |
105 void BlimpClientContextImpl::ConnectWithAssignment( | 117 void BlimpClientContextImpl::ConnectWithAssignment( |
106 AssignmentRequestResult result, | 118 AssignmentRequestResult result, |
107 const Assignment& assignment) { | 119 const Assignment& assignment) { |
108 VLOG(1) << "Assignment result: " << result; | 120 VLOG(1) << "Assignment result: " << result; |
109 | 121 |
110 if (delegate_) { | 122 if (delegate_) { |
111 delegate_->OnAssignmentConnectionAttempted(result, assignment); | 123 delegate_->OnAssignmentConnectionAttempted(result, assignment); |
112 } | 124 } |
113 | 125 |
114 if (result != ASSIGNMENT_REQUEST_RESULT_OK) { | 126 if (result != ASSIGNMENT_REQUEST_RESULT_OK) { |
115 LOG(ERROR) << "Assignment failed, reason: " << result; | 127 LOG(ERROR) << "Assignment failed, reason: " << result; |
116 return; | 128 return; |
117 } | 129 } |
118 | 130 |
119 io_thread_task_runner_->PostTask( | 131 io_thread_task_runner_->PostTask( |
120 FROM_HERE, | 132 FROM_HERE, |
121 base::Bind(&ClientNetworkComponents::ConnectWithAssignment, | 133 base::Bind(&ClientNetworkComponents::ConnectWithAssignment, |
122 base::Unretained(net_components_.get()), assignment)); | 134 base::Unretained(net_components_.get()), assignment)); |
123 } | 135 } |
124 | 136 |
137 void BlimpClientContextImpl::RegisterFeatures() { | |
138 // Register features' message senders and receivers. | |
139 tab_control_feature_->set_outgoing_message_processor( | |
140 thread_pipe_manager_->RegisterFeature(BlimpMessage::kTabControl, | |
141 tab_control_feature_.get())); | |
142 } | |
143 | |
125 } // namespace client | 144 } // namespace client |
126 } // namespace blimp | 145 } // namespace blimp |
OLD | NEW |