Title: [209583] trunk/Source
Revision
209583
Author
[email protected]
Date
2016-12-08 16:56:48 -0800 (Thu, 08 Dec 2016)

Log Message

Move FileHandle to WebCore FileHandle.h
https://bugs.webkit.org/show_bug.cgi?id=165562

Reviewed by Alex Christensen.

Source/WebCore:

Add FileHandle, a small wrapper around FileSystem facilities to manage
the lifetime of an open file and give the facilities a C++ interface.

No new tests -- affected facility is currently only used in testing
code and is not user reachable.

* CMakeLists.txt:
* WebCore.xcodeproj/project.pbxproj:
* platform/FileHandle.cpp: Added.
(WebCore::FileHandle::FileHandle):
(WebCore::FileHandle::~FileHandle):
(WebCore::FileHandle::operator=):
(WebCore::FileHandle::operator bool):
(WebCore::FileHandle::open):
(WebCore::FileHandle::read):
(WebCore::FileHandle::write):
(WebCore::FileHandle::printf):
(WebCore::FileHandle::close):
* platform/FileHandle.h: Added.

Source/WebKit2:

Move FileHandle from NetworkCaptureTypes.h (which can now be deleted)
to WebCore. Update client code to use the new version.

* NetworkProcess/capture/NetworkCaptureEvent.cpp:
* NetworkProcess/capture/NetworkCaptureEvent.h:
* NetworkProcess/capture/NetworkCaptureManager.cpp:
(WebKit::NetworkCapture::Manager::initialize):
(WebKit::NetworkCapture::Manager::terminate):
(WebKit::NetworkCapture::Manager::logRecordedResource):
(WebKit::NetworkCapture::Manager::logLoadedResource):
(WebKit::NetworkCapture::Manager::logPlayedBackResource):
(WebKit::NetworkCapture::Manager::openCacheFile):
(WebKit::NetworkCapture::Manager::ensureFileHandle): Deleted.
(WebKit::NetworkCapture::Manager::printToFile): Deleted.
* NetworkProcess/capture/NetworkCaptureManager.h:
* NetworkProcess/capture/NetworkCaptureRecorder.cpp:
(WebKit::NetworkCapture::Recorder::writeEvents):
* NetworkProcess/capture/NetworkCaptureTypes.h: Removed.
* WebKit2.xcodeproj/project.pbxproj:

Modified Paths

Added Paths

Removed Paths

Diff

Modified: trunk/Source/WebCore/CMakeLists.txt (209582 => 209583)


--- trunk/Source/WebCore/CMakeLists.txt	2016-12-09 00:53:32 UTC (rev 209582)
+++ trunk/Source/WebCore/CMakeLists.txt	2016-12-09 00:56:48 UTC (rev 209583)
@@ -2142,6 +2142,7 @@
     platform/DragImage.cpp
     platform/EventTrackingRegions.cpp
     platform/FileChooser.cpp
+    platform/FileHandle.cpp
     platform/FileStream.cpp
     platform/FileSystem.cpp
     platform/GenericTaskQueue.cpp

Modified: trunk/Source/WebCore/ChangeLog (209582 => 209583)


--- trunk/Source/WebCore/ChangeLog	2016-12-09 00:53:32 UTC (rev 209582)
+++ trunk/Source/WebCore/ChangeLog	2016-12-09 00:56:48 UTC (rev 209583)
@@ -1,3 +1,30 @@
+2016-12-08  Keith Rollin  <[email protected]>
+
+        Move FileHandle to WebCore FileHandle.h
+        https://bugs.webkit.org/show_bug.cgi?id=165562
+
+        Reviewed by Alex Christensen.
+
+        Add FileHandle, a small wrapper around FileSystem facilities to manage
+        the lifetime of an open file and give the facilities a C++ interface.
+
+        No new tests -- affected facility is currently only used in testing
+        code and is not user reachable.
+
+        * CMakeLists.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+        * platform/FileHandle.cpp: Added.
+        (WebCore::FileHandle::FileHandle):
+        (WebCore::FileHandle::~FileHandle):
+        (WebCore::FileHandle::operator=):
+        (WebCore::FileHandle::operator bool):
+        (WebCore::FileHandle::open):
+        (WebCore::FileHandle::read):
+        (WebCore::FileHandle::write):
+        (WebCore::FileHandle::printf):
+        (WebCore::FileHandle::close):
+        * platform/FileHandle.h: Added.
+
 2016-12-07  Ryosuke Niwa  <[email protected]>
 
         ASSERTION FAILED: m_items.isEmpty() in CustomElementReactionQueue destructor

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (209582 => 209583)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2016-12-09 00:53:32 UTC (rev 209582)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2016-12-09 00:56:48 UTC (rev 209583)
@@ -2320,6 +2320,8 @@
 		52F52E1114A0134F00ACC397 /* NSScrollerImpDetails.mm in Sources */ = {isa = PBXBuildFile; fileRef = 52F52E1014A0134F00ACC397 /* NSScrollerImpDetails.mm */; };
 		5317612213C516690026E454 /* StyleFlexibleBoxData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5317612013C516690026E454 /* StyleFlexibleBoxData.cpp */; };
 		5317612313C516690026E454 /* StyleFlexibleBoxData.h in Headers */ = {isa = PBXBuildFile; fileRef = 5317612113C516690026E454 /* StyleFlexibleBoxData.h */; settings = {ATTRIBUTES = (Private, ); }; };
