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

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

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

Powered by Google App Engine
This is Rietveld 408576698