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

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

Issue 1948003003: Dart: Wait to handle events on a Stub until it makes sense to do it. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Add test 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 directory_mojom; 5 library directory_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/files/file.mojom.dart' as file_mojom; 10 import 'package:mojo_services/mojo/files/file.mojom.dart' as file_mojom;
(...skipping 1482 matching lines...) Expand 10 before | Expand all | Expand 10 after
1493 impl.requireVersion(requiredVersion); 1493 impl.requireVersion(requiredVersion);
1494 } 1494 }
1495 1495
1496 String toString() { 1496 String toString() {
1497 return "DirectoryProxy($impl)"; 1497 return "DirectoryProxy($impl)";
1498 } 1498 }
1499 } 1499 }
1500 1500
1501 1501
1502 class DirectoryStub extends bindings.Stub { 1502 class DirectoryStub extends bindings.Stub {
1503 Directory _impl = null; 1503 Directory _impl;
1504 1504
1505 DirectoryStub.fromEndpoint( 1505 DirectoryStub.fromEndpoint(
1506 core.MojoMessagePipeEndpoint endpoint, [this._impl]) 1506 core.MojoMessagePipeEndpoint endpoint, [Directory impl])
1507 : super.fromEndpoint(endpoint); 1507 : super.fromEndpoint(endpoint, autoBegin: impl != null) {
1508 _impl = impl;
1509 }
1508 1510
1509 DirectoryStub.fromHandle(core.MojoHandle handle, [this._impl]) 1511 DirectoryStub.fromHandle(
1510 : super.fromHandle(handle); 1512 core.MojoHandle handle, [Directory impl])
1513 : super.fromHandle(handle, autoBegin: impl != null) {
1514 _impl = impl;
1515 }
1511 1516
1512 DirectoryStub.unbound() : super.unbound(); 1517 DirectoryStub.unbound() : super.unbound();
1513 1518
1514 static DirectoryStub newFromEndpoint( 1519 static DirectoryStub newFromEndpoint(
1515 core.MojoMessagePipeEndpoint endpoint) { 1520 core.MojoMessagePipeEndpoint endpoint) {
1516 assert(endpoint.setDescription("For DirectoryStub")); 1521 assert(endpoint.setDescription("For DirectoryStub"));
1517 return new DirectoryStub.fromEndpoint(endpoint); 1522 return new DirectoryStub.fromEndpoint(endpoint);
1518 } 1523 }
1519 1524
1520 1525
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1555 result.error = error; 1560 result.error = error;
1556 return result; 1561 return result;
1557 } 1562 }
1558 1563
1559 dynamic handleMessage(bindings.ServiceMessage message) { 1564 dynamic handleMessage(bindings.ServiceMessage message) {
1560 if (bindings.ControlMessageHandler.isControlMessage(message)) { 1565 if (bindings.ControlMessageHandler.isControlMessage(message)) {
1561 return bindings.ControlMessageHandler.handleMessage(this, 1566 return bindings.ControlMessageHandler.handleMessage(this,
1562 0, 1567 0,
1563 message); 1568 message);
1564 } 1569 }
1565 assert(_impl != null); 1570 if (_impl == null) {
1571 throw new core.MojoApiError("$this has no implementation set");
1572 }
1566 switch (message.header.type) { 1573 switch (message.header.type) {
1567 case _directoryMethodReadName: 1574 case _directoryMethodReadName:
1568 var response = _impl.read(_directoryReadResponseParamsFactory); 1575 var response = _impl.read(_directoryReadResponseParamsFactory);
1569 if (response is Future) { 1576 if (response is Future) {
1570 return response.then((response) { 1577 return response.then((response) {
1571 if (response != null) { 1578 if (response != null) {
1572 return buildResponseWithId( 1579 return buildResponseWithId(
1573 response, 1580 response,
1574 _directoryMethodReadName, 1581 _directoryMethodReadName,
1575 message.header.requestId, 1582 message.header.requestId,
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
1716 break; 1723 break;
1717 default: 1724 default:
1718 throw new bindings.MojoCodecError("Unexpected message name"); 1725 throw new bindings.MojoCodecError("Unexpected message name");
1719 break; 1726 break;
1720 } 1727 }
1721 return null; 1728 return null;
1722 } 1729 }
1723 1730
1724 Directory get impl => _impl; 1731 Directory get impl => _impl;
1725 set impl(Directory d) { 1732 set impl(Directory d) {
1726 assert(_impl == null); 1733 if (d == null) {
1734 throw new core.MojoApiError("$this: Cannot set a null implementation");
1735 }
1736 if (isBound && (_impl == null)) {
1737 beginHandlingEvents();
1738 }
1727 _impl = d; 1739 _impl = d;
1728 } 1740 }
1729 1741
1742 @override
1743 void bind(core.MojoMessagePipeEndpoint endpoint) {
1744 super.bind(endpoint);
1745 if (!isOpen && (_impl != null)) {
1746 beginHandlingEvents();
1747 }
1748 }
1749
1730 String toString() { 1750 String toString() {
1731 var superString = super.toString(); 1751 var superString = super.toString();
1732 return "DirectoryStub($superString)"; 1752 return "DirectoryStub($superString)";
1733 } 1753 }
1734 1754
1735 int get version => 0; 1755 int get version => 0;
1736 1756
1737 static service_describer.ServiceDescription _cachedServiceDescription; 1757 static service_describer.ServiceDescription _cachedServiceDescription;
1738 static service_describer.ServiceDescription get serviceDescription { 1758 static service_describer.ServiceDescription get serviceDescription {
1739 if (_cachedServiceDescription == null) { 1759 if (_cachedServiceDescription == null) {
1740 _cachedServiceDescription = new _DirectoryServiceDescription(); 1760 _cachedServiceDescription = new _DirectoryServiceDescription();
1741 } 1761 }
1742 return _cachedServiceDescription; 1762 return _cachedServiceDescription;
1743 } 1763 }
1744 } 1764 }
1745 1765
1746 1766
1747 1767
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698