Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 26cb681

Browse files
committed
Introduce method_channel.cc implementation file
1 parent 69e56a1 commit 26cb681

File tree

5 files changed

+65
-49
lines changed

5 files changed

+65
-49
lines changed

ci/licenses_golden/licenses_flutter

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4444,6 +4444,7 @@ ORIGIN: ../../../flutter/shell/platform/common/client_wrapper/include/flutter/st
44444444
ORIGIN: ../../../flutter/shell/platform/common/client_wrapper/include/flutter/standard_message_codec.h + ../../../flutter/LICENSE
44454445
ORIGIN: ../../../flutter/shell/platform/common/client_wrapper/include/flutter/standard_method_codec.h + ../../../flutter/LICENSE
44464446
ORIGIN: ../../../flutter/shell/platform/common/client_wrapper/include/flutter/texture_registrar.h + ../../../flutter/LICENSE
4447+
ORIGIN: ../../../flutter/shell/platform/common/client_wrapper/method_channel.cc + ../../../flutter/LICENSE
44474448
ORIGIN: ../../../flutter/shell/platform/common/client_wrapper/plugin_registrar.cc + ../../../flutter/LICENSE
44484449
ORIGIN: ../../../flutter/shell/platform/common/client_wrapper/standard_codec.cc + ../../../flutter/LICENSE
44494450
ORIGIN: ../../../flutter/shell/platform/common/client_wrapper/texture_registrar_impl.h + ../../../flutter/LICENSE
@@ -7244,6 +7245,7 @@ FILE: ../../../flutter/shell/platform/common/client_wrapper/include/flutter/stan
72447245
FILE: ../../../flutter/shell/platform/common/client_wrapper/include/flutter/standard_message_codec.h
72457246
FILE: ../../../flutter/shell/platform/common/client_wrapper/include/flutter/standard_method_codec.h
72467247
FILE: ../../../flutter/shell/platform/common/client_wrapper/include/flutter/texture_registrar.h
7248+
FILE: ../../../flutter/shell/platform/common/client_wrapper/method_channel.cc
72477249
FILE: ../../../flutter/shell/platform/common/client_wrapper/plugin_registrar.cc
72487250
FILE: ../../../flutter/shell/platform/common/client_wrapper/standard_codec.cc
72497251
FILE: ../../../flutter/shell/platform/common/client_wrapper/texture_registrar_impl.h

