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

Commit c6e9fe9

Browse files
committed
Move helper functions to core_implementations.cc
1 parent 308cda2 commit c6e9fe9

File tree

3 files changed

+71
-59
lines changed

3 files changed

+71
-59
lines changed

shell/platform/common/client_wrapper/core_implementations.cc

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
#include "binary_messenger_impl.h"
2121
#include "include/flutter/engine_method_result.h"
22+
#include "include/flutter/method_channel.h"
23+
#include "include/flutter/standard_method_codec.h"
2224
#include "texture_registrar_impl.h"
2325

2426
namespace flutter {
@@ -164,6 +166,46 @@ void ReplyManager::SendResponseData(const std::vector<uint8_t>* data) {
164166

165167
} // namespace internal
166168

169+
// ========== method_channel.h ==========
170+
171+
namespace {
172+
173+
constexpr char kControlChannelName[] = "dev.flutter/channel-buffers";
174+
constexpr char kResizeMethod[] = "resize";
175+
constexpr char kOverflowMethod[] = "overflow";
176+
177+
} // namespace
178+
179+
namespace internal {
180+
181+
void ResizeChannel(BinaryMessenger* messenger, std::string name, int new_size) {
182+
auto control_channel = std::make_unique<MethodChannel<EncodableValue>>(
183+
messenger, kControlChannelName, &StandardMethodCodec::GetInstance());
184+
185+
// The deserialization logic handles only 32 bits values, see
186+
// https://github.com/flutter/engine/blob/93e8901490e78c7ba7e319cce4470d9c6478c6dc/lib/ui/channel_buffers.dart#L495.
187+
control_channel->InvokeMethod(
188+
kResizeMethod, std::make_unique<EncodableValue>(EncodableList{
189+
EncodableValue(name),
190+
EncodableValue(static_cast<int32_t>(new_size)),
191+
}));
192+
}
193+
194+
void SetChannelWarnsOnOverflow(BinaryMessenger* messenger,
195+
std::string name,
196+
bool warns) {
197+
auto control_channel = std::make_unique<MethodChannel<EncodableValue>>(
198+
messenger, kControlChannelName, &StandardMethodCodec::GetInstance());
199+
200+
control_channel->InvokeMethod(kOverflowMethod,
201+
std::make_unique<EncodableValue>(EncodableList{
202+
EncodableValue(name),
203+
EncodableValue(!warns),
204+
}));
205+
}
206+
207+
} // namespace internal
208+
167209
// ========== texture_registrar_impl.h ==========
168210

169211
TextureRegistrarImpl::TextureRegistrarImpl(

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

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,29 @@
1111

1212
#include "binary_messenger.h"
1313
#include "message_codec.h"
14-
#include "method_channel.h"
1514

1615
namespace flutter {
1716

17+
namespace internal {
18+
// Internal helper functions used by BasicMessageChannel and MethodChannel.
19+
20+
// Adjusts the number of messages that will get buffered when sending messages
21+
// to channels that aren't fully set up yet. For example, the engine isn't
22+
// running yet or the channel's message handler isn't set up on the Dart side
23+
// yet.
24+
void ResizeChannel(BinaryMessenger* messenger, std::string name, int new_size);
25+
26+
// Defines whether the channel should show warning messages when discarding
27+
// messages due to overflow.
28+
//
29+
// When |warns| is false, the channel is expected to overflow and warning
30+
// messages will not be shown.
31+
void SetChannelWarnsOnOverflow(BinaryMessenger* messenger,
32+
std::string name,
33+
bool warns);
34+
35+
} // namespace internal
36+
1837
class EncodableValue;
1938

2039
// A message reply callback.
@@ -106,15 +125,17 @@ class BasicMessageChannel {
106125
// to channels that aren't fully set up yet. For example, the engine isn't
107126
// running yet or the channel's message handler isn't set up on the Dart side
108127
// yet.
109-
void Resize(int new_size) { ResizeChannel(messenger_, name_, new_size); }
128+
void Resize(int new_size) {
129+
internal::ResizeChannel(messenger_, name_, new_size);
130+
}
110131

111132
// Defines whether the channel should show warning messages when discarding
112133
// messages due to overflow.
113134
//
114135
// When |warns| is false, the channel is expected to overflow and warning
115136
// messages will not be shown.
116137
void SetWarnsOnOverflow(bool warns) {
117-
SetChannelWarnsOnOverflow(messenger_, name_, warns);
138+
internal::SetChannelWarnsOnOverflow(messenger_, name_, warns);
118139
}
119140

120141
private:

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

Lines changed: 5 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,15 @@
88
#include <iostream>
99
#include <string>
1010

11+
#include "basic_message_channel.h"
1112
#include "binary_messenger.h"
1213
#include "engine_method_result.h"
1314
#include "method_call.h"
1415
#include "method_codec.h"
1516
#include "method_result.h"
16-
#include "standard_method_codec.h"
1717

1818
namespace flutter {
1919

20-
namespace {
21-
22-
void ResizeChannel(BinaryMessenger* messenger, std::string name, int new_size);
23-
24-
void SetChannelWarnsOnOverflow(BinaryMessenger* messenger,
25-
std::string name,
26-
bool warns);
27-
28-
} // namespace
29-
3020
class EncodableValue;
3121

3222
// A handler for receiving a method call from the Flutter engine.
@@ -137,15 +127,17 @@ class MethodChannel {
137127
// to channels that aren't fully set up yet. For example, the engine isn't
138128
// running yet or the channel's message handler isn't set up on the Dart side
139129
// yet.
140-
void Resize(int new_size) { ResizeChannel(messenger_, name_, new_size); }
130+
void Resize(int new_size) {
131+
internal::ResizeChannel(messenger_, name_, new_size);
132+
}
141133

142134
// Defines whether the channel should show warning messages when discarding
143135
// messages due to overflow.
144136
//
145137
// When |warns| is false, the channel is expected to overflow and warning
146138
// messages will not be shown.
147139
void SetWarnsOnOverflow(bool warns) {
148-
SetChannelWarnsOnOverflow(messenger_, name_, warns);
140+
internal::SetChannelWarnsOnOverflow(messenger_, name_, warns);
149141
}
150142

151143
private:
@@ -154,49 +146,6 @@ class MethodChannel {
154146
const MethodCodec<T>* codec_;
155147
};
156148

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-
200149
} // namespace flutter
201150

202151
#endif // FLUTTER_SHELL_PLATFORM_COMMON_CLIENT_WRAPPER_INCLUDE_FLUTTER_METHOD_CHANNEL_H_

0 commit comments

Comments
 (0)