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

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: merge origin/master 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(),
48 delegate_(nullptr),
39 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),
40 weak_factory_(this) { 51 weak_factory_(this) {
41 blimp_connection_statistics_ = new BlimpConnectionStatistics(); 52 blimp_connection_statistics_ = new BlimpConnectionStatistics();
42 net_components_.reset(new ClientNetworkComponents( 53 net_components_.reset(new ClientNetworkComponents(
43 base::MakeUnique<CrossThreadNetworkEventObserver>( 54 base::MakeUnique<CrossThreadNetworkEventObserver>(
44 weak_factory_.GetWeakPtr(), base::SequencedTaskRunnerHandle::Get()), 55 weak_factory_.GetWeakPtr(), base::SequencedTaskRunnerHandle::Get()),
45 base::WrapUnique(blimp_connection_statistics_))); 56 base::WrapUnique(blimp_connection_statistics_)));
46 57
47 // The |thread_pipe_manager_| must be set up correctly before features are 58 // The |thread_pipe_manager_| must be set up correctly before features are
48 // registered. 59 // registered.
49 thread_pipe_manager_ = base::MakeUnique<ThreadPipeManager>( 60 thread_pipe_manager_ = base::MakeUnique<ThreadPipeManager>(
(...skipping 14 matching lines...) Expand all
64 delegate_ = delegate; 75 delegate_ = delegate;
65 } 76 }
66 77
67 std::unique_ptr<BlimpContents> BlimpClientContextImpl::CreateBlimpContents() { 78 std::unique_ptr<BlimpContents> BlimpClientContextImpl::CreateBlimpContents() {
68 std::unique_ptr<BlimpContents> blimp_contents = 79 std::unique_ptr<BlimpContents> blimp_contents =
69 base::MakeUnique<BlimpContentsImpl>(); 80 base::MakeUnique<BlimpContentsImpl>();
70 delegate_->AttachBlimpContentsHelpers(blimp_contents.get()); 81 delegate_->AttachBlimpContentsHelpers(blimp_contents.get());
71 return blimp_contents; 82 return blimp_contents;
72 } 83 }
73 84
85 void BlimpClientContextImpl::Connect(const std::string& client_auth_token) {
86 if (!assignment_source_) {
87 assignment_source_.reset(new AssignmentSource(
88 GetAssignerURL(), io_thread_task_runner_, file_thread_task_runner_));
89 }
90
91 VLOG(1) << "Trying to get assignment.";
92 assignment_source_->GetAssignment(
93 client_auth_token,
94 base::Bind(&BlimpClientContextImpl::ConnectWithAssignment,
95 weak_factory_.GetWeakPtr()));
96 }
97
74 void BlimpClientContextImpl::OnConnected() {} 98 void BlimpClientContextImpl::OnConnected() {}
75 99
76 void BlimpClientContextImpl::OnDisconnected(int result) {} 100 void BlimpClientContextImpl::OnDisconnected(int result) {}
77 101
102 GURL BlimpClientContextImpl::GetAssignerURL() {
103 return GURL(kDefaultAssignerUrl);
104 }
105
106 void BlimpClientContextImpl::ConnectWithAssignment(
107 AssignmentRequestResult result,
108 const Assignment& assignment) {
109 VLOG(1) << "Assignment result: " << result;
110
111 if (delegate_) {
112 delegate_->OnAssignmentConnectionAttempted(result, assignment);
113 }
114
115 if (result != ASSIGNMENT_REQUEST_RESULT_OK) {
116 LOG(ERROR) << "Assignment failed, reason: " << result;
117 return;
118 }
119
120 io_thread_task_runner_->PostTask(
121 FROM_HERE,
122 base::Bind(&ClientNetworkComponents::ConnectWithAssignment,
123 base::Unretained(net_components_.get()), assignment));
124 }
125
78 } // namespace client 126 } // namespace client
79 } // namespace blimp 127 } // namespace blimp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698