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

Unified Diff: mojo/public/dart/mojo/lib/src/drain_data.dart

Issue 1441033002: Move mojo and mojom from mojo/public/dart to mojo/dart/packages (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/public/dart/mojo/lib/src/data_pipe.dart ('k') | mojo/public/dart/mojo/lib/src/enum.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/dart/mojo/lib/src/drain_data.dart
diff --git a/mojo/public/dart/mojo/lib/src/drain_data.dart b/mojo/public/dart/mojo/lib/src/drain_data.dart
deleted file mode 100644
index dc630bfbdc7c1a2fc73b72023bcebd4af8a2fe6a..0000000000000000000000000000000000000000
--- a/mojo/public/dart/mojo/lib/src/drain_data.dart
+++ /dev/null
@@ -1,72 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-part of core;
-
-class DataPipeDrainer {
- MojoDataPipeConsumer _consumer;
- MojoEventSubscription _eventSubscription;
- List<ByteData> _dataList;
- int _dataSize;
-
- DataPipeDrainer(this._consumer) {
- _eventSubscription = new MojoEventSubscription(_consumer.handle);
- _dataList = new List();
- _dataSize = 0;
- }
-
- ByteData _copy(ByteData byteData) => new ByteData.view(
- new Uint8List.fromList(byteData.buffer.asUint8List()).buffer);
-
- MojoResult _doRead() {
- ByteData thisRead = _consumer.beginRead();
- if (thisRead == null) {
- throw 'Data pipe beginRead failed: ${_consumer.status}';
- }
- _dataList.add(_copy(thisRead));
- _dataSize += thisRead.lengthInBytes;
- return _consumer.endRead(thisRead.lengthInBytes);
- }
-
- ByteData _concatData() {
- var data = new ByteData(_dataSize);
- int end = 0;
- for (var chunk in _dataList) {
- data.buffer
- .asUint8List()
- .setRange(end, end + chunk.lengthInBytes, chunk.buffer.asUint8List());
- end += chunk.lengthInBytes;
- }
- return data;
- }
-
- Future<ByteData> drain() {
- var completer = new Completer();
- _eventSubscription.subscribe((List<int> event) {
- var mojoSignals = new MojoHandleSignals(event[1]);
- if (mojoSignals.isReadable) {
- var result = _doRead();
- if (!result.isOk) {
- _eventSubscription.close();
- _eventSubscription = null;
- completer.complete(_concatData());
- } else {
- _eventSubscription.enableReadEvents();
- }
- } else if (mojoSignals.isPeerClosed) {
- _eventSubscription.close();
- _eventSubscription = null;
- completer.complete(_concatData());
- } else {
- throw 'Unexpected handle event: $mojoSignals';
- }
- });
- return completer.future;
- }
-
- static Future<ByteData> drainHandle(MojoDataPipeConsumer consumer) {
- var drainer = new DataPipeDrainer(consumer);
- return drainer.drain();
- }
-}
« no previous file with comments | « mojo/public/dart/mojo/lib/src/data_pipe.dart ('k') | mojo/public/dart/mojo/lib/src/enum.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698