Remove dead code in FormDataStreamCFNet.cpp
authorpsolanki@apple.com <psolanki@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 14 Feb 2011 22:20:47 +0000 (22:20 +0000)
committerpsolanki@apple.com <psolanki@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 14 Feb 2011 22:20:47 +0000 (22:20 +0000)
https://bugs.webkit.org/show_bug.cgi?id=54401

Reviewed by Darin Adler.

The static functions in this file are no longer reachable. We added a conditional branch to
use new CFNetwork functions in r30329 and later made that code path permanent in r41517
which made these functions unreachable.

* platform/network/cf/FormDataStreamCFNet.cpp:

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

Source/WebCore/ChangeLog
Source/WebCore/platform/network/cf/FormDataStreamCFNet.cpp

index be9e3d9..9776c26 100644 (file)
@@ -1,3 +1,16 @@
+2011-02-14  Pratik Solanki  <psolanki@apple.com>
+
+        Remove dead code in FormDataStreamCFNet.cpp
+        https://bugs.webkit.org/show_bug.cgi?id=54401
+
+        Reviewed by Darin Adler.
+
+        The static functions in this file are no longer reachable. We added a conditional branch to
+        use new CFNetwork functions in r30329 and later made that code path permanent in r41517
+        which made these functions unreachable.
+
+        * platform/network/cf/FormDataStreamCFNet.cpp:
+
 2011-02-14  Andreas Kling  <kling@webkit.org>
 
         Reviewed by Darin Adler.
