Title: [287125] trunk/Source/WebKit
Revision
287125
Author
[email protected]
Date
2021-12-15 20:33:12 -0800 (Wed, 15 Dec 2021)

Log Message

Some webpushtool improvements.
https://bugs.webkit.org/show_bug.cgi?id=234372

Reviewed by Alex Christensen.

- Make the list of current connections be reliably ordered
- If the invocation is solely about injecting a push message, exit afterwards
- Some other tiny niceties

* webpushd/WebPushDaemon.mm:
(WebPushD::Daemon::broadcastAllConnectionIdentities):
(WebPushD::Daemon::injectPushMessageForTesting):

* webpushd/webpushtool/WebPushToolConnection.h:
* webpushd/webpushtool/WebPushToolConnection.mm:
(WebPushTool::Connection::create):
(WebPushTool::Connection::Connection):
(WebPushTool::Connection::connectToService):
(WebPushTool::Connection::startAction):
(WebPushTool::Connection::sendPushMessage):

* webpushd/webpushtool/WebPushToolMain.mm:
(main):

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (287124 => 287125)


--- trunk/Source/WebKit/ChangeLog	2021-12-16 03:46:06 UTC (rev 287124)
+++ trunk/Source/WebKit/ChangeLog	2021-12-16 04:33:12 UTC (rev 287125)
@@ -1,5 +1,31 @@
 2021-12-15  Brady Eidson  <[email protected]>
 
+        Some webpushtool improvements.
+        https://bugs.webkit.org/show_bug.cgi?id=234372
+
+        Reviewed by Alex Christensen.
+
+        - Make the list of current connections be reliably ordered
+        - If the invocation is solely about injecting a push message, exit afterwards
+        - Some other tiny niceties
+
+        * webpushd/WebPushDaemon.mm:
+        (WebPushD::Daemon::broadcastAllConnectionIdentities):
+        (WebPushD::Daemon::injectPushMessageForTesting):
+
+        * webpushd/webpushtool/WebPushToolConnection.h:
+        * webpushd/webpushtool/WebPushToolConnection.mm:
+        (WebPushTool::Connection::create):
+        (WebPushTool::Connection::Connection):
+        (WebPushTool::Connection::connectToService):
+        (WebPushTool::Connection::startAction):
+        (WebPushTool::Connection::sendPushMessage):
+
+        * webpushd/webpushtool/WebPushToolMain.mm:
+        (main):
+
+2021-12-15  Brady Eidson  <[email protected]>
+
         Add a "NotificationData" object to encompass local Notification-related parameters, instead of passing tons of them around everywhere.
         https://bugs.webkit.org/show_bug.cgi?id=234370
 

Modified: trunk/Source/WebKit/webpushd/WebPushDaemon.mm (287124 => 287125)


--- trunk/Source/WebKit/webpushd/WebPushDaemon.mm	2021-12-16 03:46:06 UTC (rev 287124)
+++ trunk/Source/WebKit/webpushd/WebPushDaemon.mm	2021-12-16 04:33:12 UTC (rev 287125)
@@ -188,8 +188,14 @@
 void Daemon::broadcastAllConnectionIdentities()
 {
     broadcastDebugMessage((JSC::MessageLevel)4, "===\nCurrent connections:");
-    for (auto& iterator : m_connectionMap)
-        iterator.value->broadcastDebugMessage("");
+
+    auto connections = copyToVector(m_connectionMap.values());
+    std::sort(connections.begin(), connections.end(), [] (const Ref<ClientConnection>& a, const Ref<ClientConnection>& b) {
+        return a->identifier() < b->identifier();
+    });
+
+    for (auto& iterator : connections)
+        iterator->broadcastDebugMessage("");
     broadcastDebugMessage((JSC::MessageLevel)4, "===");
 }
 
@@ -350,7 +356,7 @@
         return;
     }
 
