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

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

Issue 2255533002: Add TabControlFeature to BlimpClientContextImpl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add BlimpContentsImplTest.SetSizeAndScaleThroughTabControlFeature Created 4 years, 4 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 "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/contents/tab_control_feature.h"
13 #include "blimp/client/core/session/cross_thread_network_event_observer.h" 14 #include "blimp/client/core/session/cross_thread_network_event_observer.h"
14 #include "blimp/client/public/blimp_client_context_delegate.h" 15 #include "blimp/client/public/blimp_client_context_delegate.h"
15 16
16 #if defined(OS_ANDROID) 17 #if defined(OS_ANDROID)
17 #include "blimp/client/core/android/blimp_client_context_impl_android.h" 18 #include "blimp/client/core/android/blimp_client_context_impl_android.h"
18 #endif // OS_ANDROID 19 #endif // OS_ANDROID
19 20
20 namespace blimp { 21 namespace blimp {
21 namespace client { 22 namespace client {
22 23
23 namespace { 24 namespace {
24 const char kDefaultAssignerUrl[] = 25 const char kDefaultAssignerUrl[] =
25 "https://blimp-pa.googleapis.com/v1/assignment"; 26 "https://blimp-pa.googleapis.com/v1/assignment";
27 const int kDummyTabId = 0;
26 } // namespace 28 } // namespace
27 29
28 // This function is declared in //blimp/client/public/blimp_client_context.h, 30 // This function is declared in //blimp/client/public/blimp_client_context.h,
29 // and either this function or the one in 31 // and either this function or the one in
30 // //blimp/client/core/dummy_blimp_client_context.cc should be linked in to 32 // //blimp/client/core/dummy_blimp_client_context.cc should be linked in to
31 // any binary using BlimpClientContext::Create. 33 // any binary using BlimpClientContext::Create.
32 // static 34 // static
33 BlimpClientContext* BlimpClientContext::Create( 35 BlimpClientContext* BlimpClientContext::Create(
34 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner, 36 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner,
35 scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner) { 37 scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner) {
36 #if defined(OS_ANDROID) 38 #if defined(OS_ANDROID)
37 return new BlimpClientContextImplAndroid(io_thread_task_runner, 39 return new BlimpClientContextImplAndroid(io_thread_task_runner,
38 file_thread_task_runner); 40 file_thread_task_runner);
39 #else 41 #else
40 return new BlimpClientContextImpl(io_thread_task_runner, 42 return new BlimpClientContextImpl(io_thread_task_runner,
41 file_thread_task_runner); 43 file_thread_task_runner);
42 #endif // defined(OS_ANDROID) 44 #endif // defined(OS_ANDROID)
43 } 45 }
44 46
45 BlimpClientContextImpl::BlimpClientContextImpl( 47 BlimpClientContextImpl::BlimpClientContextImpl(
46 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner, 48 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner,
47 scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner) 49 scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner)
48 : BlimpClientContext(), 50 : BlimpClientContext(),
49 io_thread_task_runner_(io_thread_task_runner), 51 io_thread_task_runner_(io_thread_task_runner),
50 file_thread_task_runner_(file_thread_task_runner), 52 file_thread_task_runner_(file_thread_task_runner),
51 blimp_contents_manager_(new BlimpContentsManager), 53 blimp_contents_manager_(new BlimpContentsManager),
54 tab_control_feature_(new TabControlFeature),
52 weak_factory_(this) { 55 weak_factory_(this) {
53 net_components_.reset(new ClientNetworkComponents( 56 net_components_.reset(new ClientNetworkComponents(
54 base::MakeUnique<CrossThreadNetworkEventObserver>( 57 base::MakeUnique<CrossThreadNetworkEventObserver>(
55 weak_factory_.GetWeakPtr(), base::SequencedTaskRunnerHandle::Get()))); 58 weak_factory_.GetWeakPtr(), base::SequencedTaskRunnerHandle::Get())));
56 59
57 // The |thread_pipe_manager_| must be set up correctly before features are 60 // The |thread_pipe_manager_| must be set up correctly before features are
58 // registered. 61 // registered.
59 thread_pipe_manager_ = base::MakeUnique<ThreadPipeManager>( 62 thread_pipe_manager_ = base::MakeUnique<ThreadPipeManager>(
60 io_thread_task_runner_, net_components_->GetBrowserConnectionHandler()); 63 io_thread_task_runner_, net_components_->GetBrowserConnectionHandler());
61 64
65 RegisterFeatures();
66
62 // Initialize must only be posted after the calls features have been 67 // Initialize must only be posted after the calls features have been
63 // registered. 68 // registered.
64 io_thread_task_runner_->PostTask( 69 io_thread_task_runner_->PostTask(
65 FROM_HERE, base::Bind(&ClientNetworkComponents::Initialize, 70 FROM_HERE, base::Bind(&ClientNetworkComponents::Initialize,
66 base::Unretained(net_components_.get()))); 71 base::Unretained(net_components_.get())));
72
73 // Create a single tab's WebContents.
74 // TODO(kmarshall): Remove this once we add tab-literacy to Blimp.
75 GetTabControlFeature()->CreateTab(kDummyTabId);
David Trainor- moved to gerrit 2016/08/18 17:41:58 We don't need this. It'll be driven by the Chrome
Menglin 2016/08/19 00:50:21 Done.
67 } 76 }
68 77
69 BlimpClientContextImpl::~BlimpClientContextImpl() { 78 BlimpClientContextImpl::~BlimpClientContextImpl() {
70 io_thread_task_runner_->DeleteSoon(FROM_HERE, net_components_.release()); 79 io_thread_task_runner_->DeleteSoon(FROM_HERE, net_components_.release());
71 } 80 }
72 81
73 void BlimpClientContextImpl::SetDelegate(BlimpClientContextDelegate* delegate) { 82 void BlimpClientContextImpl::SetDelegate(BlimpClientContextDelegate* delegate) {
74 delegate_ = delegate; 83 delegate_ = delegate;
75 } 84 }
76 85
77 std::unique_ptr<BlimpContents> BlimpClientContextImpl::CreateBlimpContents() { 86 std::unique_ptr<BlimpContents> BlimpClientContextImpl::CreateBlimpContents() {
78 std::unique_ptr<BlimpContents> blimp_contents = 87 std::unique_ptr<BlimpContents> blimp_contents =
79 blimp_contents_manager_->CreateBlimpContents(); 88 blimp_contents_manager_->CreateBlimpContents(tab_control_feature_.get());
80 delegate_->AttachBlimpContentsHelpers(blimp_contents.get()); 89 delegate_->AttachBlimpContentsHelpers(blimp_contents.get());
81 return blimp_contents; 90 return blimp_contents;
82 } 91 }
83 92
84 void BlimpClientContextImpl::Connect(const std::string& client_auth_token) { 93 void BlimpClientContextImpl::Connect(const std::string& client_auth_token) {
85 if (!assignment_source_) { 94 if (!assignment_source_) {
86 assignment_source_.reset(new AssignmentSource( 95 assignment_source_.reset(new AssignmentSource(
87 GetAssignerURL(), io_thread_task_runner_, file_thread_task_runner_)); 96 GetAssignerURL(), io_thread_task_runner_, file_thread_task_runner_));
88 } 97 }
89 98
90 VLOG(1) << "Trying to get assignment."; 99 VLOG(1) << "Trying to get assignment.";
91 assignment_source_->GetAssignment( 100 assignment_source_->GetAssignment(
92 client_auth_token, 101 client_auth_token,
93 base::Bind(&BlimpClientContextImpl::ConnectWithAssignment, 102 base::Bind(&BlimpClientContextImpl::ConnectWithAssignment,
94 weak_factory_.GetWeakPtr())); 103 weak_factory_.GetWeakPtr()));
95 } 104 }
96 105
97 void BlimpClientContextImpl::OnConnected() {} 106 void BlimpClientContextImpl::OnConnected() {}
98 107
99 void BlimpClientContextImpl::OnDisconnected(int result) {} 108 void BlimpClientContextImpl::OnDisconnected(int result) {}
100 109
110 TabControlFeature* BlimpClientContextImpl::GetTabControlFeature() const {
111 return tab_control_feature_.get();
112 }
113
101 GURL BlimpClientContextImpl::GetAssignerURL() { 114 GURL BlimpClientContextImpl::GetAssignerURL() {
102 return GURL(kDefaultAssignerUrl); 115 return GURL(kDefaultAssignerUrl);
103 } 116 }
104 117
105 void BlimpClientContextImpl::ConnectWithAssignment( 118 void BlimpClientContextImpl::ConnectWithAssignment(
106 AssignmentRequestResult result, 119 AssignmentRequestResult result,
107 const Assignment& assignment) { 120 const Assignment& assignment) {
108 VLOG(1) << "Assignment result: " << result; 121 VLOG(1) << "Assignment result: " << result;
109 122
110 if (delegate_) { 123 if (delegate_) {
111 delegate_->OnAssignmentConnectionAttempted(result, assignment); 124 delegate_->OnAssignmentConnectionAttempted(result, assignment);
112 } 125 }
113 126
114 if (result != ASSIGNMENT_REQUEST_RESULT_OK) { 127 if (result != ASSIGNMENT_REQUEST_RESULT_OK) {
115 LOG(ERROR) << "Assignment failed, reason: " << result; 128 LOG(ERROR) << "Assignment failed, reason: " << result;
116 return; 129 return;
117 } 130 }
118 131
119 io_thread_task_runner_->PostTask( 132 io_thread_task_runner_->PostTask(
120 FROM_HERE, 133 FROM_HERE,
121 base::Bind(&ClientNetworkComponents::ConnectWithAssignment, 134 base::Bind(&ClientNetworkComponents::ConnectWithAssignment,
122 base::Unretained(net_components_.get()), assignment)); 135 base::Unretained(net_components_.get()), assignment));
123 } 136 }
124 137
138 void BlimpClientContextImpl::RegisterFeatures() {
139 // Register features' message senders and receivers.
140 tab_control_feature_->set_outgoing_message_processor(
141 thread_pipe_manager_->RegisterFeature(BlimpMessage::kTabControl,
142 tab_control_feature_.get()));
143 }
144
125 } // namespace client 145 } // namespace client
126 } // namespace blimp 146 } // namespace blimp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698