Rename RegistrationOptions to ServiceWorkerRegistrationOptions
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 30 Nov 2017 19:17:55 +0000 (19:17 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 30 Nov 2017 19:17:55 +0000 (19:17 +0000)
https://bugs.webkit.org/show_bug.cgi?id=180207

Reviewed by Geoffrey Garen.

Rename RegistrationOptions to ServiceWorkerRegistrationOptions as the name
RegistrationOptions is too generic and likely to conflict. Also modernize
ServiceWorkerRegistrationOptions' IPC decoder.

* workers/service/ServiceWorkerContainer.h:
* workers/service/ServiceWorkerJobData.h:
(WebCore::ServiceWorkerJobData::decode):
* workers/service/ServiceWorkerRegistrationOptions.cpp:
(WebCore::ServiceWorkerRegistrationOptions::isolatedCopy const):
* workers/service/ServiceWorkerRegistrationOptions.h:
(WebCore::ServiceWorkerRegistrationOptions::encode const):
(WebCore::ServiceWorkerRegistrationOptions::decode):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225335 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/workers/service/ServiceWorkerContainer.h
Source/WebCore/workers/service/ServiceWorkerJobData.h
Source/WebCore/workers/service/ServiceWorkerRegistrationOptions.cpp
Source/WebCore/workers/service/ServiceWorkerRegistrationOptions.h

index 3793607..3d6f400 100644 (file)
@@ -1,3 +1,23 @@
+2017-11-30  Chris Dumez  <cdumez@apple.com>
+
+        Rename RegistrationOptions to ServiceWorkerRegistrationOptions
+        https://bugs.webkit.org/show_bug.cgi?id=180207
+
+        Reviewed by Geoffrey Garen.
+
+        Rename RegistrationOptions to ServiceWorkerRegistrationOptions as the name
+        RegistrationOptions is too generic and likely to conflict. Also modernize
+        ServiceWorkerRegistrationOptions' IPC decoder.
+
+        * workers/service/ServiceWorkerContainer.h:
+        * workers/service/ServiceWorkerJobData.h:
+        (WebCore::ServiceWorkerJobData::decode):
+        * workers/service/ServiceWorkerRegistrationOptions.cpp:
+        (WebCore::ServiceWorkerRegistrationOptions::isolatedCopy const):
+        * workers/service/ServiceWorkerRegistrationOptions.h:
+        (WebCore::ServiceWorkerRegistrationOptions::encode const):
+        (WebCore::ServiceWorkerRegistrationOptions::decode):
+
 2017-11-30  Darin Adler  <darin@apple.com>
 
         [Mac] remove unneeded RetainPtr use introduced in r225142
index bb5da69..285c681 100644 (file)
@@ -53,13 +53,12 @@ public:
     ServiceWorkerContainer(ScriptExecutionContext&, NavigatorBase&);
     ~ServiceWorkerContainer();
 
-    typedef WebCore::RegistrationOptions RegistrationOptions;
-
     ServiceWorker* controller() const;
 
     using ReadyPromise = DOMPromiseProxy<IDLInterface<ServiceWorkerRegistration>>;
     ReadyPromise& ready() { return m_readyPromise; }
 
+    using RegistrationOptions = ServiceWorkerRegistrationOptions;
     void addRegistration(const String& scriptURL, const RegistrationOptions&, Ref<DeferredPromise>&&);
     void removeRegistration(const URL& scopeURL, Ref<DeferredPromise>&&);
     void updateRegistration(const URL& scopeURL, const URL& scriptURL, WorkerType, Ref<DeferredPromise>&&);
index 32e5403..be13b8b 100644 (file)
@@ -51,7 +51,7 @@ struct ServiceWorkerJobData {
     URL scopeURL;
     ServiceWorkerJobType type;
 
-    RegistrationOptions registrationOptions;
+    ServiceWorkerRegistrationOptions registrationOptions;
 
     Identifier identifier() const { return m_identifier; }
     ServiceWorkerRegistrationKey registrationKey() const;
@@ -89,35 +89,39 @@ std::optional<ServiceWorkerJobData> ServiceWorkerJobData::decode(Decoder& decode
     if (!identifier)
         return std::nullopt;
 
-    std::optional<ServiceWorkerJobData> jobData = { ServiceWorkerJobData { WTFMove(*identifier) } };
+    ServiceWorkerJobData jobData { WTFMove(*identifier) };
 
-    if (!decoder.decode(jobData->scriptURL))
+    if (!decoder.decode(jobData.scriptURL))
         return std::nullopt;
-    if (!decoder.decode(jobData->clientCreationURL))
+    if (!decoder.decode(jobData.clientCreationURL))
         return std::nullopt;
 
     std::optional<SecurityOriginData> topOrigin;
     decoder >> topOrigin;
     if (!topOrigin)
         return std::nullopt;
-    jobData->topOrigin = WTFMove(*topOrigin);
+    jobData.topOrigin = WTFMove(*topOrigin);
 
-    if (!decoder.decode(jobData->scopeURL))
+    if (!decoder.decode(jobData.scopeURL))
         return std::nullopt;
-    if (!decoder.decodeEnum(jobData->type))
+    if (!decoder.decodeEnum(jobData.type))
         return std::nullopt;
 
-    switch (jobData->type) {
-    case ServiceWorkerJobType::Register:
-        if (!decoder.decode(jobData->registrationOptions))
+    switch (jobData.type) {
+    case ServiceWorkerJobType::Register: {
+        std::optional<ServiceWorkerRegistrationOptions> registrationOptions;
+        decoder >> registrationOptions;
+        if (!registrationOptions)
             return std::nullopt;
+        jobData.registrationOptions = WTFMove(*registrationOptions);
         break;
+    }
     case ServiceWorkerJobType::Unregister:
     case ServiceWorkerJobType::Update:
         break;
     }
 
-    return jobData;
+    return WTFMove(jobData);
 }
 
 } // namespace WebCore
index 3795362..ef02a7f 100644 (file)
 
 namespace WebCore {
 
-RegistrationOptions RegistrationOptions::isolatedCopy() const
+ServiceWorkerRegistrationOptions ServiceWorkerRegistrationOptions::isolatedCopy() const
 {
-    RegistrationOptions result;
-    result.scope = scope.isolatedCopy();
-    result.type = type;
-    result.updateViaCache = updateViaCache;
-
-    return result;
+    return ServiceWorkerRegistrationOptions { scope.isolatedCopy(), type, updateViaCache };
 }
 
 } // namespace WebCore
index 187b85b..3bfcaf7 100644 (file)
@@ -34,36 +34,42 @@ namespace WebCore {
 enum class ServiceWorkerUpdateViaCache;
 enum class WorkerType;
 
-struct RegistrationOptions {
+struct ServiceWorkerRegistrationOptions {
     String scope;
     WorkerType type;
     ServiceWorkerUpdateViaCache updateViaCache;
 
-    RegistrationOptions isolatedCopy() const;
+    ServiceWorkerRegistrationOptions isolatedCopy() const;
 
     template<class Encoder> void encode(Encoder&) const;
-    template<class Decoder> static bool decode(Decoder&, RegistrationOptions&);
+    template<class Decoder> static std::optional<ServiceWorkerRegistrationOptions> decode(Decoder&);
 };
 
 template<class Encoder>
-void RegistrationOptions::encode(Encoder& encoder) const
+void ServiceWorkerRegistrationOptions::encode(Encoder& encoder) const
 {
-    encoder << scope;
-    encoder.encodeEnum(type);
-    encoder.encodeEnum(updateViaCache);
+    encoder << scope << type << updateViaCache;
 }
 
 template<class Decoder>
-bool RegistrationOptions::decode(Decoder& decoder, RegistrationOptions& options)
+std::optional<ServiceWorkerRegistrationOptions> ServiceWorkerRegistrationOptions::decode(Decoder& decoder)
 {
-    if (!decoder.decode(options.scope))
-        return false;
-    if (!decoder.decodeEnum(options.type))
-        return false;
-    if (!decoder.decodeEnum(options.updateViaCache))
-        return false;
+    std::optional<String> scope;
+    decoder >> scope;
+    if (!scope)
+        return std::nullopt;
 
-    return true;
+    std::optional<WorkerType> type;
+    decoder >> type;
+    if (!type)
+        return std::nullopt;
+
+    std::optional<ServiceWorkerUpdateViaCache> updateViaCache;
+    decoder >> updateViaCache;
+    if (!updateViaCache)
+        return std::nullopt;
+
+    return ServiceWorkerRegistrationOptions { WTFMove(*scope), WTFMove(*type), WTFMove(*updateViaCache) };
 }
 
 } // namespace WebCore