+		5351D4B01DF916B4008010CD /* FileHandle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5351D4AE1DF916AC008010CD /* FileHandle.cpp */; };
+		5351D4B11DF916B4008010CD /* FileHandle.h in Headers */ = {isa = PBXBuildFile; fileRef = 5351D4AF1DF916AC008010CD /* FileHandle.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		536D5A20193E18E900CE4CAB /* HTMLSrcsetParser.h in Headers */ = {isa = PBXBuildFile; fileRef = 536D5A1F193E18E900CE4CAB /* HTMLSrcsetParser.h */; };
 		536D5A21193E18EE00CE4CAB /* HTMLSrcsetParser.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 536D5A1E193E18D000CE4CAB /* HTMLSrcsetParser.cpp */; };
 		536D5A23193E8E0C00CE4CAB /* ParsingUtilities.h in Headers */ = {isa = PBXBuildFile; fileRef = 536D5A22193E8E0C00CE4CAB /* ParsingUtilities.h */; };
@@ -9565,6 +9567,8 @@
 		52F52E1014A0134F00ACC397 /* NSScrollerImpDetails.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = NSScrollerImpDetails.mm; sourceTree = "<group>"; };
 		5317612013C516690026E454 /* StyleFlexibleBoxData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StyleFlexibleBoxData.cpp; sourceTree = "<group>"; };
 		5317612113C516690026E454 /* StyleFlexibleBoxData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StyleFlexibleBoxData.h; sourceTree = "<group>"; };
+		5351D4AE1DF916AC008010CD /* FileHandle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FileHandle.cpp; sourceTree = "<group>"; };
+		5351D4AF1DF916AC008010CD /* FileHandle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FileHandle.h; sourceTree = "<group>"; };
 		536D5A1E193E18D000CE4CAB /* HTMLSrcsetParser.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HTMLSrcsetParser.cpp; sourceTree = "<group>"; };
 		536D5A1F193E18E900CE4CAB /* HTMLSrcsetParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HTMLSrcsetParser.h; sourceTree = "<group>"; };
 		536D5A22193E8E0C00CE4CAB /* ParsingUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ParsingUtilities.h; sourceTree = "<group>"; };
@@ -22515,6 +22519,8 @@
 				262EC4191D078F3D00BA78FC /* EventTrackingRegions.h */,
 				934FE9E40B5CA539003E4A73 /* FileChooser.cpp */,
 				066C772A0AB603B700238CC4 /* FileChooser.h */,
+				5351D4AE1DF916AC008010CD /* FileHandle.cpp */,
+				5351D4AF1DF916AC008010CD /* FileHandle.h */,
 				4689F1AE1267BAE100E8D380 /* FileMetadata.h */,
 				2EF1BFE8121C9F4200C27627 /* FileStream.cpp */,
 				2EF1BFE9121C9F4200C27627 /* FileStream.h */,
@@ -27379,6 +27385,7 @@
 				57E233631DC7DA2400F28D01 /* RsaOtherPrimesInfo.h in Headers */,
 				07AB996918DA3C010018771E /* RTCConfiguration.h in Headers */,
 				07AB996F18DA3C740018771E /* RTCConfigurationPrivate.h in Headers */,
