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

Side by Side Diff: remoting/host/setup/daemon_controller.cc

Issue 1272833002: Pass error messages from native messaging to web-app. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed unit tests. Created 5 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "remoting/host/setup/daemon_controller.h" 5 #include "remoting/host/setup/daemon_controller.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/single_thread_task_runner.h" 9 #include "base/single_thread_task_runner.h"
10 #include "base/thread_task_runner_handle.h" 10 #include "base/thread_task_runner_handle.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 DaemonController::GetConfigCallback wrapped_done = base::Bind( 43 DaemonController::GetConfigCallback wrapped_done = base::Bind(
44 &DaemonController::InvokeConfigCallbackAndScheduleNext, this, done); 44 &DaemonController::InvokeConfigCallbackAndScheduleNext, this, done);
45 base::Closure request = base::Bind( 45 base::Closure request = base::Bind(
46 &DaemonController::DoGetConfig, this, wrapped_done); 46 &DaemonController::DoGetConfig, this, wrapped_done);
47 ServiceOrQueueRequest(request); 47 ServiceOrQueueRequest(request);
48 } 48 }
49 49
50 void DaemonController::SetConfigAndStart( 50 void DaemonController::SetConfigAndStart(
51 scoped_ptr<base::DictionaryValue> config, 51 scoped_ptr<base::DictionaryValue> config,
52 bool consent, 52 bool consent,
53 const CompletionCallback& done) { 53 const base::Closure& on_done,
54 const ErrorCallback& on_error) {
54 DCHECK(caller_task_runner_->BelongsToCurrentThread()); 55 DCHECK(caller_task_runner_->BelongsToCurrentThread());
55 56
56 DaemonController::CompletionCallback wrapped_done = base::Bind( 57 base::Closure wrapped_on_done = base::Bind(
57 &DaemonController::InvokeCompletionCallbackAndScheduleNext, this, done); 58 &DaemonController::InvokeSuccessCallbackAndScheduleNext, this, on_done);
59 DaemonController::ErrorCallback wrapped_on_error = base::Bind(
60 &DaemonController::InvokeErrorCallbackAndScheduleNext, this, on_error);
Sergey Ulanov 2015/08/08 00:57:09 Do we need separate on_done and on_error cases? I
58 base::Closure request = base::Bind( 61 base::Closure request = base::Bind(
59 &DaemonController::DoSetConfigAndStart, this, base::Passed(&config), 62 &DaemonController::DoSetConfigAndStart, this, base::Passed(&config),
60 consent, wrapped_done); 63 consent, wrapped_on_done, wrapped_on_error);
61 ServiceOrQueueRequest(request); 64 ServiceOrQueueRequest(request);
62 } 65 }
63 66
64 void DaemonController::UpdateConfig(scoped_ptr<base::DictionaryValue> config, 67 void DaemonController::UpdateConfig(scoped_ptr<base::DictionaryValue> config,
65 const CompletionCallback& done) { 68 const base::Closure& on_done,
69 const ErrorCallback& on_error) {
66 DCHECK(caller_task_runner_->BelongsToCurrentThread()); 70 DCHECK(caller_task_runner_->BelongsToCurrentThread());
67 71
68 DaemonController::CompletionCallback wrapped_done = base::Bind( 72 base::Closure wrapped_on_done = base::Bind(
69 &DaemonController::InvokeCompletionCallbackAndScheduleNext, this, done); 73 &DaemonController::InvokeSuccessCallbackAndScheduleNext, this, on_done);
74 DaemonController::ErrorCallback wrapped_on_error = base::Bind(
75 &DaemonController::InvokeErrorCallbackAndScheduleNext, this, on_error);
70 base::Closure request = base::Bind( 76 base::Closure request = base::Bind(
71 &DaemonController::DoUpdateConfig, this, base::Passed(&config), 77 &DaemonController::DoUpdateConfig, this, base::Passed(&config),
72 wrapped_done); 78 wrapped_on_done, wrapped_on_error);
73 ServiceOrQueueRequest(request); 79 ServiceOrQueueRequest(request);
74 } 80 }
75 81
76 void DaemonController::Stop(const CompletionCallback& done) { 82 void DaemonController::Stop(const base::Closure& on_done,
83 const ErrorCallback& on_error) {
77 DCHECK(caller_task_runner_->BelongsToCurrentThread()); 84 DCHECK(caller_task_runner_->BelongsToCurrentThread());
78 85
79 DaemonController::CompletionCallback wrapped_done = base::Bind( 86 base::Closure wrapped_on_done = base::Bind(
80 &DaemonController::InvokeCompletionCallbackAndScheduleNext, this, done); 87 &DaemonController::InvokeSuccessCallbackAndScheduleNext, this, on_done);
88 DaemonController::ErrorCallback wrapped_on_error = base::Bind(
89 &DaemonController::InvokeErrorCallbackAndScheduleNext, this, on_error);
81 base::Closure request = base::Bind( 90 base::Closure request = base::Bind(
82 &DaemonController::DoStop, this, wrapped_done); 91 &DaemonController::DoStop, this, wrapped_on_done, wrapped_on_error);
83 ServiceOrQueueRequest(request); 92 ServiceOrQueueRequest(request);
84 } 93 }
85 94
86 void DaemonController::GetUsageStatsConsent( 95 void DaemonController::GetUsageStatsConsent(
87 const GetUsageStatsConsentCallback& done) { 96 const GetUsageStatsConsentCallback& done) {
88 DCHECK(caller_task_runner_->BelongsToCurrentThread()); 97 DCHECK(caller_task_runner_->BelongsToCurrentThread());
89 98
90 DaemonController::GetUsageStatsConsentCallback wrapped_done = base::Bind( 99 DaemonController::GetUsageStatsConsentCallback wrapped_done = base::Bind(
91 &DaemonController::InvokeConsentCallbackAndScheduleNext, this, done); 100 &DaemonController::InvokeConsentCallbackAndScheduleNext, this, done);
92 base::Closure request = base::Bind( 101 base::Closure request = base::Bind(
(...skipping 14 matching lines...) Expand all
107 DCHECK(delegate_task_runner_->BelongsToCurrentThread()); 116 DCHECK(delegate_task_runner_->BelongsToCurrentThread());
108 117
109 scoped_ptr<base::DictionaryValue> config = delegate_->GetConfig(); 118 scoped_ptr<base::DictionaryValue> config = delegate_->GetConfig();
110 caller_task_runner_->PostTask(FROM_HERE, 119 caller_task_runner_->PostTask(FROM_HERE,
111 base::Bind(done, base::Passed(&config))); 120 base::Bind(done, base::Passed(&config)));
112 } 121 }
113 122
114 void DaemonController::DoSetConfigAndStart( 123 void DaemonController::DoSetConfigAndStart(
115 scoped_ptr<base::DictionaryValue> config, 124 scoped_ptr<base::DictionaryValue> config,
116 bool consent, 125 bool consent,
117 const CompletionCallback& done) { 126 const base::Closure& on_done,
127 const ErrorCallback& on_error) {
118 DCHECK(delegate_task_runner_->BelongsToCurrentThread()); 128 DCHECK(delegate_task_runner_->BelongsToCurrentThread());
119 129
120 delegate_->SetConfigAndStart(config.Pass(), consent, done); 130 delegate_->SetConfigAndStart(config.Pass(), consent, on_done, on_error);
121 } 131 }
122 132
123 void DaemonController::DoUpdateConfig( 133 void DaemonController::DoUpdateConfig(
124 scoped_ptr<base::DictionaryValue> config, 134 scoped_ptr<base::DictionaryValue> config,
125 const CompletionCallback& done) { 135 const base::Closure& on_done,
136 const ErrorCallback& on_error) {
126 DCHECK(delegate_task_runner_->BelongsToCurrentThread()); 137 DCHECK(delegate_task_runner_->BelongsToCurrentThread());
127 138
128 delegate_->UpdateConfig(config.Pass(), done); 139 delegate_->UpdateConfig(config.Pass(), on_done, on_error);
129 } 140 }
130 141
131 void DaemonController::DoStop(const CompletionCallback& done) { 142 void DaemonController::DoStop(const base::Closure& on_done,
143 const ErrorCallback& on_error) {
132 DCHECK(delegate_task_runner_->BelongsToCurrentThread()); 144 DCHECK(delegate_task_runner_->BelongsToCurrentThread());
133 145
134 delegate_->Stop(done); 146 delegate_->Stop(on_done, on_error);
135 } 147 }
136 148
137 void DaemonController::DoGetUsageStatsConsent( 149 void DaemonController::DoGetUsageStatsConsent(
138 const GetUsageStatsConsentCallback& done) { 150 const GetUsageStatsConsentCallback& done) {
139 DCHECK(delegate_task_runner_->BelongsToCurrentThread()); 151 DCHECK(delegate_task_runner_->BelongsToCurrentThread());
140 152
141 DaemonController::UsageStatsConsent consent = 153 DaemonController::UsageStatsConsent consent =
142 delegate_->GetUsageStatsConsent(); 154 delegate_->GetUsageStatsConsent();
143 caller_task_runner_->PostTask(FROM_HERE, base::Bind(done, consent)); 155 caller_task_runner_->PostTask(FROM_HERE, base::Bind(done, consent));
144 } 156 }
145 157
146 void DaemonController::InvokeCompletionCallbackAndScheduleNext( 158 void DaemonController::InvokeSuccessCallbackAndScheduleNext(
147 const CompletionCallback& done, 159 const base::Closure& callback) {
148 AsyncResult result) {
149 if (!caller_task_runner_->BelongsToCurrentThread()) { 160 if (!caller_task_runner_->BelongsToCurrentThread()) {
150 caller_task_runner_->PostTask( 161 caller_task_runner_->PostTask(
151 FROM_HERE, 162 FROM_HERE,
152 base::Bind(&DaemonController::InvokeCompletionCallbackAndScheduleNext, 163 base::Bind(&DaemonController::InvokeSuccessCallbackAndScheduleNext,
153 this, done, result)); 164 this, callback));
154 return; 165 return;
155 } 166 }
156 167
157 done.Run(result); 168 callback.Run();
169 ScheduleNext();
170 }
171
172 void DaemonController::InvokeErrorCallbackAndScheduleNext(
173 const ErrorCallback& callback,
174 const std::string& error_message,
175 const tracked_objects::Location& location) {
176 if (!caller_task_runner_->BelongsToCurrentThread()) {
Sergey Ulanov 2015/08/08 00:57:09 Delegate interface definition says that the callba
177 caller_task_runner_->PostTask(
178 FROM_HERE,
179 base::Bind(&DaemonController::InvokeErrorCallbackAndScheduleNext,
180 this, callback, error_message, location));
181 return;
182 }
183
184 callback.Run(error_message, location);
158 ScheduleNext(); 185 ScheduleNext();
159 } 186 }
160 187
161 void DaemonController::InvokeConfigCallbackAndScheduleNext( 188 void DaemonController::InvokeConfigCallbackAndScheduleNext(
162 const GetConfigCallback& done, 189 const GetConfigCallback& callback,
163 scoped_ptr<base::DictionaryValue> config) { 190 scoped_ptr<base::DictionaryValue> config) {
164 DCHECK(caller_task_runner_->BelongsToCurrentThread()); 191 DCHECK(caller_task_runner_->BelongsToCurrentThread());
165 192
166 done.Run(config.Pass()); 193 callback.Run(config.Pass());
167 ScheduleNext(); 194 ScheduleNext();
168 } 195 }
169 196
170 void DaemonController::InvokeConsentCallbackAndScheduleNext( 197 void DaemonController::InvokeConsentCallbackAndScheduleNext(
171 const GetUsageStatsConsentCallback& done, 198 const GetUsageStatsConsentCallback& callback,
172 const UsageStatsConsent& consent) { 199 const UsageStatsConsent& consent) {
173 DCHECK(caller_task_runner_->BelongsToCurrentThread()); 200 DCHECK(caller_task_runner_->BelongsToCurrentThread());
174 201
175 done.Run(consent); 202 callback.Run(consent);
176 ScheduleNext(); 203 ScheduleNext();
177 } 204 }
178 205
179 void DaemonController::ScheduleNext() { 206 void DaemonController::ScheduleNext() {
180 DCHECK(caller_task_runner_->BelongsToCurrentThread()); 207 DCHECK(caller_task_runner_->BelongsToCurrentThread());
181 208
182 pending_requests_.pop(); 209 pending_requests_.pop();
183 ServiceNextRequest(); 210 ServiceNextRequest();
184 } 211 }
185 212
186 void DaemonController::ServiceOrQueueRequest(const base::Closure& request) { 213 void DaemonController::ServiceOrQueueRequest(const base::Closure& request) {
187 bool servicing_request = !pending_requests_.empty(); 214 bool servicing_request = !pending_requests_.empty();
188 pending_requests_.push(request); 215 pending_requests_.push(request);
189 if (!servicing_request) 216 if (!servicing_request)
190 ServiceNextRequest(); 217 ServiceNextRequest();
191 } 218 }
192 219
193 void DaemonController::ServiceNextRequest() { 220 void DaemonController::ServiceNextRequest() {
194 if (!pending_requests_.empty()) 221 if (!pending_requests_.empty())
195 delegate_task_runner_->PostTask(FROM_HERE, pending_requests_.front()); 222 delegate_task_runner_->PostTask(FROM_HERE, pending_requests_.front());
196 } 223 }
197 224
198 } // namespace remoting 225 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698