Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
eaae468
add changed files
bparrishMines Feb 22, 2023
9d90d9f
some more changes
bparrishMines Feb 23, 2023
1094620
update tests
bparrishMines Feb 23, 2023
ce1634c
fix tests
bparrishMines Feb 23, 2023
3fae384
Merge branch 'main' of github.com:flutter/packages into instance_mana…
bparrishMines Feb 23, 2023
44e6f81
update instancemanager
bparrishMines Feb 23, 2023
ce6550b
ensure callback methods are passed to copy
bparrishMines Feb 23, 2023
def8956
version bump
bparrishMines Feb 23, 2023
ca9993e
update tests since objects can't be added multiple times
bparrishMines Feb 23, 2023
1408d00
Merge branch 'main' of github.com:flutter/packages into instance_mana…
bparrishMines Feb 27, 2023
1c48779
fix test
bparrishMines Feb 28, 2023
a552de9
change back to using copyable
bparrishMines Feb 28, 2023
9d58bd8
probably fix tests
bparrishMines Feb 28, 2023
2a05f7c
some reverts
bparrishMines Feb 28, 2023
73ea794
update changelog
bparrishMines Feb 28, 2023
625146d
Merge branch 'main' of github.com:flutter/packages into instance_mana…
bparrishMines Feb 28, 2023
32ff598
add a copy
bparrishMines Feb 28, 2023
b848c1f
raise minimum meta version
bparrishMines Feb 28, 2023
8efddc9
remove meta
bparrishMines Feb 28, 2023
e2b53b1
remove copy override
bparrishMines Feb 28, 2023
a9a9aa6
remove print
bparrishMines Feb 28, 2023
0ea91f7
remove unneeded changes
bparrishMines Feb 28, 2023
8141e9a
include raising of pigeon version
bparrishMines Feb 28, 2023
4a5aab1
Merge branch 'main' of github.com:flutter/packages into instance_mana…
bparrishMines Mar 6, 2023
f196771
update globalInstanceManager
bparrishMines Mar 6, 2023
7e32787
move location of asserts
bparrishMines Mar 6, 2023
9b572e2
Merge branch 'main' of github.com:flutter/packages into instance_mana…
bparrishMines Mar 9, 2023
1062ddb
lint
bparrishMines Mar 9, 2023
9605570
use a constant
bparrishMines Mar 16, 2023
d786495
Merge branch 'main' of github.com:flutter/packages into instance_mana…
bparrishMines Mar 16, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
use a constant
  • Loading branch information
bparrishMines committed Mar 16, 2023
commit 96055701d6bb6f733a081d022054343b0d377a36
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
*/
@SuppressWarnings("unchecked")
public class InstanceManager {
/// Constant returned from #addHostCreatedInstance() if the manager is closed.
public static final int INSTANCE_CLOSED = -1;

// Identifiers are locked to a specific range to avoid collisions with objects
// created simultaneously from Dart.
// Host uses identifiers >= 2^16 and Dart is expected to use values n where,
Expand Down Expand Up @@ -87,8 +90,7 @@ private InstanceManager(FinalizationListener finalizationListener) {
*/
@Nullable
public <T> T remove(long identifier) {
if (isClosed()) {
Log.w(TAG, CLOSED_WARNING);
if (assertNotClosed()) {
return null;
}
return (T) strongInstances.remove(identifier);
Expand All @@ -112,8 +114,7 @@ public <T> T remove(long identifier) {
*/
@Nullable
public Long getIdentifierForStrongReference(Object instance) {
if (isClosed()) {
Log.w(TAG, CLOSED_WARNING);
if (assertNotClosed()) {
return null;
}
final Long identifier = identifiers.get(instance);
Expand All @@ -137,8 +138,7 @@ public Long getIdentifierForStrongReference(Object instance) {
* unique.
*/
public void addDartCreatedInstance(Object instance, long identifier) {
if (isClosed()) {
Log.w(TAG, CLOSED_WARNING);
if (assertNotClosed()) {
return;
}
addInstance(instance, identifier);
Expand All @@ -149,12 +149,14 @@ public void addDartCreatedInstance(Object instance, long identifier) {
*
* @param instance the instance to be stored. This must be unique to all other added instances.
* @return the unique identifier stored with instance. If the manager is closed, returns -1.
* Otherwise, returns a value >= 0.
*/
public long addHostCreatedInstance(Object instance) {
if (isClosed()) {
Log.w(TAG, CLOSED_WARNING);
return -1;
} else if (containsInstance(instance)) {
if (assertNotClosed()) {
return INSTANCE_CLOSED;
}

if (containsInstance(instance)) {
throw new IllegalArgumentException(
String.format("Instance of `%s` has already been added.", instance.getClass()));
}
Expand All @@ -173,10 +175,10 @@ public long addHostCreatedInstance(Object instance) {
*/
@Nullable
public <T> T getInstance(long identifier) {
if (isClosed()) {
Log.w(TAG, CLOSED_WARNING);
if (assertNotClosed()) {
return null;
}

final WeakReference<T> instance = (WeakReference<T>) weakInstances.get(identifier);
if (instance != null) {
return instance.get();
Expand All @@ -192,8 +194,7 @@ public <T> T getInstance(long identifier) {
* `false`.
*/
public boolean containsInstance(Object instance) {
if (isClosed()) {
Log.w(TAG, CLOSED_WARNING);
if (assertNotClosed()) {
return false;
}
return identifiers.containsKey(instance);
Expand Down Expand Up @@ -259,4 +260,12 @@ private void addInstance(Object instance, long identifier) {
weakReferencesToIdentifiers.put(weakReference, identifier);
strongInstances.put(identifier, instance);
}

private boolean assertNotClosed() {
if (isClosed()) {
Log.w(TAG, CLOSED_WARNING);
return true;
}
return false;
}
}