+				5351D4B11DF916B4008010CD /* FileHandle.h in Headers */,
 				078E091E17D14D1C00420AA1 /* RTCDataChannel.h in Headers */,
 				078E091F17D14D1C00420AA1 /* RTCDataChannelEvent.h in Headers */,
 				078E093C17D16E1C00420AA1 /* RTCDataChannelHandler.h in Headers */,
@@ -31730,6 +31737,7 @@
 				2D0621441DA639B600A7FB26 /* WebKitMediaKeyMessageEvent.cpp in Sources */,
 				2D0621521DA63AA200A7FB26 /* WebKitMediaKeyNeededEvent.cpp in Sources */,
 				2D06214D1DA63A8B00A7FB26 /* WebKitMediaKeys.cpp in Sources */,
+				5351D4B01DF916B4008010CD /* FileHandle.cpp in Sources */,
 				2D06214F1DA63A9100A7FB26 /* WebKitMediaKeySession.cpp in Sources */,
 				D7613A501474F13F00DB8606 /* WebKitNamedFlow.cpp in Sources */,
 				7C48A6D0191C9D6500026674 /* WebKitNamespace.cpp in Sources */,

Added: trunk/Source/WebCore/platform/FileHandle.cpp (0 => 209583)


--- trunk/Source/WebCore/platform/FileHandle.cpp	                        (rev 0)
+++ trunk/Source/WebCore/platform/FileHandle.cpp	2016-12-09 00:56:48 UTC (rev 209583)
@@ -0,0 +1,122 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ * 3.  Neither the name of Apple Inc. ("Apple") nor the names of
+ *     its contributors may be used to endorse or promote products derived
+ *     from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "FileHandle.h"
+
+#include <stdarg.h>
+#include <stdio.h>
+
+namespace WebCore {
+
+FileHandle::FileHandle(const String& path, FileOpenMode mode)
+    : m_path(path)
+    , m_mode(mode)
+{
+}
+
+FileHandle::FileHandle(FileHandle&& other)
+    : m_path(WTFMove(other.m_path))
+    , m_mode(WTFMove(other.m_mode))
+    , m_fileHandle(std::exchange(other.m_fileHandle, invalidPlatformFileHandle))
+{
+}
+
+FileHandle::~FileHandle()
+{
+    close();
+}
+
+FileHandle& FileHandle::operator=(FileHandle&& other)
+{
+    close();
+    m_path = WTFMove(other.m_path);
+    m_mode = WTFMove(other.m_mode);
+    m_fileHandle = std::exchange(other.m_fileHandle, invalidPlatformFileHandle);
+    return *this;
+}
+
+FileHandle::operator bool() const
+{
+    return isHandleValid(m_fileHandle);
+}
+
+bool FileHandle::open(const String& path, FileOpenMode mode)
+{
+    if (*this && path == m_path && mode == m_mode)
+        return true;
+
+    close();
+    m_path = path;
+    m_mode = mode;
+    return open();
+}
+
+bool FileHandle::open()
+{
+    if (!*this)
+        m_fileHandle = openFile(m_path, m_mode);
+    return static_cast<bool>(*this);
+}
+
+int FileHandle::read(void* data, int length)
+{
+    if (!open())
+        return -1;
+    return readFromFile(m_fileHandle, static_cast<char*>(data), length);
+}
+
+int FileHandle::write(const void* data, int length)
+{
+    if (!open())
+        return -1;
+    return writeToFile(m_fileHandle, static_cast<const char*>(data), length);
+}
+
+bool FileHandle::printf(const char* format, ...)
+{
+    va_list args;
+    va_start(args, format);
+
+    char* buffer = nullptr;
+    if (vasprintf(&buffer, format, args) == -1)
+        return false;
+    auto writeResult = write(buffer, strlen(buffer));
+    free(buffer);
+
+    va_end(args);
+
+    return writeResult >= 0;
+}
+
+void FileHandle::close()
+{
+    closeFile(m_fileHandle);
+}
+
+} // namespace WebCore

Added: trunk/Source/WebCore/platform/FileHandle.h (0 => 209583)


