Skip to content

Commit

Permalink
follow-up and use more ChannelOwnerBase
Browse files Browse the repository at this point in the history
  • Loading branch information
mxschmitt committed Dec 9, 2023
1 parent fc77be3 commit ab23a98
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 12 deletions.
9 changes: 4 additions & 5 deletions src/Playwright/Transport/ChannelOwnerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace Microsoft.Playwright.Transport;
internal class ChannelOwnerBase : IChannelOwner
{
internal readonly Connection _connection;
private readonly ConcurrentDictionary<string, IChannelOwner> _objects = new();
private readonly ConcurrentDictionary<string, ChannelOwnerBase> _objects = new();
internal bool _wasCollected;

internal ChannelOwnerBase(IChannelOwner parent, string guid) : this(parent, null, guid)
Expand Down Expand Up @@ -64,7 +64,7 @@ internal ChannelOwnerBase(IChannelOwner parent, Connection connection, string gu
ChannelBase IChannelOwner.Channel => null;

/// <inheritdoc/>
ConcurrentDictionary<string, IChannelOwner> IChannelOwner.Objects => _objects;
ConcurrentDictionary<string, ChannelOwnerBase> IChannelOwner.Objects => _objects;

internal string Guid { get; set; }

Expand All @@ -74,15 +74,14 @@ internal virtual void OnMessage(string method, JsonElement? serverParams)
{
}

void IChannelOwner.Adopt(ChannelOwnerBase child)
internal void Adopt(ChannelOwnerBase child)
{
child.Parent.Objects.TryRemove(child.Guid, out _);
_objects[child.Guid] = child;
child.Parent = this;
}

/// <inheritdoc/>
void IChannelOwner.DisposeOwner(string reason)
internal void DisposeOwner(string reason)
{
Parent?.Objects?.TryRemove(Guid, out var _);
_connection?.Objects.TryRemove(Guid, out var _);
Expand Down
6 changes: 1 addition & 5 deletions src/Playwright/Transport/Channels/IChannelOwner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,7 @@ internal interface IChannelOwner
/// <summary>
/// Child objects.
/// </summary>
ConcurrentDictionary<string, IChannelOwner> Objects { get; }

void DisposeOwner(string reason);

void Adopt(ChannelOwnerBase child);
ConcurrentDictionary<string, ChannelOwnerBase> Objects { get; }

Task<T> WrapApiCallAsync<T>(Func<Task<T>> action, bool isInternal = false);

Expand Down
4 changes: 2 additions & 2 deletions src/Playwright/Transport/Connection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ JsonSerializerOptions NewJsonSerializerOptions(bool keepNulls)

internal event EventHandler<Exception> Close;

public ConcurrentDictionary<string, IChannelOwner> Objects { get; } = new();
public ConcurrentDictionary<string, ChannelOwnerBase> Objects { get; } = new();

internal AsyncLocal<List<ApiZone>> ApiZone { get; } = new();

Expand Down Expand Up @@ -305,7 +305,7 @@ internal void Dispatch(PlaywrightServerMessage message)
@object.DisposeOwner(message.Params.Value.TryGetProperty("reason", out var reason) ? reason.GetString() : null);
return;
}
((ChannelOwnerBase)@object).OnMessage(message.Method, message.Params);
@object.OnMessage(message.Method, message.Params);
}
catch (Exception ex)
{
Expand Down

0 comments on commit ab23a98

Please sign in to comment.