-    connection->broadcastDebugMessage(makeString("Injected a test push messasge for ", message.targetAppCodeSigningIdentifier, " at ", message.registrationURL.string()));
+    connection->broadcastDebugMessage(makeString("Injected a test push message for ", message.targetAppCodeSigningIdentifier, " at ", message.registrationURL.string()));
     connection->broadcastDebugMessage(message.message);
 
     auto addResult = m_testingPushMessages.ensure(message.targetAppCodeSigningIdentifier, [] {

Modified: trunk/Source/WebKit/webpushd/webpushtool/WebPushToolConnection.h (287124 => 287125)


--- trunk/Source/WebKit/webpushd/webpushtool/WebPushToolConnection.h	2021-12-16 03:46:06 UTC (rev 287124)
+++ trunk/Source/WebKit/webpushd/webpushtool/WebPushToolConnection.h	2021-12-16 04:33:12 UTC (rev 287125)
@@ -58,8 +58,8 @@
 class Connection : public CanMakeWeakPtr<Connection> {
     WTF_MAKE_FAST_ALLOCATED;
 public:
-    static std::unique_ptr<Connection> create(Action, PreferTestService, Reconnect);
-    Connection(Action, PreferTestService, Reconnect);
+    static std::unique_ptr<Connection> create(std::optional<Action>, PreferTestService, Reconnect);
+    Connection(std::optional<Action>, PreferTestService, Reconnect);
 
     void connectToService(WaitForServiceToExist);
 
@@ -75,7 +75,7 @@
 
     void sendAuditToken();
 
-    Action m_action;
+    std::optional<Action> m_action;
     bool m_reconnect { false };
     RetainPtr<xpc_connection_t> m_connection;
     const char* m_serviceName;

Modified: trunk/Source/WebKit/webpushd/webpushtool/WebPushToolConnection.mm (287124 => 287125)


--- trunk/Source/WebKit/webpushd/webpushtool/WebPushToolConnection.mm	2021-12-16 03:46:06 UTC (rev 287124)
+++ trunk/Source/WebKit/webpushd/webpushtool/WebPushToolConnection.mm	2021-12-16 04:33:12 UTC (rev 287125)
@@ -37,7 +37,7 @@
 
 namespace WebPushTool {
 
-std::unique_ptr<Connection> Connection::create(Action action, PreferTestService preferTestService, Reconnect reconnect)
+std::unique_ptr<Connection> Connection::create(std::optional<Action> action, PreferTestService preferTestService, Reconnect reconnect)
 {
     return makeUnique<Connection>(action, preferTestService, reconnect);
 }
@@ -56,7 +56,7 @@
     return MACH_PORT_NULL;
 }
 
-Connection::Connection(Action action, PreferTestService preferTestService, Reconnect reconnect)
+Connection::Connection(std::optional<Action> action, PreferTestService preferTestService, Reconnect reconnect)
     : m_action(action)
     , m_reconnect(reconnect == Reconnect::Yes)
 {
@@ -110,6 +110,7 @@
         }
     }
 
+    printf("Connecting to service '%s'\n", m_serviceName);
     xpc_connection_activate(m_connection.get());
 
     sendAuditToken();
@@ -118,11 +119,13 @@
 
 void Connection::startAction()
 {
-    switch (m_action) {
-    case Action::StreamDebugMessages:
-        startDebugStreamAction();
-        break;
-    };
+    if (m_action) {
+        switch (*m_action) {
+        case Action::StreamDebugMessages:
+            startDebugStreamAction();
+            break;
+        };
+    }
 
     if (m_pushMessage)
         sendPushMessage();
@@ -140,8 +143,14 @@
     xpc_dictionary_set_value(dictionary.get(), WebKit::WebPushD::protocolEncodedMessageKey, WebKit::vectorToXPCData(encoder.takeBuffer()).get());
     xpc_dictionary_set_uint64(dictionary.get(), WebKit::WebPushD::protocolMessageTypeKey, static_cast<uint64_t>(WebKit::WebPushD::MessageType::InjectPushMessageForTesting));
 
+    printf("Injecting push message\n");
+
+    // If we have no action for this invocation (such as streaming debug messages) then we can exit after the push injection completes
+    __block bool shouldExitAfterInject = !m_action;
     xpc_connection_send_message_with_reply(m_connection.get(), dictionary.get(), dispatch_get_main_queue(), ^(xpc_object_t resultMessage) {
-        // This reply handler intentionally left blank
+        printf("Push message injected\n");
+        if (shouldExitAfterInject)
+            CFRunLoopStop(CFRunLoopGetMain());
     });
 }
 

Modified: trunk/Source/WebKit/webpushd/webpushtool/WebPushToolMain.mm (287124 => 287125)


--- trunk/Source/WebKit/webpushd/webpushtool/WebPushToolMain.mm	2021-12-16 03:46:06 UTC (rev 287124)
+++ trunk/Source/WebKit/webpushd/webpushtool/WebPushToolMain.mm	2021-12-16 04:33:12 UTC (rev 287125)
@@ -187,7 +187,7 @@
         printUsageAndTerminate(@"Unable to install plist to host the service");
 #endif
 
-    auto connection = WebPushTool::Connection::create(*action, preferTestService, reconnect);
+    auto connection = WebPushTool::Connection::create(action, preferTestService, reconnect);
     if (pushMessage)
         connection->setPushMessage(WTFMove(pushMessage));
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to