--- trunk/Source/WebCore/platform/FileHandle.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/FileHandle.h	2016-12-09 00:56:48 UTC (rev 209583)
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ * 3.  Neither the name of Apple Inc. ("Apple") nor the names of
+ *     its contributors may be used to endorse or promote products derived
+ *     from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include "FileSystem.h"
+
+#include <wtf/Assertions.h>
+
+namespace WebCore {
+
+class WEBCORE_EXPORT FileHandle final {
+public:
+    FileHandle() = default;
+    FileHandle(const String& path, FileOpenMode);
+    FileHandle(const FileHandle& other) = delete;
+    FileHandle(FileHandle&& other);
+
+    ~FileHandle();
+
+    FileHandle& operator=(const FileHandle& other) = delete;
+    FileHandle& operator=(FileHandle&& other);
+
+    explicit operator bool() const;
+
+    bool open(const String& path, FileOpenMode);
+    bool open();
+    int read(void* data, int length);
+    int write(const void* data, int length);
+    bool printf(const char* format, ...) WTF_ATTRIBUTE_PRINTF(2, 3);
+    void close();
+
+private:
+    String m_path;
+    FileOpenMode m_mode { OpenForRead };
+    PlatformFileHandle m_fileHandle { invalidPlatformFileHandle };
+};
+
+} // namespace WebCore

Modified: trunk/Source/WebKit2/ChangeLog (209582 => 209583)


--- trunk/Source/WebKit2/ChangeLog	2016-12-09 00:53:32 UTC (rev 209582)
+++ trunk/Source/WebKit2/ChangeLog	2016-12-09 00:56:48 UTC (rev 209583)
@@ -1,3 +1,30 @@
+2016-12-08  Keith Rollin  <[email protected]>
+
+        Move FileHandle to WebCore FileHandle.h
+        https://bugs.webkit.org/show_bug.cgi?id=165562
+
+        Reviewed by Alex Christensen.
+
+        Move FileHandle from NetworkCaptureTypes.h (which can now be deleted)
+        to WebCore. Update client code to use the new version.
+
+        * NetworkProcess/capture/NetworkCaptureEvent.cpp:
+        * NetworkProcess/capture/NetworkCaptureEvent.h:
+        * NetworkProcess/capture/NetworkCaptureManager.cpp:
+        (WebKit::NetworkCapture::Manager::initialize):
+        (WebKit::NetworkCapture::Manager::terminate):
+        (WebKit::NetworkCapture::Manager::logRecordedResource):
+        (WebKit::NetworkCapture::Manager::logLoadedResource):
+        (WebKit::NetworkCapture::Manager::logPlayedBackResource):
+        (WebKit::NetworkCapture::Manager::openCacheFile):
+        (WebKit::NetworkCapture::Manager::ensureFileHandle): Deleted.
+        (WebKit::NetworkCapture::Manager::printToFile): Deleted.
+        * NetworkProcess/capture/NetworkCaptureManager.h:
+        * NetworkProcess/capture/NetworkCaptureRecorder.cpp:
+        (WebKit::NetworkCapture::Recorder::writeEvents):
+        * NetworkProcess/capture/NetworkCaptureTypes.h: Removed.
+        * WebKit2.xcodeproj/project.pbxproj:
+
 2016-12-08  Anders Carlsson  <[email protected]>
 
         Attempt to fix the iOS build.

Modified: trunk/Source/WebKit2/NetworkProcess/capture/NetworkCaptureEvent.cpp (209582 => 209583)


--- trunk/Source/WebKit2/NetworkProcess/capture/NetworkCaptureEvent.cpp	2016-12-09 00:53:32 UTC (rev 209582)
+++ trunk/Source/WebKit2/NetworkProcess/capture/NetworkCaptureEvent.cpp	2016-12-09 00:56:48 UTC (rev 209583)
@@ -28,7 +28,6 @@
 
 #if ENABLE(NETWORK_CAPTURE)
 
-
 #include "NetworkCaptureLogging.h"
 #include "json.hpp"
 #include <WebCore/ResourceError.h>

Modified: trunk/Source/WebKit2/NetworkProcess/capture/NetworkCaptureEvent.h (209582 => 209583)


--- trunk/Source/WebKit2/NetworkProcess/capture/NetworkCaptureEvent.h	2016-12-09 00:53:32 UTC (rev 209582)
+++ trunk/Source/WebKit2/NetworkProcess/capture/NetworkCaptureEvent.h	2016-12-09 00:56:48 UTC (rev 209583)
@@ -27,7 +27,6 @@
 
 #if ENABLE(NETWORK_CAPTURE)
 
-#include "NetworkCaptureTypes.h"
 #include <WebCore/SharedBuffer.h>
 #include <wtf/MonotonicTime.h>
 #include <wtf/Optional.h>

