Chromium Code Reviews| 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/context/blimp_client_context_impl.h" | 5 #include "blimp/client/core/context/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 22 matching lines...) Expand all Loading... | |
| 33 | 33 |
| 34 #if defined(OS_ANDROID) | 34 #if defined(OS_ANDROID) |
| 35 #include "blimp/client/core/context/android/blimp_client_context_impl_android.h" | 35 #include "blimp/client/core/context/android/blimp_client_context_impl_android.h" |
| 36 #endif // OS_ANDROID | 36 #endif // OS_ANDROID |
| 37 | 37 |
| 38 namespace blimp { | 38 namespace blimp { |
| 39 namespace client { | 39 namespace client { |
| 40 | 40 |
| 41 namespace { | 41 namespace { |
| 42 | 42 |
| 43 const char kDefaultAssignerUrl[] = | |
| 44 "https://blimp-pa.googleapis.com/v1/assignment"; | |
| 45 | |
| 46 void DropConnectionOnIOThread(ClientNetworkComponents* net_components) { | 43 void DropConnectionOnIOThread(ClientNetworkComponents* net_components) { |
| 47 net_components->GetBrowserConnectionHandler()->DropCurrentConnection(); | 44 net_components->GetBrowserConnectionHandler()->DropCurrentConnection(); |
| 48 } | 45 } |
| 49 | 46 |
| 50 } // namespace | 47 } // namespace |
| 51 | 48 |
| 52 // This function is declared in //blimp/client/public/blimp_client_context.h, | 49 // This function is declared in //blimp/client/public/blimp_client_context.h, |
| 53 // and either this function or the one in | 50 // and either this function or the one in |
| 54 // //blimp/client/core/dummy_blimp_client_context.cc should be linked in to | 51 // //blimp/client/core/dummy_blimp_client_context.cc should be linked in to |
| 55 // any binary using BlimpClientContext::Create. | 52 // any binary using BlimpClientContext::Create. |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 98 net_components_.reset(new ClientNetworkComponents( | 95 net_components_.reset(new ClientNetworkComponents( |
| 99 base::MakeUnique<CrossThreadNetworkEventObserver>( | 96 base::MakeUnique<CrossThreadNetworkEventObserver>( |
| 100 connection_status_.GetWeakPtr(), | 97 connection_status_.GetWeakPtr(), |
| 101 base::SequencedTaskRunnerHandle::Get()))); | 98 base::SequencedTaskRunnerHandle::Get()))); |
| 102 | 99 |
| 103 // The |thread_pipe_manager_| must be set up correctly before features are | 100 // The |thread_pipe_manager_| must be set up correctly before features are |
| 104 // registered. | 101 // registered. |
| 105 thread_pipe_manager_ = base::MakeUnique<ThreadPipeManager>( | 102 thread_pipe_manager_ = base::MakeUnique<ThreadPipeManager>( |
| 106 io_thread_task_runner_, net_components_->GetBrowserConnectionHandler()); | 103 io_thread_task_runner_, net_components_->GetBrowserConnectionHandler()); |
| 107 | 104 |
| 105 assignment_fetcher_ = base::MakeUnique<AssignmentFetcher>( | |
| 106 base::Bind(&BlimpClientContextImpl::OnAssignmentReceived, | |
| 107 weak_factory_.GetWeakPtr()), | |
| 108 io_thread_task_runner_, file_thread_task_runner_); | |
| 109 | |
| 108 RegisterFeatures(); | 110 RegisterFeatures(); |
| 109 InitializeSettings(); | 111 InitializeSettings(); |
| 110 | 112 |
| 111 // Initialize must only be posted after the features have been | 113 // Initialize must only be posted after the features have been |
| 112 // registered. | 114 // registered. |
| 113 io_thread_task_runner_->PostTask( | 115 io_thread_task_runner_->PostTask( |
| 114 FROM_HERE, base::Bind(&ClientNetworkComponents::Initialize, | 116 FROM_HERE, base::Bind(&ClientNetworkComponents::Initialize, |
| 115 base::Unretained(net_components_.get()))); | 117 base::Unretained(net_components_.get()))); |
| 116 | 118 |
| 117 UMA_HISTOGRAM_BOOLEAN("Blimp.Supported", true); | 119 UMA_HISTOGRAM_BOOLEAN("Blimp.Supported", true); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 128 std::unique_ptr<BlimpContents> BlimpClientContextImpl::CreateBlimpContents( | 130 std::unique_ptr<BlimpContents> BlimpClientContextImpl::CreateBlimpContents( |
| 129 gfx::NativeWindow window) { | 131 gfx::NativeWindow window) { |
| 130 std::unique_ptr<BlimpContents> blimp_contents = | 132 std::unique_ptr<BlimpContents> blimp_contents = |
| 131 blimp_contents_manager_->CreateBlimpContents(window); | 133 blimp_contents_manager_->CreateBlimpContents(window); |
| 132 if (blimp_contents) | 134 if (blimp_contents) |
| 133 delegate_->AttachBlimpContentsHelpers(blimp_contents.get()); | 135 delegate_->AttachBlimpContentsHelpers(blimp_contents.get()); |
| 134 return blimp_contents; | 136 return blimp_contents; |
| 135 } | 137 } |
| 136 | 138 |
| 137 void BlimpClientContextImpl::Connect() { | 139 void BlimpClientContextImpl::Connect() { |
| 138 // Start Blimp authentication flow. The OAuth2 token will be used in | 140 assignment_fetcher_->Fetch(delegate_); |
| 139 // assignment source. | |
| 140 GetIdentitySource()->Connect(); | |
| 141 } | 141 } |
| 142 | 142 |
| 143 void BlimpClientContextImpl::ConnectWithAssignment( | 143 void BlimpClientContextImpl::ConnectWithAssignment( |
| 144 const Assignment& assignment) { | 144 const Assignment& assignment) { |
| 145 io_thread_task_runner_->PostTask( | 145 io_thread_task_runner_->PostTask( |
| 146 FROM_HERE, | 146 FROM_HERE, |
| 147 base::Bind(&ClientNetworkComponents::ConnectWithAssignment, | 147 base::Bind(&ClientNetworkComponents::ConnectWithAssignment, |
| 148 base::Unretained(net_components_.get()), assignment)); | 148 base::Unretained(net_components_.get()), assignment)); |
| 149 } | 149 } |
| 150 | 150 |
| 151 std::unordered_map<std::string, std::string> | 151 std::unordered_map<std::string, std::string> |
| 152 BlimpClientContextImpl::CreateFeedbackData() { | 152 BlimpClientContextImpl::CreateFeedbackData() { |
| 153 return CreateBlimpFeedbackData(blimp_contents_manager_.get()); | 153 return CreateBlimpFeedbackData(blimp_contents_manager_.get()); |
| 154 } | 154 } |
| 155 | 155 |
| 156 void BlimpClientContextImpl::OnAuthTokenReceived( | |
| 157 const std::string& client_auth_token) { | |
| 158 if (!assignment_source_) { | |
| 159 assignment_source_.reset(new AssignmentSource( | |
| 160 GetAssignerURL(), io_thread_task_runner_, file_thread_task_runner_)); | |
| 161 } | |
| 162 | |
| 163 VLOG(1) << "Trying to get assignment."; | |
| 164 assignment_source_->GetAssignment( | |
| 165 client_auth_token, | |
| 166 base::Bind(&BlimpClientContextImpl::OnAssignmentReceived, | |
| 167 weak_factory_.GetWeakPtr())); | |
| 168 } | |
| 169 | |
| 170 GURL BlimpClientContextImpl::GetAssignerURL() { | |
| 171 return GURL(kDefaultAssignerUrl); | |
| 172 } | |
| 173 | |
| 174 IdentitySource* BlimpClientContextImpl::GetIdentitySource() { | 156 IdentitySource* BlimpClientContextImpl::GetIdentitySource() { |
| 175 if (!identity_source_) { | 157 return assignment_fetcher_->GetIdentitySource(); |
|
David Trainor- moved to gerrit
2016/10/13 03:52:29
I wonder if we can pass the IdentityProvider direc
CJ
2016/10/13 21:19:16
Yeah I'm pretty out of the loop when it comes to s
David Trainor- moved to gerrit
2016/10/20 16:50:32
Don't worry about this for now, I/we can look into
CJ
2016/10/20 20:52:57
Acknowledged.
| |
| 176 CreateIdentitySource(); | |
| 177 } | |
| 178 return identity_source_.get(); | |
| 179 } | 158 } |
| 180 | 159 |
| 181 ConnectionStatus* BlimpClientContextImpl::GetConnectionStatus() { | 160 ConnectionStatus* BlimpClientContextImpl::GetConnectionStatus() { |
| 182 return &connection_status_; | 161 return &connection_status_; |
| 183 } | 162 } |
| 184 | 163 |
| 185 void BlimpClientContextImpl::OnAssignmentReceived( | 164 void BlimpClientContextImpl::OnAssignmentReceived( |
| 186 AssignmentRequestResult result, | 165 AssignmentRequestResult result, |
| 187 const Assignment& assignment) { | 166 const Assignment& assignment) { |
| 188 VLOG(1) << "Assignment result: " << result; | 167 VLOG(1) << "Assignment result: " << result; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 236 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 215 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 237 switches::kDownloadWholeDocument)) | 216 switches::kDownloadWholeDocument)) |
| 238 settings_feature_->SetRecordWholeDocument(true); | 217 settings_feature_->SetRecordWholeDocument(true); |
| 239 } | 218 } |
| 240 | 219 |
| 241 void BlimpClientContextImpl::DropConnection() { | 220 void BlimpClientContextImpl::DropConnection() { |
| 242 io_thread_task_runner_->PostTask( | 221 io_thread_task_runner_->PostTask( |
| 243 FROM_HERE, base::Bind(&DropConnectionOnIOThread, net_components_.get())); | 222 FROM_HERE, base::Bind(&DropConnectionOnIOThread, net_components_.get())); |
| 244 } | 223 } |
| 245 | 224 |
| 246 void BlimpClientContextImpl::CreateIdentitySource() { | |
| 247 identity_source_ = base::MakeUnique<IdentitySource>( | |
| 248 delegate_, base::Bind(&BlimpClientContextImpl::OnAuthTokenReceived, | |
| 249 base::Unretained(this))); | |
| 250 } | |
| 251 | |
| 252 void BlimpClientContextImpl::OnImageDecodeError() { | 225 void BlimpClientContextImpl::OnImageDecodeError() { |
| 253 // Currently we just drop the connection on image decoding error. | 226 // Currently we just drop the connection on image decoding error. |
| 254 DropConnection(); | 227 DropConnection(); |
| 255 } | 228 } |
| 256 | 229 |
| 257 } // namespace client | 230 } // namespace client |
| 258 } // namespace blimp | 231 } // namespace blimp |
| OLD | NEW |