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

Conversation

@chinmaygarde
Copy link
Contributor

return LOG_EMBEDDER_ERROR(kInvalidArguments);
}

flutter::EmbedderPlatformMessageResponse::Callback response =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it naming this "response_callback" would make it a bit more clear since this is just the callback, not the whole response.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


auto handle = new FlutterPlatformMessageResponseHandle();
handle->message = fml::MakeRefCounted<flutter::PlatformMessage>(
"", fml::MakeRefCounted<flutter::EmbedderPlatformMessageResponse>(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to add a comment explaining why we are sending an empty channel, or is that obvious?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

return kSuccess;
}

FLUTTER_EXPORT
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


namespace flutter {

class EmbedderPlatformMessageResponse : public PlatformMessageResponse {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add class definition documentation?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.



@pragma('vm:entry-point')
void platform_messages_response() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these messages have documentation relating to the tests using them?

kill_latch.Wait();
}

TEST_F(EmbedderTest, ShouldBeAbleToCreateAndCollectCallbacks) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this test be called CanCreateAndCollectcallbacks, for consistency with the test PlatformMessagesCanReceiveResponse below?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

kill_latch.Wait();
}

TEST_F(EmbedderTest, ShouldBeAbleToCreateAndCollectCallbacks) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion for this and future tests: We should have a brief comment explaining what the test does.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

return LOG_EMBEDDER_ERROR(kInvalidArguments);
}

auto response_handle = SAFE_ACCESS(flutter_message, response_handle, nullptr);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer auto* to auto here. (I'd actually suggest FlutterPlatformMessageResponseHandle* since I don't think the type is obvious in immediate context, and it's used in a way other than just passing off to something else, so this is a case where the guide prefers explicit type).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair point. Done.

FlutterEngine engine,
const FlutterPlatformMessage* message);

// Create a platform message response handle that allows the embedder to set a
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/Create/Creates/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


// Create a platform message response handle that allows the embedder to set a
// native callback for a response to a message. This handle may be set on the
// |response_handle| field of any |FlutterPlatformMessage|. The handle must be
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/any |FlutterPlatformMessage|/any |FlutterPlatformMessage| sent to the engine/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

// Create a platform message response handle that allows the embedder to set a
// native callback for a response to a message. This handle may be set on the
// |response_handle| field of any |FlutterPlatformMessage|. The handle must be
// collected via a call to |FlutterPlatformMessageReleaseResponseHandle|. This
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not clear to me why we need this step; why not just do the cleanup internally, and make it an error not to send the message?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The memory management is cleaner and more explicit than deleting objects in obscure struct fields on specific calls that don't even operate on that object directly. I strongly think this makes the lifecycle of these resources easier to reason about.

void* user_data,
FlutterPlatformMessageResponseHandle** response_out);

// Collect the handle created using
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/Collect/Collects/ (if this function is kept)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Contributor Author

@chinmaygarde chinmaygarde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed all PR comments.

return LOG_EMBEDDER_ERROR(kInvalidArguments);
}

auto response_handle = SAFE_ACCESS(flutter_message, response_handle, nullptr);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair point. Done.

return LOG_EMBEDDER_ERROR(kInvalidArguments);
}

flutter::EmbedderPlatformMessageResponse::Callback response =
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


auto handle = new FlutterPlatformMessageResponseHandle();
handle->message = fml::MakeRefCounted<flutter::PlatformMessage>(
"", fml::MakeRefCounted<flutter::EmbedderPlatformMessageResponse>(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

return kSuccess;
}

FLUTTER_EXPORT
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

// Create a platform message response handle that allows the embedder to set a
// native callback for a response to a message. This handle may be set on the
// |response_handle| field of any |FlutterPlatformMessage|. The handle must be
// collected via a call to |FlutterPlatformMessageReleaseResponseHandle|. This
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The memory management is cleaner and more explicit than deleting objects in obscure struct fields on specific calls that don't even operate on that object directly. I strongly think this makes the lifecycle of these resources easier to reason about.

void* user_data,
FlutterPlatformMessageResponseHandle** response_out);

// Collect the handle created using
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


namespace flutter {

class EmbedderPlatformMessageResponse : public PlatformMessageResponse {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

kill_latch.Wait();
}

TEST_F(EmbedderTest, ShouldBeAbleToCreateAndCollectCallbacks) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

kill_latch.Wait();
}

TEST_F(EmbedderTest, ShouldBeAbleToCreateAndCollectCallbacks) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Contributor

@stuartmorgan-g stuartmorgan-g left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with some nits and one API type question.


//----------------------------------------------------------------------------
/// @brief Destroys the message response. Can be called on any thread.
/// Does no execute unfulfilled callbacks.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: no->not

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