Modified: trunk/Source/WebKit2/NetworkProcess/capture/NetworkCaptureManager.cpp (209582 => 209583)


--- trunk/Source/WebKit2/NetworkProcess/capture/NetworkCaptureManager.cpp	2016-12-09 00:53:32 UTC (rev 209582)
+++ trunk/Source/WebKit2/NetworkProcess/capture/NetworkCaptureManager.cpp	2016-12-09 00:56:48 UTC (rev 209583)
@@ -39,7 +39,6 @@
 #include <algorithm>
 #include <iterator>
 #include <limits>
-#include <stdarg.h>
 
 #define DEBUG_CLASS Manager
 
@@ -73,6 +72,9 @@
         m_recordReplayMode = Disabled;
 
     m_recordReplayCacheLocation = WebCore::pathByAppendingComponent(recordReplayCacheLocation, kDirNameRecordReplay);
+    m_loadFileHandle = WebCore::FileHandle(reportLoadPath(), WebCore::OpenForWrite);
+    m_recordFileHandle = WebCore::FileHandle(reportRecordPath(), WebCore::OpenForWrite);
+    m_replayFileHandle = WebCore::FileHandle(reportReplayPath(), WebCore::OpenForWrite);
 
     DEBUG_LOG("Cache location = %{public}s", DEBUG_STR(m_recordReplayCacheLocation));
 
@@ -82,9 +84,9 @@
 
 void Manager::terminate()
 {
-    m_loadFileHandle.closeFile();
-    m_replayFileHandle.closeFile();
-    m_recordFileHandle.closeFile();
+    m_loadFileHandle.close();
+    m_recordFileHandle.close();
+    m_replayFileHandle.close();
 }
 
 Resource* Manager::findMatch(const WebCore::ResourceRequest& request)
@@ -416,10 +418,8 @@
 {
     // Log network resources as they are cached to disk.
 
-    if (ensureFileHandle(reportRecordPath(), m_recordFileHandle)) {
-        const auto& url = ""
-        printToFile(m_recordFileHandle, "%s %s\n", DEBUG_STR(stringToHash(url.string())), DEBUG_STR(url.string()));
-    }
+    const auto& url = ""
+    m_recordFileHandle.printf("%s %s\n", DEBUG_STR(stringToHash(url.string())), DEBUG_STR(url.string()));
 }
 
 void Manager::logLoadedResource(Resource& resource)
@@ -426,8 +426,7 @@
 {
     // Log cached resources as they are loaded from disk.
 
-    if (ensureFileHandle(reportLoadPath(), m_loadFileHandle))
-        printToFile(m_loadFileHandle, "%s\n", DEBUG_STR(resource.url().string()));
+    m_loadFileHandle.printf("%s\n", DEBUG_STR(resource.url().string()));
 }
 
 void Manager::logPlayedBackResource(const WebCore::ResourceRequest& request, bool wasCacheMiss)
@@ -441,24 +440,16 @@
     else
         DEBUG_LOG("Cache hit:  URL = "" DEBUG_STR(url.string()));
 
-    if (ensureFileHandle(reportReplayPath(), m_replayFileHandle))
-        printToFile(m_replayFileHandle, "%s %s\n", wasCacheMiss ? "miss" : "hit ", DEBUG_STR(url.string()));
+    m_replayFileHandle.printf("%s %s\n", wasCacheMiss ? "miss" : "hit ", DEBUG_STR(url.string()));
 }
 
-bool Manager::ensureFileHandle(const String& filePath, FileHandle& fileHandle)
+WebCore::FileHandle Manager::openCacheFile(const String& filePath, WebCore::FileOpenMode mode)
 {
-    if (!fileHandle)
-        fileHandle = openCacheFile(filePath, WebCore::OpenForWrite);
-    return fileHandle;
-}
-
-FileHandle Manager::openCacheFile(const String& filePath, WebCore::FileOpenMode mode)
-{
     // If we can trivially open the file, then do that and return the new file
     // handle.
 
-    auto fileHandle = FileHandle::openFile(filePath, mode);
-    if (fileHandle)
+    auto fileHandle = WebCore::FileHandle(filePath, mode);
+    if (fileHandle.open())
         return fileHandle;
 
     // If we're opening the file for writing (including appending), then try
@@ -471,8 +462,8 @@
             return fileHandle;
         }
 
