17
17
18
18
namespace flutter {
19
19
20
- static constexpr char kControlChannelName [] = " dev.flutter/channel-buffers" ;
21
- static constexpr char kResizeMethod [] = " resize" ;
22
- static constexpr char kOverflowMethod [] = " overflow" ;
23
-
24
20
class EncodableValue ;
25
21
26
22
// A handler for receiving a method call from the Flutter engine.
@@ -131,35 +127,15 @@ class MethodChannel {
131
127
// to channels that aren't fully set up yet. For example, the engine isn't
132
128
// running yet or the channel's message handler isn't set up on the Dart side
133
129
// yet.
134
- //
135
- // |new_size] is an int because the deserialization logic handles only 32 bits
136
- // values, see
137
- // https://github.com/flutter/engine/blob/93e8901490e78c7ba7e319cce4470d9c6478c6dc/lib/ui/channel_buffers.dart#L495.
138
- void Resize (int new_size) {
139
- auto control_channel = std::make_unique<MethodChannel<EncodableValue>>(
140
- messenger_, kControlChannelName , &StandardMethodCodec::GetInstance ());
141
-
142
- control_channel->InvokeMethod (
143
- kResizeMethod , std::make_unique<EncodableValue>(EncodableList{
144
- EncodableValue (name_),
145
- EncodableValue (new_size),
146
- }));
147
- }
130
+ void Resize (int new_size) { ResizeChannel (messenger_, name_, new_size); }
148
131
149
132
// Defines whether the channel should show warning messages when discarding
150
133
// messages due to overflow.
151
134
//
152
135
// When |warns| is false, the channel is expected to overflow and warning
153
136
// messages will not be shown.
154
137
void SetWarnsOnOverflow (bool warns) {
155
- auto control_channel = std::make_unique<MethodChannel<EncodableValue>>(
156
- messenger_, kControlChannelName , &StandardMethodCodec::GetInstance ());
157
-
158
- control_channel->InvokeMethod (
159
- kOverflowMethod , std::make_unique<EncodableValue>(EncodableList{
160
- EncodableValue (name_),
161
- EncodableValue (!warns),
162
- }));
138
+ SetChannelWarnsOnOverflow (messenger_, name_, warns);
163
139
}
164
140
165
141
private:
@@ -168,6 +144,49 @@ class MethodChannel {
168
144
const MethodCodec<T>* codec_;
169
145
};
170
146
147
+ namespace {
148
+
149
+ static constexpr char kControlChannelName [] = " dev.flutter/channel-buffers" ;
150
+ static constexpr char kResizeMethod [] = " resize" ;
151
+ static constexpr char kOverflowMethod [] = " overflow" ;
152
+
153
+ // Adjusts the number of messages that will get buffered when sending messages
154
+ // to channels that aren't fully set up yet. For example, the engine isn't
155
+ // running yet or the channel's message handler isn't set up on the Dart side
156
+ // yet.
157
+ void ResizeChannel (BinaryMessenger* messenger, std::string name, int new_size) {
158
+ auto control_channel = std::make_unique<MethodChannel<EncodableValue>>(
159
+ messenger, kControlChannelName , &StandardMethodCodec::GetInstance ());
160
+
161
+ // The deserialization logic handles only 32 bits values, see
162
+ // https://github.com/flutter/engine/blob/93e8901490e78c7ba7e319cce4470d9c6478c6dc/lib/ui/channel_buffers.dart#L495.
163
+ control_channel->InvokeMethod (
164
+ kResizeMethod , std::make_unique<EncodableValue>(EncodableList{
165
+ EncodableValue (name),
166
+ EncodableValue (static_cast <int32_t >(new_size)),
167
+ }));
168
+ }
169
+
170
+ // Defines whether the channel should show warning messages when discarding
171
+ // messages due to overflow.
172
+ //
173
+ // When |warns| is false, the channel is expected to overflow and warning
174
+ // messages will not be shown.
175
+ void SetChannelWarnsOnOverflow (BinaryMessenger* messenger,
176
+ std::string name,
177
+ bool warns) {
178
+ auto control_channel = std::make_unique<MethodChannel<EncodableValue>>(
179
+ messenger, kControlChannelName , &StandardMethodCodec::GetInstance ());
180
+
181
+ control_channel->InvokeMethod (kOverflowMethod ,
182
+ std::make_unique<EncodableValue>(EncodableList{
183
+ EncodableValue (name),
184
+ EncodableValue (!warns),
185
+ }));
186
+ }
187
+
188
+ } // namespace
189
+
171
190
} // namespace flutter
172
191
173
192
#endif // FLUTTER_SHELL_PLATFORM_COMMON_CLIENT_WRAPPER_INCLUDE_FLUTTER_METHOD_CHANNEL_H_
0 commit comments