| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/session/blimp_client_session.h" | 5 #include "blimp/client/session/blimp_client_session.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 11 #include "base/numerics/safe_conversions.h" | 11 #include "base/numerics/safe_conversions.h" |
| 12 #include "base/sequenced_task_runner.h" |
| 12 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
| 13 #include "base/threading/sequenced_task_runner_handle.h" | 14 #include "base/threading/task_runner_handle.h" |
| 14 #include "base/threading/thread_task_runner_handle.h" | |
| 15 #include "blimp/client/app/blimp_client_switches.h" | 15 #include "blimp/client/app/blimp_client_switches.h" |
| 16 #include "blimp/client/feature/ime_feature.h" | 16 #include "blimp/client/feature/ime_feature.h" |
| 17 #include "blimp/client/feature/navigation_feature.h" | 17 #include "blimp/client/feature/navigation_feature.h" |
| 18 #include "blimp/client/feature/render_widget_feature.h" | 18 #include "blimp/client/feature/render_widget_feature.h" |
| 19 #include "blimp/client/feature/settings_feature.h" | 19 #include "blimp/client/feature/settings_feature.h" |
| 20 #include "blimp/client/feature/tab_control_feature.h" | 20 #include "blimp/client/feature/tab_control_feature.h" |
| 21 #include "blimp/common/blob_cache/in_memory_blob_cache.h" | 21 #include "blimp/common/blob_cache/in_memory_blob_cache.h" |
| 22 #include "blimp/net/blimp_connection.h" | 22 #include "blimp/net/blimp_connection.h" |
| 23 #include "blimp/net/blimp_message_processor.h" | 23 #include "blimp/net/blimp_message_processor.h" |
| 24 #include "blimp/net/blimp_message_thread_pipe.h" | 24 #include "blimp/net/blimp_message_thread_pipe.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 39 | 39 |
| 40 namespace blimp { | 40 namespace blimp { |
| 41 namespace client { | 41 namespace client { |
| 42 namespace { | 42 namespace { |
| 43 | 43 |
| 44 // Posts network events to an observer across the IO/UI thread boundary. | 44 // Posts network events to an observer across the IO/UI thread boundary. |
| 45 class CrossThreadNetworkEventObserver : public NetworkEventObserver { | 45 class CrossThreadNetworkEventObserver : public NetworkEventObserver { |
| 46 public: | 46 public: |
| 47 CrossThreadNetworkEventObserver( | 47 CrossThreadNetworkEventObserver( |
| 48 const base::WeakPtr<NetworkEventObserver>& target, | 48 const base::WeakPtr<NetworkEventObserver>& target, |
| 49 const scoped_refptr<base::TaskRunner>& task_runner) | 49 const scoped_refptr<base::SequencedTaskRunner>& task_runner) |
| 50 : target_(target), task_runner_(task_runner) {} | 50 : target_(target), task_runner_(task_runner) {} |
| 51 | 51 |
| 52 ~CrossThreadNetworkEventObserver() override {} | 52 ~CrossThreadNetworkEventObserver() override {} |
| 53 | 53 |
| 54 void OnConnected() override { | 54 void OnConnected() override { |
| 55 task_runner_->PostTask( | 55 task_runner_->PostTask( |
| 56 FROM_HERE, base::Bind(&NetworkEventObserver::OnConnected, target_)); | 56 FROM_HERE, base::Bind(&NetworkEventObserver::OnConnected, target_)); |
| 57 } | 57 } |
| 58 | 58 |
| 59 void OnDisconnected(int result) override { | 59 void OnDisconnected(int result) override { |
| 60 task_runner_->PostTask( | 60 task_runner_->PostTask( |
| 61 FROM_HERE, | 61 FROM_HERE, |
| 62 base::Bind(&NetworkEventObserver::OnDisconnected, target_, result)); | 62 base::Bind(&NetworkEventObserver::OnDisconnected, target_, result)); |
| 63 } | 63 } |
| 64 | 64 |
| 65 private: | 65 private: |
| 66 base::WeakPtr<NetworkEventObserver> target_; | 66 base::WeakPtr<NetworkEventObserver> target_; |
| 67 scoped_refptr<base::TaskRunner> task_runner_; | 67 scoped_refptr<base::SequencedTaskRunner> task_runner_; |
| 68 }; | 68 }; |
| 69 | 69 |
| 70 } // namespace | 70 } // namespace |
| 71 | 71 |
| 72 // This class's functions and destruction are all invoked on the IO thread by | 72 // This class's functions and destruction are all invoked on the IO thread by |
| 73 // the BlimpClientSession. | 73 // the BlimpClientSession. |
| 74 class ClientNetworkComponents : public ConnectionHandler, | 74 class ClientNetworkComponents : public ConnectionHandler, |
| 75 public ConnectionErrorObserver { | 75 public ConnectionErrorObserver { |
| 76 public: | 76 public: |
| 77 // Can be created on any thread. | 77 // Can be created on any thread. |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 ime_feature_(new ImeFeature), | 185 ime_feature_(new ImeFeature), |
| 186 render_widget_feature_(new RenderWidgetFeature), | 186 render_widget_feature_(new RenderWidgetFeature), |
| 187 settings_feature_(new SettingsFeature), | 187 settings_feature_(new SettingsFeature), |
| 188 weak_factory_(this) { | 188 weak_factory_(this) { |
| 189 base::Thread::Options options; | 189 base::Thread::Options options; |
| 190 options.message_loop_type = base::MessageLoop::TYPE_IO; | 190 options.message_loop_type = base::MessageLoop::TYPE_IO; |
| 191 io_thread_.StartWithOptions(options); | 191 io_thread_.StartWithOptions(options); |
| 192 blimp_connection_statistics_ = new BlimpConnectionStatistics(); | 192 blimp_connection_statistics_ = new BlimpConnectionStatistics(); |
| 193 net_components_.reset(new ClientNetworkComponents( | 193 net_components_.reset(new ClientNetworkComponents( |
| 194 base::WrapUnique(new CrossThreadNetworkEventObserver( | 194 base::WrapUnique(new CrossThreadNetworkEventObserver( |
| 195 weak_factory_.GetWeakPtr(), base::SequencedTaskRunnerHandle::Get())), | 195 weak_factory_.GetWeakPtr(), base::TaskRunnerHandle::GetSequenced())), |
| 196 base::WrapUnique(blimp_connection_statistics_))); | 196 base::WrapUnique(blimp_connection_statistics_))); |
| 197 | 197 |
| 198 assignment_source_.reset(new AssignmentSource( | 198 assignment_source_.reset(new AssignmentSource( |
| 199 assigner_endpoint, io_thread_.task_runner(), io_thread_.task_runner())); | 199 assigner_endpoint, io_thread_.task_runner(), io_thread_.task_runner())); |
| 200 | 200 |
| 201 std::unique_ptr<HeliumBlobReceiverDelegate> blob_delegate( | 201 std::unique_ptr<HeliumBlobReceiverDelegate> blob_delegate( |
| 202 new HeliumBlobReceiverDelegate); | 202 new HeliumBlobReceiverDelegate); |
| 203 blob_delegate_ = blob_delegate.get(); | 203 blob_delegate_ = blob_delegate.get(); |
| 204 blob_receiver_ = BlobChannelReceiver::Create( | 204 blob_receiver_ = BlobChannelReceiver::Create( |
| 205 base::WrapUnique(new InMemoryBlobCache), std::move(blob_delegate)); | 205 base::WrapUnique(new InMemoryBlobCache), std::move(blob_delegate)); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 return settings_feature_.get(); | 316 return settings_feature_.get(); |
| 317 } | 317 } |
| 318 | 318 |
| 319 BlimpConnectionStatistics* BlimpClientSession::GetBlimpConnectionStatistics() | 319 BlimpConnectionStatistics* BlimpClientSession::GetBlimpConnectionStatistics() |
| 320 const { | 320 const { |
| 321 return blimp_connection_statistics_; | 321 return blimp_connection_statistics_; |
| 322 } | 322 } |
| 323 | 323 |
| 324 } // namespace client | 324 } // namespace client |
| 325 } // namespace blimp | 325 } // namespace blimp |
| OLD | NEW |