-        fileHandle = FileHandle::openFile(filePath, mode);
-        if (fileHandle)
+        fileHandle = WebCore::FileHandle(filePath, mode);
+        if (fileHandle.open())
             return fileHandle;
     }
 
@@ -578,21 +569,6 @@
     return true;
 }
 
-bool Manager::printToFile(const FileHandle& fileHandle, const char* format, ...)
-{
-    va_list args;
-    va_start(args, format);
-
-    char* buffer = nullptr;
-    vasprintf(&buffer, format, args);
-    auto writeResult = fileHandle.writeToFile(buffer, strlen(buffer));
-    free(buffer);
-
-    va_end(args);
-
-    return writeResult >= 0;
-}
-
 } // namespace NetworkCapture
 } // namespace WebKit
 

Modified: trunk/Source/WebKit2/NetworkProcess/capture/NetworkCaptureManager.h (209582 => 209583)


--- trunk/Source/WebKit2/NetworkProcess/capture/NetworkCaptureManager.h	2016-12-09 00:53:32 UTC (rev 209582)
+++ trunk/Source/WebKit2/NetworkProcess/capture/NetworkCaptureManager.h	2016-12-09 00:56:48 UTC (rev 209583)
@@ -27,7 +27,7 @@
 
 #if ENABLE(NETWORK_CAPTURE)
 
-#include "NetworkCaptureTypes.h"
+#include <WebCore/FileHandle.h>
 #include <WebCore/FileSystem.h>
 #include <WebCore/URLParser.h>
 #include <wtf/Function.h>
@@ -80,7 +80,7 @@
     void logLoadedResource(Resource&);
     void logPlayedBackResource(const WebCore::ResourceRequest&, bool wasCacheMiss);
 
-    FileHandle openCacheFile(const String&, WebCore::FileOpenMode);
+    WebCore::FileHandle openCacheFile(const String&, WebCore::FileOpenMode);
 
     String requestToPath(const WebCore::ResourceRequest&);
 
@@ -101,19 +101,16 @@
     String stringToHash(const String&);
     String hashToPath(const String& hash);
 
-    bool ensureFileHandle(const String& filePath, FileHandle&);
-
     std::optional<Vector<Vector<String>>> readFile(const String& filePath);
     bool getLine(uint8_t const *& p, uint8_t const * const end, Vector<String>& line);
     bool getWord(uint8_t const *& p, uint8_t const * const end, String& word);
-    bool printToFile(const FileHandle&, const char* format, ...);
 
     RecordReplayMode m_recordReplayMode { Disabled };
     String m_recordReplayCacheLocation;
 
-    FileHandle m_loadFileHandle;
-    FileHandle m_replayFileHandle;
-    FileHandle m_recordFileHandle;
+    WebCore::FileHandle m_loadFileHandle;
+    WebCore::FileHandle m_recordFileHandle;
+    WebCore::FileHandle m_replayFileHandle;
 
     Vector<Resource> m_cachedResources;
 };

Modified: trunk/Source/WebKit2/NetworkProcess/capture/NetworkCaptureRecorder.cpp (209582 => 209583)


--- trunk/Source/WebKit2/NetworkProcess/capture/NetworkCaptureRecorder.cpp	2016-12-09 00:53:32 UTC (rev 209582)
+++ trunk/Source/WebKit2/NetworkProcess/capture/NetworkCaptureRecorder.cpp	2016-12-09 00:56:48 UTC (rev 209583)
@@ -33,7 +33,7 @@
 #include <WebCore/ResourceResponse.h>
 #include <WebCore/SharedBuffer.h>
 
