Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
ea082092
Unverified
Commit
ea082092
authored
Apr 20, 2020
by
Christian Mürtz
Committed by
GitHub
Apr 20, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use scheduleTask for adding licenses (#54493)
parent
34895351
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
74 additions
and
10 deletions
+74
-10
binding.dart
packages/flutter/lib/src/services/binding.dart
+5
-10
binding_test.dart
packages/flutter/test/services/binding_test.dart
+69
-0
No files found.
packages/flutter/lib/src/services/binding.dart
View file @
ea082092
...
...
@@ -89,12 +89,7 @@ mixin ServicesBinding on BindingBase, SchedulerBinding {
}
Stream
<
LicenseEntry
>
_addLicenses
()
async
*
{
// We use timers here (rather than scheduleTask from the scheduler binding)
// because the services layer can't use the scheduler binding (the scheduler
// binding uses the services layer to manage its lifecycle events). Timers
// are what scheduleTask uses under the hood anyway. The only difference is
// that these will just run next, instead of being prioritized relative to
// the other tasks that might be running. Using _something_ here to break
// Using _something_ here to break
// this into two parts is important because isolates take a while to copy
// data at the moment, and if we receive the data in the same event loop
// iteration as we send the data to the next isolate, we are definitely
...
...
@@ -105,14 +100,14 @@ mixin ServicesBinding on BindingBase, SchedulerBinding {
// https://github.com/dart-lang/sdk/issues/31960
// TODO(ianh): Remove this complexity once these bugs are fixed.
final
Completer
<
String
>
rawLicenses
=
Completer
<
String
>();
Timer
.
run
(()
async
{
scheduleTask
(()
async
{
rawLicenses
.
complete
(
rootBundle
.
loadString
(
'LICENSE'
,
cache:
false
));
});
}
,
Priority
.
animation
);
await
rawLicenses
.
future
;
final
Completer
<
List
<
LicenseEntry
>>
parsedLicenses
=
Completer
<
List
<
LicenseEntry
>>();
Timer
.
run
(()
async
{
scheduleTask
(()
async
{
parsedLicenses
.
complete
(
compute
(
_parseLicenses
,
await
rawLicenses
.
future
,
debugLabel:
'parseLicenses'
));
});
}
,
Priority
.
animation
);
await
parsedLicenses
.
future
;
yield
*
Stream
<
LicenseEntry
>.
fromIterable
(
await
parsedLicenses
.
future
);
}
...
...
packages/flutter/test/services/binding_test.dart
0 → 100644
View file @
ea082092
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'dart:typed_data'
;
import
'package:flutter/foundation.dart'
;
import
'package:flutter/scheduler.dart'
;
import
'package:flutter/services.dart'
;
import
'package:flutter/src/services/binding.dart'
;
import
'package:flutter_test/flutter_test.dart'
;
const
String
license1
=
'''
L1Package1
L1Package2
L1Package3
L1Paragraph1
L1Paragraph2
L1Paragraph3'''
;
const
String
license2
=
'''
L2Package1
L2Package2
L2Package3
L2Paragraph1
L2Paragraph2
L2Paragraph3'''
;
const
String
licenses
=
'''
$license1
--------------------------------------------------------------------------------
$license2
'''
;
class
TestBinding
extends
BindingBase
with
SchedulerBinding
,
ServicesBinding
{
@override
BinaryMessenger
createBinaryMessenger
()
{
return
super
.
createBinaryMessenger
()
..
setMockMessageHandler
(
'flutter/assets'
,
(
ByteData
message
)
async
{
if
(
const
StringCodec
().
decodeMessage
(
message
)
==
'LICENSE'
)
{
return
const
StringCodec
().
encodeMessage
(
licenses
);
}
return
null
;
});
}
}
void
main
(
)
{
test
(
'Adds rootBundle LICENSES to LicenseRegistry'
,
()
async
{
TestBinding
();
// The test binding registers a mock handler that returns licenses for the LICENSE key
final
List
<
LicenseEntry
>
licenses
=
await
LicenseRegistry
.
licenses
.
toList
();
expect
(
licenses
[
0
].
packages
,
equals
(<
String
>[
'L1Package1'
,
'L1Package2'
,
'L1Package3'
]));
expect
(
licenses
[
0
].
paragraphs
.
map
((
LicenseParagraph
p
)
=>
p
.
text
),
equals
(<
String
>[
'L1Paragraph1'
,
'L1Paragraph2'
,
'L1Paragraph3'
]));
expect
(
licenses
[
1
].
packages
,
equals
(<
String
>[
'L2Package1'
,
'L2Package2'
,
'L2Package3'
]));
expect
(
licenses
[
1
].
paragraphs
.
map
((
LicenseParagraph
p
)
=>
p
.
text
),
equals
(<
String
>[
'L2Paragraph1'
,
'L2Paragraph2'
,
'L2Paragraph3'
]));
});
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment