| 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" |
| 11 #include "blimp/client/core/contents/blimp_contents_impl.h" | 11 #include "blimp/client/core/contents/blimp_contents_impl.h" |
| 12 #include "blimp/client/core/contents/blimp_contents_manager.h" | 12 #include "blimp/client/core/contents/blimp_contents_manager.h" |
| 13 #include "blimp/client/core/session/cross_thread_network_event_observer.h" | 13 #include "blimp/client/core/session/cross_thread_network_event_observer.h" |
| 14 #include "blimp/client/public/blimp_client_context_delegate.h" | 14 #include "blimp/client/public/blimp_client_context_delegate.h" |
| 15 | 15 |
| 16 #if defined(OS_ANDROID) | 16 #if defined(OS_ANDROID) |
| 17 #include "blimp/client/core/android/blimp_client_context_impl_android.h" | 17 #include "blimp/client/core/android/blimp_client_context_impl_android.h" |
| 18 #endif // OS_ANDROID | 18 #endif // OS_ANDROID |
| 19 | 19 |
| 20 namespace blimp { | 20 namespace blimp { |
| 21 namespace client { | 21 namespace client { |
| 22 | 22 |
| 23 namespace { |
| 24 const char kDefaultAssignerUrl[] = |
| 25 "https://blimp-pa.googleapis.com/v1/assignment"; |
| 26 } // namespace |
| 27 |
| 23 // This function is declared in //blimp/client/public/blimp_client_context.h, | 28 // This function is declared in //blimp/client/public/blimp_client_context.h, |
| 24 // and either this function or the one in | 29 // and either this function or the one in |
| 25 // //blimp/client/core/dummy_blimp_client_context.cc should be linked in to | 30 // //blimp/client/core/dummy_blimp_client_context.cc should be linked in to |
| 26 // any binary using BlimpClientContext::Create. | 31 // any binary using BlimpClientContext::Create. |
| 27 // static | 32 // static |
| 28 BlimpClientContext* BlimpClientContext::Create( | 33 BlimpClientContext* BlimpClientContext::Create( |
| 29 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner) { | 34 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner, |
| 35 scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner) { |
| 30 #if defined(OS_ANDROID) | 36 #if defined(OS_ANDROID) |
| 31 return new BlimpClientContextImplAndroid(io_thread_task_runner); | 37 return new BlimpClientContextImplAndroid(io_thread_task_runner, |
| 38 file_thread_task_runner); |
| 32 #else | 39 #else |
| 33 return new BlimpClientContextImpl(io_thread_task_runner); | 40 return new BlimpClientContextImpl(io_thread_task_runner, |
| 41 file_thread_task_runner); |
| 34 #endif // defined(OS_ANDROID) | 42 #endif // defined(OS_ANDROID) |
| 35 } | 43 } |
| 36 | 44 |
| 37 BlimpClientContextImpl::BlimpClientContextImpl( | 45 BlimpClientContextImpl::BlimpClientContextImpl( |
| 38 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) |
| 39 : BlimpClientContext(), | 48 : BlimpClientContext(), |
| 40 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), |
| 41 blimp_contents_manager_(new BlimpContentsManager), | 51 blimp_contents_manager_(new BlimpContentsManager), |
| 42 weak_factory_(this) { | 52 weak_factory_(this) { |
| 43 blimp_connection_statistics_ = new BlimpConnectionStatistics(); | 53 blimp_connection_statistics_ = new BlimpConnectionStatistics(); |
| 44 net_components_.reset(new ClientNetworkComponents( | 54 net_components_.reset(new ClientNetworkComponents( |
| 45 base::MakeUnique<CrossThreadNetworkEventObserver>( | 55 base::MakeUnique<CrossThreadNetworkEventObserver>( |
| 46 weak_factory_.GetWeakPtr(), base::SequencedTaskRunnerHandle::Get()), | 56 weak_factory_.GetWeakPtr(), base::SequencedTaskRunnerHandle::Get()), |
| 47 base::WrapUnique(blimp_connection_statistics_))); | 57 base::WrapUnique(blimp_connection_statistics_))); |
| 48 | 58 |
| 49 // The |thread_pipe_manager_| must be set up correctly before features are | 59 // The |thread_pipe_manager_| must be set up correctly before features are |
| 50 // registered. | 60 // registered. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 66 delegate_ = delegate; | 76 delegate_ = delegate; |
| 67 } | 77 } |
| 68 | 78 |
| 69 std::unique_ptr<BlimpContents> BlimpClientContextImpl::CreateBlimpContents() { | 79 std::unique_ptr<BlimpContents> BlimpClientContextImpl::CreateBlimpContents() { |
| 70 std::unique_ptr<BlimpContents> blimp_contents = | 80 std::unique_ptr<BlimpContents> blimp_contents = |
| 71 blimp_contents_manager_->CreateBlimpContents(); | 81 blimp_contents_manager_->CreateBlimpContents(); |
| 72 delegate_->AttachBlimpContentsHelpers(blimp_contents.get()); | 82 delegate_->AttachBlimpContentsHelpers(blimp_contents.get()); |
| 73 return blimp_contents; | 83 return blimp_contents; |
| 74 } | 84 } |
| 75 | 85 |
| 86 void BlimpClientContextImpl::Connect(const std::string& client_auth_token) { |
| 87 if (!assignment_source_) { |
| 88 assignment_source_.reset(new AssignmentSource( |
| 89 GetAssignerURL(), io_thread_task_runner_, file_thread_task_runner_)); |
| 90 } |
| 91 |
| 92 VLOG(1) << "Trying to get assignment."; |
| 93 assignment_source_->GetAssignment( |
| 94 client_auth_token, |
| 95 base::Bind(&BlimpClientContextImpl::ConnectWithAssignment, |
| 96 weak_factory_.GetWeakPtr())); |
| 97 } |
| 98 |
| 76 void BlimpClientContextImpl::OnConnected() {} | 99 void BlimpClientContextImpl::OnConnected() {} |
| 77 | 100 |
| 78 void BlimpClientContextImpl::OnDisconnected(int result) {} | 101 void BlimpClientContextImpl::OnDisconnected(int result) {} |
| 79 | 102 |
| 103 GURL BlimpClientContextImpl::GetAssignerURL() { |
| 104 return GURL(kDefaultAssignerUrl); |
| 105 } |
| 106 |
| 107 void BlimpClientContextImpl::ConnectWithAssignment( |
| 108 AssignmentRequestResult result, |
| 109 const Assignment& assignment) { |
| 110 VLOG(1) << "Assignment result: " << result; |
| 111 |
| 112 if (delegate_) { |
| 113 delegate_->OnAssignmentConnectionAttempted(result, assignment); |
| 114 } |
| 115 |
| 116 if (result != ASSIGNMENT_REQUEST_RESULT_OK) { |
| 117 LOG(ERROR) << "Assignment failed, reason: " << result; |
| 118 return; |
| 119 } |
| 120 |
| 121 io_thread_task_runner_->PostTask( |
| 122 FROM_HERE, |
| 123 base::Bind(&ClientNetworkComponents::ConnectWithAssignment, |
| 124 base::Unretained(net_components_.get()), assignment)); |
| 125 } |
| 126 |
| 80 } // namespace client | 127 } // namespace client |
| 81 } // namespace blimp | 128 } // namespace blimp |
| OLD | NEW |