Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(750)

Side by Side Diff: blimp/client/core/blimp_client_context_impl.cc

Issue 2320923002: Add a full Blimp integration test. (Closed)
Patch Set: Addressed more comments, added thread restriction bypass for tests. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 delegate_->AttachBlimpContentsHelpers(blimp_contents.get()); 122 delegate_->AttachBlimpContentsHelpers(blimp_contents.get());
123 return blimp_contents; 123 return blimp_contents;
124 } 124 }
125 125
126 void BlimpClientContextImpl::Connect() { 126 void BlimpClientContextImpl::Connect() {
127 // Start Blimp authentication flow. The OAuth2 token will be used in 127 // Start Blimp authentication flow. The OAuth2 token will be used in
128 // assignment source. 128 // assignment source.
129 GetIdentitySource()->Connect(); 129 GetIdentitySource()->Connect();
130 } 130 }
131 131
132 void BlimpClientContextImpl::ConnectToAssignmentSource( 132 void BlimpClientContextImpl::ConnectWithAssignment(
133 const Assignment& assignment) {
134 io_thread_task_runner_->PostTask(
135 FROM_HERE,
136 base::Bind(&ClientNetworkComponents::ConnectWithAssignment,
137 base::Unretained(net_components_.get()), assignment));
138 }
139
140 void BlimpClientContextImpl::OnAuthTokenReceived(
133 const std::string& client_auth_token) { 141 const std::string& client_auth_token) {
134 if (!assignment_source_) { 142 if (!assignment_source_) {
135 assignment_source_.reset(new AssignmentSource( 143 assignment_source_.reset(new AssignmentSource(
136 GetAssignerURL(), io_thread_task_runner_, file_thread_task_runner_)); 144 GetAssignerURL(), io_thread_task_runner_, file_thread_task_runner_));
137 } 145 }
138 146
139 VLOG(1) << "Trying to get assignment."; 147 VLOG(1) << "Trying to get assignment.";
140 assignment_source_->GetAssignment( 148 assignment_source_->GetAssignment(
141 client_auth_token, 149 client_auth_token,
142 base::Bind(&BlimpClientContextImpl::ConnectWithAssignment, 150 base::Bind(&BlimpClientContextImpl::OnAssignmentReceived,
143 weak_factory_.GetWeakPtr())); 151 weak_factory_.GetWeakPtr()));
144 } 152 }
145 153
146 void BlimpClientContextImpl::OnConnected() {} 154 void BlimpClientContextImpl::OnConnected() {}
147 155
148 void BlimpClientContextImpl::OnDisconnected(int result) {} 156 void BlimpClientContextImpl::OnDisconnected(int result) {}
149 157
150 GURL BlimpClientContextImpl::GetAssignerURL() { 158 GURL BlimpClientContextImpl::GetAssignerURL() {
151 return GURL(kDefaultAssignerUrl); 159 return GURL(kDefaultAssignerUrl);
152 } 160 }
153 161
154 IdentitySource* BlimpClientContextImpl::GetIdentitySource() { 162 IdentitySource* BlimpClientContextImpl::GetIdentitySource() {
155 if (!identity_source_) { 163 if (!identity_source_) {
156 CreateIdentitySource(); 164 CreateIdentitySource();
157 } 165 }
158 return identity_source_.get(); 166 return identity_source_.get();
159 } 167 }
160 168
161 void BlimpClientContextImpl::ConnectWithAssignment( 169 void BlimpClientContextImpl::OnAssignmentReceived(
162 AssignmentRequestResult result, 170 AssignmentRequestResult result,
163 const Assignment& assignment) { 171 const Assignment& assignment) {
164 VLOG(1) << "Assignment result: " << result; 172 VLOG(1) << "Assignment result: " << result;
165 173
166 if (delegate_) { 174 if (delegate_) {
167 delegate_->OnAssignmentConnectionAttempted(result, assignment); 175 delegate_->OnAssignmentConnectionAttempted(result, assignment);
168 } 176 }
169 177
170 if (result != ASSIGNMENT_REQUEST_RESULT_OK) { 178 if (result != ASSIGNMENT_REQUEST_RESULT_OK) {
171 LOG(ERROR) << "Assignment failed, reason: " << result; 179 LOG(ERROR) << "Assignment failed, reason: " << result;
172 return; 180 return;
173 } 181 }
174 182
175 io_thread_task_runner_->PostTask( 183 ConnectWithAssignment(assignment);
176 FROM_HERE,
177 base::Bind(&ClientNetworkComponents::ConnectWithAssignment,
178 base::Unretained(net_components_.get()), assignment));
179 } 184 }
180 185
181 void BlimpClientContextImpl::RegisterFeatures() { 186 void BlimpClientContextImpl::RegisterFeatures() {
182 // Register features' message senders and receivers. 187 // Register features' message senders and receivers.
183 thread_pipe_manager_->RegisterFeature(BlimpMessage::kBlobChannel, 188 thread_pipe_manager_->RegisterFeature(BlimpMessage::kBlobChannel,
184 blob_channel_feature_.get()); 189 blob_channel_feature_.get());
185 geolocation_feature_->set_outgoing_message_processor( 190 geolocation_feature_->set_outgoing_message_processor(
186 thread_pipe_manager_->RegisterFeature(BlimpMessage::kGeolocation, 191 thread_pipe_manager_->RegisterFeature(BlimpMessage::kGeolocation,
187 geolocation_feature_.get())); 192 geolocation_feature_.get()));
188 ime_feature_->set_outgoing_message_processor( 193 ime_feature_->set_outgoing_message_processor(
(...skipping 19 matching lines...) Expand all
208 } 213 }
209 214
210 void BlimpClientContextImpl::InitializeSettings() { 215 void BlimpClientContextImpl::InitializeSettings() {
211 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 216 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
212 switches::kDownloadWholeDocument)) 217 switches::kDownloadWholeDocument))
213 settings_feature_->SetRecordWholeDocument(true); 218 settings_feature_->SetRecordWholeDocument(true);
214 } 219 }
215 220
216 void BlimpClientContextImpl::CreateIdentitySource() { 221 void BlimpClientContextImpl::CreateIdentitySource() {
217 identity_source_ = base::MakeUnique<IdentitySource>( 222 identity_source_ = base::MakeUnique<IdentitySource>(
218 delegate_, base::Bind(&BlimpClientContextImpl::ConnectToAssignmentSource, 223 delegate_, base::Bind(&BlimpClientContextImpl::OnAuthTokenReceived,
219 base::Unretained(this))); 224 base::Unretained(this)));
220 } 225 }
221 226
222 void BlimpClientContextImpl::OnImageDecodeError() { 227 void BlimpClientContextImpl::OnImageDecodeError() {
223 // Currently we just drop the connection on image decoding error. 228 // Currently we just drop the connection on image decoding error.
224 io_thread_task_runner_->PostTask( 229 io_thread_task_runner_->PostTask(
225 FROM_HERE, 230 FROM_HERE,
226 base::Bind( 231 base::Bind(
227 &BrowserConnectionHandler::DropCurrentConnection, 232 &BrowserConnectionHandler::DropCurrentConnection,
228 base::Unretained(net_components_->GetBrowserConnectionHandler()))); 233 base::Unretained(net_components_->GetBrowserConnectionHandler())));
229 } 234 }
230 235
231 } // namespace client 236 } // namespace client
232 } // namespace blimp 237 } // namespace blimp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698