//----------------------------------------------------------------------------
/// @brief Destroys the message response. Can be called on any thread.
/// Does no execute unfulfilled callbacks.
///
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: remove blank comment line.

// Creates a platform message response handle that allows the embedder to set a
// native callback for a response to a message. This handle may be set on the
// |response_handle| field of any |FlutterPlatformMessage| sent to the engine.
// The handle must be collected via a call to
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: consider adding a blank line above this, and another before the "The user data baton [...]" to break this long comment up into different conceptual sections (overview, memory management, argument details).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. At some point, we should move over to using doxygen style header docs too.

const FlutterPlatformMessage* /* message*/,
void* /* user data */);

typedef void (*FlutterDataCallback)(const void* /* data */,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missed this before: why is data a void* rather than a uint8_t* like the data in a message and the data in a response going the other way? It seems like an odd/confusing mismatch.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, it should be uint8_t*. Updated. Ditto for EmbedderPlatformMessageResponse::Callback.

@chinmaygarde chinmaygarde force-pushed the platform_message_response branch from a06c665 to c2bfb97 Compare July 3, 2019 22:01
Copy link
Contributor Author

@chinmaygarde chinmaygarde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed all comments.

const FlutterPlatformMessage* /* message*/,
void* /* user data */);

typedef void (*FlutterDataCallback)(const void* /* data */,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, it should be uint8_t*. Updated. Ditto for EmbedderPlatformMessageResponse::Callback.

// Creates a platform message response handle that allows the embedder to set a
// native callback for a response to a message. This handle may be set on the
// |response_handle| field of any |FlutterPlatformMessage| sent to the engine.
// The handle must be collected via a call to
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. At some point, we should move over to using doxygen style header docs too.


//----------------------------------------------------------------------------
/// @brief Destroys the message response. Can be called on any thread.
/// Does no execute unfulfilled callbacks.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@chinmaygarde chinmaygarde merged commit b84f89b into flutter:master Jul 3, 2019
@chinmaygarde chinmaygarde deleted the platform_message_response branch July 3, 2019 22:44
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jul 3, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jul 4, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jul 4, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jul 4, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jul 4, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jul 4, 2019
engine-flutter-autoroll added a commit to flutter/flutter that referenced this pull request Jul 4, 2019
flutter/engine@7d3e722...3c51a7b

git log 7d3e722..3c51a7b --no-merges --oneline
3c51a7b Roll src/third_party/skia 11eb847a2080..857c9f955edb (2 commits) (flutter/engine#9676)
7f828dd Raster now returns an enum rather than boolean (flutter/engine#9661)
11b6afe  Roll src/third_party/dart 67ab3be10d...b5aeaa6796 (flutter/engine#9675)
3c4dbe2 Revert &#34; Roll src/third_party/dart 67ab3be10d...43891316ca (#9670)&#34; (flutter/engine#9673)
5e596f2  Roll src/third_party/dart 67ab3be10d...43891316ca (flutter/engine#9670)
46a2239 Roll src/third_party/skia 5b52c52141ac..11eb847a2080 (6 commits) (flutter/engine#9671)
b84f89b Allow embedders to add callbacks for responses to platform messages from the framework. (flutter/engine#9655)
8dac2e9 Begin separating macOS engine from view controller (flutter/engine#9654)
d3616c7 Roll src/third_party/skia 0e0113dcbd9a..5b52c52141ac (8 commits) (flutter/engine#9665)
cea2c36 Mutators Stack refactoring (flutter/engine#9663)
6a8782f Roll src/third_party/skia 93eeff578b08..0e0113dcbd9a (9 commits) (flutter/engine#9662)
791143f ExternalViewEmbedder can CancelFrame after pre-roll (flutter/engine#9660)
d637f29 External view embedder can tell if embedded views have mutated (flutter/engine#9653)
ceee3d7 Roll src/third_party/skia 38ae3f42fec1..93eeff578b08 (1 commits) (flutter/engine#9659)
d757290 Roll src/third_party/skia febc162c7898..38ae3f42fec1 (3 commits) (flutter/engine#9658)
58133ab Roll src/third_party/skia 3de5c6388142..febc162c7898 (2 commits) (flutter/engine#9657)
29342dd Roll src/third_party/skia 1e2cb444e0c1..3de5c6388142 (8 commits) (flutter/engine#9656)
b547356 Pipeline allows continuations that can produce to front (flutter/engine#9652)
8306ee6 Move the mutators stack handling to preroll (flutter/engine#9651)
511b9f2 Roll src/third_party/skia 215ff3325230..1e2cb444e0c1 (12 commits) (flutter/engine#9650)

The AutoRoll server is located here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+/master/autoroll/README.md

If the roll is causing failures, please contact the current sheriff (jsimmons@google.com), and stop
the roller if necessary.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Embedder API should support receiving responses from messages

4 participants