index 8bc8f08..b342fe3 100644 (file)
@@ -53,260 +53,6 @@ typedef CFReadStreamCallBacks WCReadStreamCallBacks;
 
 namespace WebCore {
 
-static HashMap<CFReadStreamRef, RefPtr<FormData> >& getStreamFormDatas()
-{
-    static HashMap<CFReadStreamRef, RefPtr<FormData> > streamFormDatas;
-    return streamFormDatas;
-}
-
-static void formEventCallback(CFReadStreamRef stream, CFStreamEventType type, void* context);
-
-struct FormStreamFields {
-    CFMutableSetRef scheduledRunLoopPairs;
-    Vector<FormDataElement> remainingElements; // in reverse order
-    CFReadStreamRef currentStream;
-    char* currentData;
-    CFReadStreamRef formStream;
-};
-
-struct SchedulePair {
-    CFRunLoopRef runLoop;
-    CFStringRef mode;
-};
-
-static const void* pairRetain(CFAllocatorRef alloc, const void* value)
-{
-    const SchedulePair* pair = static_cast<const SchedulePair*>(value);
-
-    SchedulePair* result = new SchedulePair;
-    CFRetain(pair->runLoop);
-    result->runLoop = pair->runLoop;
-    result->mode = CFStringCreateCopy(alloc, pair->mode);
-    return result;
-}
-
-static void pairRelease(CFAllocatorRef alloc, const void* value)
-{
-    const SchedulePair* pair = static_cast<const SchedulePair*>(value);
-
-    CFRelease(pair->runLoop);
-    CFRelease(pair->mode);
-    delete pair;
-}
-
-static Boolean pairEqual(const void* a, const void* b)
-{
-    const SchedulePair* pairA = static_cast<const SchedulePair*>(a);
-    const SchedulePair* pairB = static_cast<const SchedulePair*>(b);
-
-    return pairA->runLoop == pairB->runLoop && CFEqual(pairA->mode, pairB->mode);
-}
-
-static CFHashCode pairHash(const void* value)
-{
-    const SchedulePair* pair = static_cast<const SchedulePair*>(value);
-
-    return (CFHashCode)pair->runLoop ^ CFHash(pair->mode);
-}
-
-static void closeCurrentStream(FormStreamFields *form)
-{
-    if (form->currentStream) {
-        CFReadStreamClose(form->currentStream);
-        CFReadStreamSetClient(form->currentStream, kCFStreamEventNone, NULL, NULL);
-        CFRelease(form->currentStream);
-        form->currentStream = NULL;
-    }
-    if (form->currentData) {
-        fastFree(form->currentData);
-        form->currentData = 0;
-    }
-}
-
-static void scheduleWithPair(const void* value, void* context)
-{
-    const SchedulePair* pair = static_cast<const SchedulePair*>(value);
-    CFReadStreamRef stream = (CFReadStreamRef)context;
-
-    CFReadStreamScheduleWithRunLoop(stream, pair->runLoop, pair->mode);
-}
-
-static void advanceCurrentStream(FormStreamFields *form)
-{
-    closeCurrentStream(form);
-
-    if (form->remainingElements.isEmpty())
-        return;
-
-    // Create the new stream.
-    FormDataElement& nextInput = form->remainingElements.last();
-    if (nextInput.m_type == FormDataElement::data) {
-        size_t size = nextInput.m_data.size();
-        char* data = nextInput.m_data.releaseBuffer();
-        form->currentStream = CFReadStreamCreateWithBytesNoCopy(0, reinterpret_cast<const UInt8*>(data), size, kCFAllocatorNull);
-        form->currentData = data;
-    } else
-        form->currentStream = CFReadStreamCreateWithFile(0, pathAsURL(nextInput.m_filename).get());
-    form->remainingElements.removeLast();
-
-    // Set up the callback.
-    CFStreamClientContext context = { 0, form, NULL, NULL, NULL };
-    CFReadStreamSetClient(form->currentStream, kCFStreamEventHasBytesAvailable | kCFStreamEventErrorOccurred | kCFStreamEventEndEncountered,
-        formEventCallback, &context);
-
-    // Schedule with the current set of run loops.
-    CFSetApplyFunction(form->scheduledRunLoopPairs, scheduleWithPair, form->currentStream);
-}
-
-static void openNextStream(FormStreamFields* form)
-{
-    // Skip over any streams we can't open.
-    // For some purposes we might want to return an error, but the current CFURLConnection
-    // can't really do anything useful with an error at this point, so this is better.
-    advanceCurrentStream(form);
-    while (form->currentStream && !CFReadStreamOpen(form->currentStream))
-        advanceCurrentStream(form);
-}
-
-static void* formCreate(CFReadStreamRef stream, void* context)
-{
-    FormData* formData = static_cast<FormData*>(context);
-
-    CFSetCallBacks runLoopAndModeCallBacks = { 0, pairRetain, pairRelease, NULL, pairEqual, pairHash };
-
-    FormStreamFields* newInfo = new FormStreamFields;
-    newInfo->scheduledRunLoopPairs = CFSetCreateMutable(0, 0, &runLoopAndModeCallBacks);
-    newInfo->currentStream = NULL;
-    newInfo->currentData = 0;
-    newInfo->formStream = stream; // Don't retain. That would create a reference cycle.
-
-    // Append in reverse order since we remove elements from the end.
-    size_t size = formData->elements().size();
-    newInfo->remainingElements.reserveCapacity(size);
-    for (size_t i = 0; i < size; ++i)
-        newInfo->remainingElements.append(formData->elements()[size - i - 1]);
-
-    getStreamFormDatas().set(stream, adoptRef(formData));
-
-    return newInfo;
-}
-
-static void formFinalize(CFReadStreamRef stream, void* context)
-{
-    FormStreamFields* form = static_cast<FormStreamFields*>(context);
-
-    getStreamFormDatas().remove(stream);
-
-    closeCurrentStream(form);
-    CFRelease(form->scheduledRunLoopPairs);
-    delete form;
-}
-
-static Boolean formOpen(CFReadStreamRef stream, CFStreamError* error, Boolean* openComplete, void* context)
-{
-    FormStreamFields* form = static_cast<FormStreamFields*>(context);
-
-    openNextStream(form);
-
-    *openComplete = TRUE;
-    error->error = 0;
-    return TRUE;
-}
-
-static CFIndex formRead(CFReadStreamRef stream, UInt8* buffer, CFIndex bufferLength, CFStreamError* error, Boolean* atEOF, void* context)
-{
-    FormStreamFields* form = static_cast<FormStreamFields*>(context);
-
-    while (form->currentStream) {
-        CFIndex bytesRead = CFReadStreamRead(form->currentStream, buffer, bufferLength);
-        if (bytesRead < 0) {
-            *error = CFReadStreamGetError(form->currentStream);
-            return -1;
-        }
-        if (bytesRead > 0) {
-            error->error = 0;
-            *atEOF = FALSE;
-            return bytesRead;
-        }
-        openNextStream(form);
-    }
-
-    error->error = 0;
-    *atEOF = TRUE;
-    return 0;
-}
-
-static Boolean formCanRead(CFReadStreamRef stream, void* context)
-{
-    FormStreamFields* form = static_cast<FormStreamFields*>(context);
-
-    while (form->currentStream && CFReadStreamGetStatus(form->currentStream) == kCFStreamStatusAtEnd) {
-        openNextStream(form);
-    }
-    if (!form->currentStream) {
-        CFReadStreamSignalEvent(stream, kCFStreamEventEndEncountered, 0);
-        return FALSE;
-    }
-    return CFReadStreamHasBytesAvailable(form->currentStream);
-}
-
-static void formClose(CFReadStreamRef stream, void* context)
-{
-    FormStreamFields* form = static_cast<FormStreamFields*>(context);
-
-    closeCurrentStream(form);
-}
-
-static void formSchedule(CFReadStreamRef stream, CFRunLoopRef runLoop, CFStringRef runLoopMode, void* context)
-{
-    FormStreamFields* form = static_cast<FormStreamFields*>(context);
-
-    if (form->currentStream)
-        CFReadStreamScheduleWithRunLoop(form->currentStream, runLoop, runLoopMode);
-    SchedulePair pair = { runLoop, runLoopMode };
-    CFSetAddValue(form->scheduledRunLoopPairs, &pair);
-}
-
-static void formUnschedule(CFReadStreamRef stream, CFRunLoopRef runLoop, CFStringRef runLoopMode, void* context)
-{
-    FormStreamFields* form = static_cast<FormStreamFields*>(context);
-
-    if (form->currentStream)
-        CFReadStreamUnscheduleFromRunLoop(form->currentStream, runLoop, runLoopMode);
-    SchedulePair pair = { runLoop, runLoopMode };
-    CFSetRemoveValue(form->scheduledRunLoopPairs, &pair);
-}
-
-static void formEventCallback(CFReadStreamRef stream, CFStreamEventType type, void* context)
-{
-    FormStreamFields* form = static_cast<FormStreamFields*>(context);
-
-    switch (type) {
-    case kCFStreamEventHasBytesAvailable:
-        CFReadStreamSignalEvent(form->formStream, kCFStreamEventHasBytesAvailable, 0);
-        break;
-    case kCFStreamEventErrorOccurred: {
-        CFStreamError readStreamError = CFReadStreamGetError(stream);
-        CFReadStreamSignalEvent(form->formStream, kCFStreamEventErrorOccurred, &readStreamError);
-        break;
-    }
-    case kCFStreamEventEndEncountered:
-        openNextStream(form);
-        if (!form->currentStream)
-            CFReadStreamSignalEvent(form->formStream, kCFStreamEventEndEncountered, 0);
-        break;
-    case kCFStreamEventNone:
-        LOG_ERROR("unexpected kCFStreamEventNone");
-        break;
-    case kCFStreamEventOpenCompleted:
-        LOG_ERROR("unexpected kCFStreamEventOpenCompleted");
-        break;
-    case kCFStreamEventCanAcceptBytes:
-        LOG_ERROR("unexpected kCFStreamEventCanAcceptBytes");
-        break;
-    }
-}
-
 void setHTTPBody(CFMutableURLRequestRef request, PassRefPtr<FormData> formData)
 {
     if (!formData) {