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

Side by Side Diff: mojo/dart/packages/mojo_services/lib/mojo/location_service.mojom.dart

Issue 1964193002: Dart: Refactors Proxies (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Cleanup Created 4 years, 7 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 library location_service_mojom; 5 library location_service_mojom;
6 import 'dart:async'; 6 import 'dart:async';
7 import 'package:mojo/bindings.dart' as bindings; 7 import 'package:mojo/bindings.dart' as bindings;
8 import 'package:mojo/core.dart' as core; 8 import 'package:mojo/core.dart' as core;
9 import 'package:mojo/mojo/bindings/types/service_describer.mojom.dart' as servic e_describer; 9 import 'package:mojo/mojo/bindings/types/service_describer.mojom.dart' as servic e_describer;
10 import 'package:mojo_services/mojo/location.mojom.dart' as location_mojom; 10 import 'package:mojo_services/mojo/location.mojom.dart' as location_mojom;
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 dynamic getAllTypeDefinitions([Function responseFactory]) => 237 dynamic getAllTypeDefinitions([Function responseFactory]) =>
238 responseFactory(null); 238 responseFactory(null);
239 } 239 }
240 240
241 abstract class LocationService { 241 abstract class LocationService {
242 static const String serviceName = "mojo::LocationService"; 242 static const String serviceName = "mojo::LocationService";
243 dynamic getNextLocation(LocationServiceUpdatePriority priority,[Function respo nseFactory = null]); 243 dynamic getNextLocation(LocationServiceUpdatePriority priority,[Function respo nseFactory = null]);
244 } 244 }
245 245
246 246
247 class _LocationServiceProxyImpl extends bindings.Proxy { 247 class _LocationServiceProxyControl extends bindings.ProxyMessageHandler
248 _LocationServiceProxyImpl.fromEndpoint( 248 implements bindings.ProxyControl {
249 _LocationServiceProxyControl.fromEndpoint(
249 core.MojoMessagePipeEndpoint endpoint) : super.fromEndpoint(endpoint); 250 core.MojoMessagePipeEndpoint endpoint) : super.fromEndpoint(endpoint);
250 251
251 _LocationServiceProxyImpl.fromHandle(core.MojoHandle handle) : 252 _LocationServiceProxyControl.fromHandle(
252 super.fromHandle(handle); 253 core.MojoHandle handle) : super.fromHandle(handle);
253 254
254 _LocationServiceProxyImpl.unbound() : super.unbound(); 255 _LocationServiceProxyControl.unbound() : super.unbound();
255
256 static _LocationServiceProxyImpl newFromEndpoint(
257 core.MojoMessagePipeEndpoint endpoint) {
258 assert(endpoint.setDescription("For _LocationServiceProxyImpl"));
259 return new _LocationServiceProxyImpl.fromEndpoint(endpoint);
260 }
261 256
262 service_describer.ServiceDescription get serviceDescription => 257 service_describer.ServiceDescription get serviceDescription =>
263 new _LocationServiceServiceDescription(); 258 new _LocationServiceServiceDescription();
264 259
260 String get serviceName => LocationService.serviceName;
261
262 @override
265 void handleResponse(bindings.ServiceMessage message) { 263 void handleResponse(bindings.ServiceMessage message) {
266 switch (message.header.type) { 264 switch (message.header.type) {
267 case _locationServiceMethodGetNextLocationName: 265 case _locationServiceMethodGetNextLocationName:
268 var r = LocationServiceGetNextLocationResponseParams.deserialize( 266 var r = LocationServiceGetNextLocationResponseParams.deserialize(
269 message.payload); 267 message.payload);
270 if (!message.header.hasRequestId) { 268 if (!message.header.hasRequestId) {
271 proxyError("Expected a message with a valid request Id."); 269 proxyError("Expected a message with a valid request Id.");
272 return; 270 return;
273 } 271 }
274 Completer c = completerMap[message.header.requestId]; 272 Completer c = completerMap[message.header.requestId];
275 if (c == null) { 273 if (c == null) {
276 proxyError( 274 proxyError(
277 "Message had unknown request Id: ${message.header.requestId}"); 275 "Message had unknown request Id: ${message.header.requestId}");
278 return; 276 return;
279 } 277 }
280 completerMap.remove(message.header.requestId); 278 completerMap.remove(message.header.requestId);
281 if (c.isCompleted) { 279 if (c.isCompleted) {
282 proxyError("Response completer already completed"); 280 proxyError("Response completer already completed");
283 return; 281 return;
284 } 282 }
285 c.complete(r); 283 c.complete(r);
286 break; 284 break;
287 default: 285 default:
288 proxyError("Unexpected message type: ${message.header.type}"); 286 proxyError("Unexpected message type: ${message.header.type}");
289 close(immediate: true); 287 close(immediate: true);
290 break; 288 break;
291 } 289 }
292 } 290 }
293 291
292 @override
294 String toString() { 293 String toString() {
295 var superString = super.toString(); 294 var superString = super.toString();
296 return "_LocationServiceProxyImpl($superString)"; 295 return "_LocationServiceProxyControl($superString)";
297 } 296 }
298 } 297 }
299 298
300 299
301 class _LocationServiceProxyCalls implements LocationService { 300 class LocationServiceProxy extends bindings.Proxy
302 _LocationServiceProxyImpl _proxyImpl; 301 implements LocationService {
302 LocationServiceProxy.fromEndpoint(
303 core.MojoMessagePipeEndpoint endpoint)
304 : super(new _LocationServiceProxyControl.fromEndpoint(endpoint));
303 305
304 _LocationServiceProxyCalls(this._proxyImpl); 306 LocationServiceProxy.fromHandle(core.MojoHandle handle)
305 dynamic getNextLocation(LocationServiceUpdatePriority priority,[Function res ponseFactory = null]) { 307 : super(new _LocationServiceProxyControl.fromHandle(handle));
306 var params = new _LocationServiceGetNextLocationParams();
307 params.priority = priority;
308 return _proxyImpl.sendMessageWithRequestId(
309 params,
310 _locationServiceMethodGetNextLocationName,
311 -1,
312 bindings.MessageHeader.kMessageExpectsResponse);
313 }
314 }
315 308
309 LocationServiceProxy.unbound()
310 : super(new _LocationServiceProxyControl.unbound());
316 311
317 class LocationServiceProxy implements bindings.ProxyBase { 312 static LocationServiceProxy newFromEndpoint(
318 final bindings.Proxy impl; 313 core.MojoMessagePipeEndpoint endpoint) {
319 LocationService ptr; 314 assert(endpoint.setDescription("For LocationServiceProxy"));
320 315 return new LocationServiceProxy.fromEndpoint(endpoint);
321 LocationServiceProxy(_LocationServiceProxyImpl proxyImpl) :
322 impl = proxyImpl,
323 ptr = new _LocationServiceProxyCalls(proxyImpl);
324
325 LocationServiceProxy.fromEndpoint(
326 core.MojoMessagePipeEndpoint endpoint) :
327 impl = new _LocationServiceProxyImpl.fromEndpoint(endpoint) {
328 ptr = new _LocationServiceProxyCalls(impl);
329 }
330
331 LocationServiceProxy.fromHandle(core.MojoHandle handle) :
332 impl = new _LocationServiceProxyImpl.fromHandle(handle) {
333 ptr = new _LocationServiceProxyCalls(impl);
334 }
335
336 LocationServiceProxy.unbound() :
337 impl = new _LocationServiceProxyImpl.unbound() {
338 ptr = new _LocationServiceProxyCalls(impl);
339 } 316 }
340 317
341 factory LocationServiceProxy.connectToService( 318 factory LocationServiceProxy.connectToService(
342 bindings.ServiceConnector s, String url, [String serviceName]) { 319 bindings.ServiceConnector s, String url, [String serviceName]) {
343 LocationServiceProxy p = new LocationServiceProxy.unbound(); 320 LocationServiceProxy p = new LocationServiceProxy.unbound();
344 s.connectToService(url, p, serviceName); 321 s.connectToService(url, p, serviceName);
345 return p; 322 return p;
346 } 323 }
347 324
348 static LocationServiceProxy newFromEndpoint(
349 core.MojoMessagePipeEndpoint endpoint) {
350 assert(endpoint.setDescription("For LocationServiceProxy"));
351 return new LocationServiceProxy.fromEndpoint(endpoint);
352 }
353 325
354 String get serviceName => LocationService.serviceName; 326 dynamic getNextLocation(LocationServiceUpdatePriority priority,[Function respo nseFactory = null]) {
355 327 var params = new _LocationServiceGetNextLocationParams();
356 Future close({bool immediate: false}) => impl.close(immediate: immediate); 328 params.priority = priority;
357 329 return ctrl.sendMessageWithRequestId(
358 Future responseOrError(Future f) => impl.responseOrError(f); 330 params,
359 331 _locationServiceMethodGetNextLocationName,
360 Future get errorFuture => impl.errorFuture; 332 -1,
361 333 bindings.MessageHeader.kMessageExpectsResponse);
362 int get version => impl.version;
363
364 Future<int> queryVersion() => impl.queryVersion();
365
366 void requireVersion(int requiredVersion) {
367 impl.requireVersion(requiredVersion);
368 }
369
370 String toString() {
371 return "LocationServiceProxy($impl)";
372 } 334 }
373 } 335 }
374 336
375 337
376 class LocationServiceStub extends bindings.Stub { 338 class LocationServiceStub extends bindings.Stub {
377 LocationService _impl; 339 LocationService _impl;
378 340
379 LocationServiceStub.fromEndpoint( 341 LocationServiceStub.fromEndpoint(
380 core.MojoMessagePipeEndpoint endpoint, [LocationService impl]) 342 core.MojoMessagePipeEndpoint endpoint, [LocationService impl])
381 : super.fromEndpoint(endpoint, autoBegin: impl != null) { 343 : super.fromEndpoint(endpoint, autoBegin: impl != null) {
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 static service_describer.ServiceDescription get serviceDescription { 434 static service_describer.ServiceDescription get serviceDescription {
473 if (_cachedServiceDescription == null) { 435 if (_cachedServiceDescription == null) {
474 _cachedServiceDescription = new _LocationServiceServiceDescription(); 436 _cachedServiceDescription = new _LocationServiceServiceDescription();
475 } 437 }
476 return _cachedServiceDescription; 438 return _cachedServiceDescription;
477 } 439 }
478 } 440 }
479 441
480 442
481 443
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698