-#define DEBUG_CLASS Manager
+#define DEBUG_CLASS Recorder
 
 namespace WebKit {
 namespace NetworkCapture {
@@ -141,7 +141,7 @@
         // to better find the separate JSON objects that we write to a single
         // file. It also works better with JSON parsers that expect to find a
         // NUL at the end of their input.
-        if (handle.writeToFile(asString.c_str(), asString.size() + 1) == -1) {
+        if (handle.write(asString.c_str(), asString.size() + 1) == -1) {
             DEBUG_LOG_ERROR("Error trying to write to file for URL = "" DEBUG_STR(m_initialRequest.url().string()));
             return;
         }

Deleted: trunk/Source/WebKit2/NetworkProcess/capture/NetworkCaptureTypes.h (209582 => 209583)


--- trunk/Source/WebKit2/NetworkProcess/capture/NetworkCaptureTypes.h	2016-12-09 00:53:32 UTC (rev 209582)
+++ trunk/Source/WebKit2/NetworkProcess/capture/NetworkCaptureTypes.h	2016-12-09 00:56:48 UTC (rev 209583)
@@ -1,97 +0,0 @@
-/*
- * Copyright (C) 2016 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#pragma once
-
-#if ENABLE(NETWORK_CAPTURE)
-
-#include <WebCore/FileSystem.h>
-
-namespace WebKit {
-namespace NetworkCapture {
-
-class FileHandle final {
-public:
-    FileHandle() = default;
-
-    FileHandle(WebCore::PlatformFileHandle fileHandle)
-        : m_fileHandle(fileHandle) { }
-
-    FileHandle(FileHandle&& other)
-        : m_fileHandle(std::exchange(other.m_fileHandle, WebCore::invalidPlatformFileHandle)) { }
-
-    ~FileHandle()
-    {
-        closeFile();
-    }
-
-    FileHandle& operator=(WebCore::PlatformFileHandle fileHandle)
-    {
-        closeFile();
-        m_fileHandle = fileHandle;
-        return *this;
-    }
-
-    FileHandle& operator=(FileHandle&& other)
-    {
-        closeFile();
-        m_fileHandle = std::exchange(other.m_fileHandle, WebCore::invalidPlatformFileHandle);
-        return *this;
-    }
-
-    FileHandle(const FileHandle&) = delete;
-    FileHandle& operator=(const FileHandle&) = delete;
-
-    operator WebCore::PlatformFileHandle() const { return m_fileHandle; }
-    explicit operator bool() const { return WebCore::isHandleValid(m_fileHandle); }
-
-    static FileHandle openFile(const String& path, WebCore::FileOpenMode mode)
-    {
-        return FileHandle(WebCore::openFile(path, mode));
-    }
-
-    int readFromFile(void* data, int length) const
-    {
-        return WebCore::readFromFile(m_fileHandle, static_cast<char*>(data), length);
-    }
-
-    int writeToFile(const void* data, int length) const
-    {
-        return WebCore::writeToFile(m_fileHandle, static_cast<const char*>(data), length);
-    }
-
-    void closeFile()
-    {
-        WebCore::closeFile(m_fileHandle);
-    }
-
-private:
-    WebCore::PlatformFileHandle m_fileHandle { WebCore::invalidPlatformFileHandle };
-};
-
-} // namespace NetworkCapture
-} // namespace WebKit
-
-#endif // ENABLE(NETWORK_CAPTURE)

Modified: trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj (209582 => 209583)


--- trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj	2016-12-09 00:53:32 UTC (rev 209582)
+++ trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj	2016-12-09 00:56:48 UTC (rev 209583)
@@ -1076,7 +1076,6 @@
 		53BA47D01DC2EF5E004DF4AD /* NetworkDataTaskBlob.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 539EB5461DC2EE40009D48CF /* NetworkDataTaskBlob.cpp */; };
 		53BA47D11DC2EF5E004DF4AD /* NetworkDataTaskBlob.h in Headers */ = {isa = PBXBuildFile; fileRef = 539EB5471DC2EE40009D48CF /* NetworkDataTaskBlob.h */; };
 		53DEA3661DDE423100E82648 /* json.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 53DEA3651DDE422E00E82648 /* json.hpp */; };
-		53E260651DDA948E00590818 /* NetworkCaptureTypes.h in Headers */ = {isa = PBXBuildFile; fileRef = 53E260641DDA948100590818 /* NetworkCaptureTypes.h */; };
 		5C052F261C6D3BD30076E919 /* AuthenticationManagerCocoa.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5C052F241C6D3AB60076E919 /* AuthenticationManagerCocoa.mm */; };
 		5C1426EC1C23F80900D41183 /* NetworkProcessCreationParameters.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5C1426E21C23F80500D41183 /* NetworkProcessCreationParameters.cpp */; };
 		5C1426ED1C23F80900D41183 /* NetworkProcessCreationParameters.h in Headers */ = {isa = PBXBuildFile; fileRef = 5C1426E31C23F80500D41183 /* NetworkProcessCreationParameters.h */; };