shell/platform/common/client_wrapper/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ executable("client_wrapper_unittests") {
4343
"encodable_value_unittests.cc",
4444
"event_channel_unittests.cc",
4545
"method_call_unittests.cc",
46+
"method_channel.cc",
4647
"method_channel_unittests.cc",
4748
"method_result_functions_unittests.cc",
4849
"plugin_registrar_unittests.cc",

shell/platform/common/client_wrapper/include/flutter/basic_message_channel.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,17 @@ class BasicMessageChannel {
106106
// to channels that aren't fully set up yet. For example, the engine isn't
107107
// running yet or the channel's message handler isn't set up on the Dart side
108108
// yet.
109-
void Resize(int new_size) { ResizeChannel(messenger_, name_, new_size); }
109+
void Resize(int new_size) {
110+
internal::ResizeChannel(messenger_, name_, new_size);
111+
}
110112

111113
// Defines whether the channel should show warning messages when discarding
112114
// messages due to overflow.
113115
//
114116
// When |warns| is false, the channel is expected to overflow and warning
115117
// messages will not be shown.
116118
void SetWarnsOnOverflow(bool warns) {
117-
SetChannelWarnsOnOverflow(messenger_, name_, warns);
119+
internal::SetChannelWarnsOnOverflow(messenger_, name_, warns);
118120
}
119121

120122
private:

shell/platform/common/client_wrapper/include/flutter/method_channel.h

Lines changed: 6 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@
1717

1818
namespace flutter {
1919

20-
namespace {
20+
namespace internal {
2121

2222
void ResizeChannel(BinaryMessenger* messenger, std::string name, int new_size);
2323

2424
void SetChannelWarnsOnOverflow(BinaryMessenger* messenger,
2525
std::string name,
2626
bool warns);
2727

28-
} // namespace
28+
} // namespace internal
2929

3030
class EncodableValue;
3131

@@ -137,15 +137,17 @@ class MethodChannel {
137137
// to channels that aren't fully set up yet. For example, the engine isn't
138138
// running yet or the channel's message handler isn't set up on the Dart side
139139
// yet.
140-
void Resize(int new_size) { ResizeChannel(messenger_, name_, new_size); }
140+
void Resize(int new_size) {
141+
internal::ResizeChannel(messenger_, name_, new_size);
142+
}
141143

142144
// Defines whether the channel should show warning messages when discarding
143145
// messages due to overflow.
144146
//
145147
// When |warns| is false, the channel is expected to overflow and warning
146148
// messages will not be shown.
147149
void SetWarnsOnOverflow(bool warns) {
148-
SetChannelWarnsOnOverflow(messenger_, name_, warns);
150+
internal::SetChannelWarnsOnOverflow(messenger_, name_, warns);
149151
}
150152

151153
private:
@@ -154,49 +156,6 @@ class MethodChannel {
154156
const MethodCodec<T>* codec_;
155157
};
156158

157-
namespace {
158-
159-
static constexpr char kControlChannelName[] = "dev.flutter/channel-buffers";
160-
static constexpr char kResizeMethod[] = "resize";
161-
static constexpr char kOverflowMethod[] = "overflow";
162-
163-
// Adjusts the number of messages that will get buffered when sending messages
164-
// to channels that aren't fully set up yet. For example, the engine isn't
165-
// running yet or the channel's message handler isn't set up on the Dart side
166-
// yet.
167-
void ResizeChannel(BinaryMessenger* messenger, std::string name, int new_size) {
168-
auto control_channel = std::make_unique<MethodChannel<EncodableValue>>(
169-
messenger, kControlChannelName, &StandardMethodCodec::GetInstance());
170-
171-
// The deserialization logic handles only 32 bits values, see
172-
// https://github.com/flutter/engine/blob/93e8901490e78c7ba7e319cce4470d9c6478c6dc/lib/ui/channel_buffers.dart#L495.
173-
control_channel->InvokeMethod(
174-
kResizeMethod, std::make_unique<EncodableValue>(EncodableList{
175-
EncodableValue(name),
176-
EncodableValue(static_cast<int32_t>(new_size)),
177-
}));
178-
}
179-
180-
// Defines whether the channel should show warning messages when discarding
181-
// messages due to overflow.
182-
//
183-
// When |warns| is false, the channel is expected to overflow and warning
184-
// messages will not be shown.
185-
void SetChannelWarnsOnOverflow(BinaryMessenger* messenger,
186-
std::string name,
187-
bool warns) {
188-
auto control_channel = std::make_unique<MethodChannel<EncodableValue>>(
189-
messenger, kControlChannelName, &StandardMethodCodec::GetInstance());
190-
191-
control_channel->InvokeMethod(kOverflowMethod,
192-
std::make_unique<EncodableValue>(EncodableList{
193-
EncodableValue(name),
194-
EncodableValue(!warns),
195-
}));
196-
}
197-
198-
} // namespace
199-
200159
} // namespace flutter
201160

202161
#endif // FLUTTER_SHELL_PLATFORM_COMMON_CLIENT_WRAPPER_INCLUDE_FLUTTER_METHOD_CHANNEL_H_
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#include "flutter/shell/platform/common/client_wrapper/include/flutter/method_channel.h"
6+
7+
namespace flutter {
8+
9+
namespace internal {
10+
11+
static constexpr char kControlChannelName[] = "dev.flutter/channel-buffers";
12+
static constexpr char kResizeMethod[] = "resize";
13+
static constexpr char kOverflowMethod[] = "overflow";
14+
15+
// Adjusts the number of messages that will get buffered when sending messages
16+
// to channels that aren't fully set up yet. For example, the engine isn't
17+
// running yet or the channel's message handler isn't set up on the Dart side
18+
// yet.
19+
void ResizeChannel(BinaryMessenger* messenger, std::string name, int new_size) {
20+
auto control_channel = std::make_unique<MethodChannel<EncodableValue>>(
21+
messenger, kControlChannelName, &StandardMethodCodec::GetInstance());
22+
23+
// The deserialization logic handles only 32 bits values, see
24+
// https://github.com/flutter/engine/blob/93e8901490e78c7ba7e319cce4470d9c6478c6dc/lib/ui/channel_buffers.dart#L495.
25+
control_channel->InvokeMethod(
26+
kResizeMethod, std::make_unique<EncodableValue>(EncodableList{
27+
EncodableValue(name),
28+
EncodableValue(static_cast<int32_t>(new_size)),
29+
}));
30+
}
31+
32+
// Defines whether the channel should show warning messages when discarding
33+
// messages due to overflow.
34+
//
35+
// When |warns| is false, the channel is expected to overflow and warning
36+
// messages will not be shown.
37+
void SetChannelWarnsOnOverflow(BinaryMessenger* messenger,
38+
std::string name,
39+
bool warns) {
40+
auto control_channel = std::make_unique<MethodChannel<EncodableValue>>(
41+
messenger, kControlChannelName, &StandardMethodCodec::GetInstance());
42+
43+
control_channel->InvokeMethod(kOverflowMethod,
44+
std::make_unique<EncodableValue>(EncodableList{
45+
EncodableValue(name),
46+
EncodableValue(!warns),
47+
}));
48+
}
49+
50+
} // namespace internal
51+
52+
} // namespace flutter

0 commit comments

Comments
 (0)