@@ -3191,7 +3190,7 @@
 		52D5A1B31C5749F200DE34A3 /* WebVideoFullscreenManager.messages.in */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = WebVideoFullscreenManager.messages.in; sourceTree = "<group>"; };
 		52D5A1B41C5749F200DE34A3 /* WebVideoFullscreenManager.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebVideoFullscreenManager.mm; sourceTree = "<group>"; };
 		5302582E1DCBBD1D00DA89C2 /* NetworkCaptureResource.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = NetworkCaptureResource.cpp; path = NetworkProcess/capture/NetworkCaptureResource.cpp; sourceTree = "<group>"; };
-		5302582F1DCBBD1D00DA89C2 /* NetworkCaptureResource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = NetworkCaptureResource.h; path = NetworkProcess/capture/NetworkeCachedResource.h; sourceTree = "<group>"; };
+		5302582F1DCBBD1D00DA89C2 /* NetworkCaptureResource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = NetworkCaptureResource.h; path = NetworkProcess/capture/NetworkCaptureResource.h; sourceTree = "<group>"; };
 		530258301DCBBD1D00DA89C2 /* NetworkCaptureEvent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = NetworkCaptureEvent.cpp; path = NetworkProcess/capture/NetworkCaptureEvent.cpp; sourceTree = "<group>"; };
 		530258311DCBBD1D00DA89C2 /* NetworkCaptureEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = NetworkCaptureEvent.h; path = NetworkProcess/capture/NetworkCaptureEvent.h; sourceTree = "<group>"; };
 		530258321DCBBD1D00DA89C2 /* NetworkCaptureLogging.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = NetworkCaptureLogging.h; path = NetworkProcess/capture/NetworkCaptureLogging.h; sourceTree = "<group>"; };
@@ -3210,7 +3209,6 @@
 		539EB5461DC2EE40009D48CF /* NetworkDataTaskBlob.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = NetworkDataTaskBlob.cpp; path = NetworkProcess/NetworkDataTaskBlob.cpp; sourceTree = "<group>"; };
 		539EB5471DC2EE40009D48CF /* NetworkDataTaskBlob.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = NetworkDataTaskBlob.h; path = NetworkProcess/NetworkDataTaskBlob.h; sourceTree = "<group>"; };
 		53DEA3651DDE422E00E82648 /* json.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = json.hpp; path = NetworkProcess/capture/json.hpp; sourceTree = "<group>"; };
-		53E260641DDA948100590818 /* NetworkCaptureTypes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = NetworkCaptureTypes.h; path = NetworkProcess/capture/NetworkCaptureTypes.h; sourceTree = "<group>"; };
 		579D18B71CCFE34B00B1974C /* PhotosSPI.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PhotosSPI.h; sourceTree = "<group>"; };
 		5C052F241C6D3AB60076E919 /* AuthenticationManagerCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = AuthenticationManagerCocoa.mm; path = Authentication/cocoa/AuthenticationManagerCocoa.mm; sourceTree = "<group>"; };
 		5C1426E21C23F80500D41183 /* NetworkProcessCreationParameters.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = NetworkProcessCreationParameters.cpp; path = NetworkProcess/NetworkProcessCreationParameters.cpp; sourceTree = "<group>"; };
@@ -5887,7 +5885,6 @@
 				530258361DCBBD1D00DA89C2 /* NetworkCaptureRecorder.h */,
 				530258371DCBBD1D00DA89C2 /* NetworkCaptureReplayer.cpp */,
 				530258381DCBBD1D00DA89C2 /* NetworkCaptureReplayer.h */,
-				53E260641DDA948100590818 /* NetworkCaptureTypes.h */,
 				530258391DCBBD1D00DA89C2 /* NetworkDataTaskReplay.cpp */,
 				5302583A1DCBBD1D00DA89C2 /* NetworkDataTaskReplay.h */,
 			);
@@ -7916,7 +7913,6 @@
 				530258411DCBBD2200DA89C2 /* NetworkCaptureManager.h in Headers */,
 				530258431DCBBD2200DA89C2 /* NetworkCaptureRecorder.h in Headers */,
 				530258451DCBBD2200DA89C2 /* NetworkCaptureReplayer.h in Headers */,
-				53E260651DDA948E00590818 /* NetworkCaptureTypes.h in Headers */,
 				513A164D1630A9BF005D7D22 /* NetworkConnectionToWebProcess.h in Headers */,
 				51DD9F2916367DA2001578E9 /* NetworkConnectionToWebProcessMessages.h in Headers */,
 				5CBC9B8E1C652CA000A8FDCF /* NetworkDataTask.h in Headers */,
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to