Changeset 68735 in webkit


Ignore:
Timestamp:
Sep 29, 2010 6:16:43 PM (14 years ago)
Author:
kinuko@chromium.org
Message:

2010-09-29 Kinuko Yasuda <kinuko@chromium.org>

Reviewed by David Levin.

Fix DirectoryReader's behavior to trigger only one EntriesCallback per readEntries
https://bugs.webkit.org/show_bug.cgi?id=46563

  • src/WebFileSystemCallbacksImpl.cpp: (WebKit::WebFileSystemCallbacksImpl::didReadDirectory):

2010-09-29 Kinuko Yasuda <kinuko@chromium.org>

Reviewed by David Levin.

Fix DirectoryReader's behavior to trigger only one EntriesCallback per readEntries
https://bugs.webkit.org/show_bug.cgi?id=46563

Test: fast/filesystem/read-directory.html

  • fileapi/DOMFileSystem.cpp: (WebCore::DOMFileSystem::readDirectory): Changed to take DirectoryReader as a parameter.
  • fileapi/DOMFileSystem.h: (WebCore::DOMFileSystem::scheduleCallback): Added.
  • fileapi/DirectoryReader.cpp: (WebCore::DirectoryReader::DirectoryReader): Added initializer for m_hasMore flag. (WebCore::DirectoryReader::readEntries): Changed to schedule EntriesCallback with an empty array if m_hasMore flag is set false.
  • fileapi/DirectoryReader.h: (WebCore::DirectoryReader::filesystem): Added. (WebCore::DirectoryReader::setHasMore): Added.
  • fileapi/FileSystemCallbacks.cpp: (WebCore::EntriesCallbacks::create): (WebCore::EntriesCallbacks::EntriesCallbacks): Changed to take DirectoryReader as a parameter. (WebCore::EntriesCallbacks::didReadDirectoryEntry): (WebCore::EntriesCallbacks::didReadDirectoryEntries): Changed 1) not to trigger the second callback when hasMore is false, and 2) to update the DirectoryReader's m_hasMore flag.
  • fileapi/FileSystemCallbacks.h:

2010-09-29 Kinuko Yasuda <kinuko@chromium.org>

Reviewed by David Levin.

Fix DirectoryReader's behavior to trigger only one EntriesCallback per readEntries
https://bugs.webkit.org/show_bug.cgi?id=46563

  • fast/filesystem/flags-passing.html: Updated to make it match with the updated TEMPLATE.html.
  • fast/filesystem/flags-passing-expected.txt: Updated.
  • fast/filesystem/read-directory.html: Added.
  • fast/filesystem/read-directory-expected.txt: Added.
  • fast/filesystem/resources/fs-test-util.js: Added for common test utilities.
  • fast/filesystem/script-tests/TEMPLATE.html: Updated to include fs-test-util.js.
  • fast/filesystem/script-tests/flags-passing.js: Updated to use jsTestIsAsync and finishJSTest (so that all the tests look alike).
  • fast/filesystem/script-tests/read-directory.js: Added.
Location:
trunk
Files:
5 added
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r68733 r68735  
     12010-09-29  Kinuko Yasuda  <kinuko@chromium.org>
     2
     3        Reviewed by David Levin.
     4
     5        Fix DirectoryReader's behavior to trigger only one EntriesCallback per readEntries
     6        https://bugs.webkit.org/show_bug.cgi?id=46563
     7
     8        * fast/filesystem/flags-passing.html: Updated to make it match
     9        with the updated TEMPLATE.html.
     10        * fast/filesystem/flags-passing-expected.txt: Updated.
     11        * fast/filesystem/read-directory.html: Added.
     12        * fast/filesystem/read-directory-expected.txt: Added.
     13        * fast/filesystem/resources/fs-test-util.js: Added for common test
     14        utilities.
     15        * fast/filesystem/script-tests/TEMPLATE.html: Updated to include
     16        fs-test-util.js.
     17        * fast/filesystem/script-tests/flags-passing.js: Updated to use
     18        jsTestIsAsync and finishJSTest (so that all the tests look alike).
     19        * fast/filesystem/script-tests/read-directory.js: Added.
     20
    1212010-09-29  MORITA Hajime  <morrita@google.com>
    222
  • trunk/LayoutTests/fast/filesystem/flags-passing-expected.txt

    r68105 r68735  
    44
    55
    6 PASS successfullyParsed is true
    7 
    8 TEST COMPLETE
    96* Passing a Flags object.
    107* Recycling the same Flags object.
     
    1512PASS expectedCallbacksCount is 3
    1613PASS unexpectedCallbacksCount is 0
     14PASS successfullyParsed is true
    1715
     16TEST COMPLETE
     17
  • trunk/LayoutTests/fast/filesystem/flags-passing.html

    r68105 r68735  
    33<link rel="stylesheet" href="../js/resources/js-test-style.css">
    44<script src="../js/resources/js-test-pre.js"></script>
     5<script src="resources/fs-test-util.js"></script>
    56</head>
    67<body>
  • trunk/LayoutTests/fast/filesystem/script-tests/TEMPLATE.html

    r68105 r68735  
    33<link rel="stylesheet" href="../js/resources/js-test-style.css">
    44<script src="../js/resources/js-test-pre.js"></script>
     5<script src="resources/fs-test-util.js"></script>
    56</head>
    67<body>
  • trunk/LayoutTests/fast/filesystem/script-tests/flags-passing.js

    r68105 r68735  
    1717var testCounter = 0;
    1818
    19 function endTest() {
    20     debug("Finished running tests.");
    21     shouldBe('expectedCallbacksCount', '3');
    22     shouldBe('unexpectedCallbacksCount', '0');
    23     if (window.layoutTestController)
    24         layoutTestController.notifyDone();
    25 }
    26 
    2719function runNextTest(v) {
    28     if (testCounter == testsList.length)
    29         endTest();
    30     else
     20    if (testCounter == testsList.length) {
     21        debug("Finished running tests.");
     22        shouldBe('expectedCallbacksCount', '3');
     23        shouldBe('unexpectedCallbacksCount', '0');
     24        finishJSTest();
     25    } else
    3126        this[testsList[testCounter++]]();
    3227}
     
    3429function errorCallback(error) {
    3530    debug("Error occured during requesting Temporary FileSystem:" + error.code);
    36 
    37     if (window.layoutTestController)
    38         layoutTestController.notifyDone();
     31    finishJSTest();
    3932}
    4033
     
    9487
    9588if (window.requestFileSystem) {
    96     if (window.layoutTestController)
    97         layoutTestController.waitUntilDone();
    98 
    9989    requestFileSystem(window.TEMPORARY, 100, fileSystemCallback, errorCallback);
     90    window.jsTestIsAsync = true;
    10091} else
    10192    debug("This test requires FileSystem API support.");
    10293
    103 var successfullyParsed = true;
     94window.successfullyParsed = true;
  • trunk/WebCore/ChangeLog

    r68734 r68735  
     12010-09-29  Kinuko Yasuda  <kinuko@chromium.org>
     2
     3        Reviewed by David Levin.
     4
     5        Fix DirectoryReader's behavior to trigger only one EntriesCallback per readEntries
     6        https://bugs.webkit.org/show_bug.cgi?id=46563
     7
     8        Test: fast/filesystem/read-directory.html
     9
     10        * fileapi/DOMFileSystem.cpp:
     11        (WebCore::DOMFileSystem::readDirectory): Changed to take DirectoryReader
     12        as a parameter.
     13        * fileapi/DOMFileSystem.h:
     14        (WebCore::DOMFileSystem::scheduleCallback): Added.
     15        * fileapi/DirectoryReader.cpp:
     16        (WebCore::DirectoryReader::DirectoryReader): Added initializer for
     17        m_hasMore flag.
     18        (WebCore::DirectoryReader::readEntries): Changed to schedule
     19        EntriesCallback with an empty array if m_hasMore flag is set false.
     20        * fileapi/DirectoryReader.h:
     21        (WebCore::DirectoryReader::filesystem): Added.
     22        (WebCore::DirectoryReader::setHasMore): Added.
     23        * fileapi/FileSystemCallbacks.cpp:
     24        (WebCore::EntriesCallbacks::create):
     25        (WebCore::EntriesCallbacks::EntriesCallbacks): Changed to take
     26        DirectoryReader as a parameter.
     27        (WebCore::EntriesCallbacks::didReadDirectoryEntry):
     28        (WebCore::EntriesCallbacks::didReadDirectoryEntries): Changed 1) not to
     29        trigger the second callback when hasMore is false, and 2) to update
     30        the DirectoryReader's m_hasMore flag.
     31        * fileapi/FileSystemCallbacks.h:
     32
    1332010-09-29  Chris Rogers  <crogers@google.com>
    234
  • trunk/WebCore/bindings/v8/custom/V8DirectoryEntryCustom.cpp

    r68105 r68735  
    7171        }
    7272    } else {
    73        EXCEPTION_BLOCK(Flags*, tmp_flags, V8Flags::HasInstance(args[1]) ? V8Flags::toNative(v8::Handle<v8::Object>::Cast(args[1])) : 0);
    74        flags = tmp_flags;
     73        EXCEPTION_BLOCK(Flags*, tmp_flags, V8Flags::HasInstance(args[1]) ? V8Flags::toNative(v8::Handle<v8::Object>::Cast(args[1])) : 0);
     74        flags = tmp_flags;
    7575    }
    7676    RefPtr<EntryCallback> successCallback;
  • trunk/WebCore/fileapi/DOMFileSystem.cpp

    r68411 r68735  
    215215}
    216216
    217 void DOMFileSystem::readDirectory(const String& path, PassRefPtr<EntriesCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback)
     217void DOMFileSystem::readDirectory(DirectoryReader* reader, const String& path, PassRefPtr<EntriesCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback)
    218218{
    219219    ASSERT(DOMFilePath::isAbsolute(path));
    220220    String platformPath = m_asyncFileSystem->virtualToPlatformPath(path);
    221     m_asyncFileSystem->readDirectory(platformPath, EntriesCallbacks::create(successCallback, errorCallback, this, path));
     221    m_asyncFileSystem->readDirectory(platformPath, EntriesCallbacks::create(successCallback, errorCallback, reader, path));
    222222}
    223223
  • trunk/WebCore/fileapi/DOMFileSystem.h

    r68101 r68735  
    4545
    4646class DirectoryEntry;
     47class DirectoryReader;
    4748class Entry;
    4849class EntryCallback;
     
    7980    void getFile(const Entry* base, const String& path, PassRefPtr<Flags>, PassRefPtr<EntryCallback>, PassRefPtr<ErrorCallback>);
    8081    void getDirectory(const Entry* base, const String& path, PassRefPtr<Flags>, PassRefPtr<EntryCallback>, PassRefPtr<ErrorCallback>);
    81     void readDirectory(const String& path, PassRefPtr<EntriesCallback>, PassRefPtr<ErrorCallback>);
     82    void readDirectory(DirectoryReader* reader, const String& path, PassRefPtr<EntriesCallback>, PassRefPtr<ErrorCallback>);
    8283    void createWriter(const FileEntry* file, PassRefPtr<FileWriterCallback>, PassRefPtr<ErrorCallback>);
    8384
    8485    // Schedule a callback. This should not cross threads (should be called on the same context thread).
     86    // FIXME: move this to a more generic place.
    8587    template <typename CB, typename CBArg>
    8688    static void scheduleCallback(ScriptExecutionContext*, PassRefPtr<CB>, PassRefPtr<CBArg>);
     89
     90    template <typename CB, typename CBArg>
     91    void scheduleCallback(PassRefPtr<CB> callback, PassRefPtr<CBArg> callbackArg)
     92    {
     93        scheduleCallback(scriptExecutionContext(), callback, callbackArg);
     94    }
    8795
    8896private:
  • trunk/WebCore/fileapi/DirectoryReader.cpp

    r66586 r68735  
    3636#include "DOMFileSystem.h"
    3737#include "EntriesCallback.h"
     38#include "EntryArray.h"
    3839#include "ErrorCallback.h"
    3940
     
    4344    : m_fileSystem(fileSystem)
    4445    , m_fullPath(fullPath)
     46    , m_hasMore(true)
    4547{
    4648}
     
    4850void DirectoryReader::readEntries(PassRefPtr<EntriesCallback> entriesCallback, PassRefPtr<ErrorCallback> errorCallback)
    4951{
    50     m_fileSystem->readDirectory(m_fullPath, entriesCallback, errorCallback);
     52    if (!m_hasMore) {
     53        m_fileSystem->scheduleCallback(entriesCallback, EntryArray::create());
     54        return;
     55    }
     56    m_fileSystem->readDirectory(this, m_fullPath, entriesCallback, errorCallback);
    5157}
    5258
  • trunk/WebCore/fileapi/DirectoryReader.h

    r66586 r68735  
    4242
    4343class EntriesCallback;
     44class EntriesCallbacks;
    4445class ErrorCallback;
    4546
     
    5152    }
    5253
    53     void readEntries(PassRefPtr<EntriesCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback = 0);
     54    DOMFileSystem* filesystem() const { return m_fileSystem.get(); }
     55    void readEntries(PassRefPtr<EntriesCallback>, PassRefPtr<ErrorCallback> = 0);
     56    void setHasMore(bool hasMore) { m_hasMore = hasMore; }
    5457
    5558private:
     
    5861    RefPtr<DOMFileSystem> m_fileSystem;
    5962    String m_fullPath;
     63    bool m_hasMore;
    6064};
    6165
  • trunk/WebCore/fileapi/FileSystemCallbacks.cpp

    r68411 r68735  
    3939#include "DOMFileSystem.h"
    4040#include "DirectoryEntry.h"
     41#include "DirectoryReader.h"
    4142#include "EntriesCallback.h"
    4243#include "EntryArray.h"
     
    138139// EntriesCallbacks -----------------------------------------------------------
    139140
    140 PassOwnPtr<EntriesCallbacks> EntriesCallbacks::create(PassRefPtr<EntriesCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback, DOMFileSystem* fileSystem, const String& basePath)
    141 {
    142     return adoptPtr(new EntriesCallbacks(successCallback, errorCallback, fileSystem, basePath));
    143 }
    144 
    145 EntriesCallbacks::EntriesCallbacks(PassRefPtr<EntriesCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback, DOMFileSystem* fileSystem, const String& basePath)
    146     : FileSystemCallbacksBase(errorCallback)
    147     , m_successCallback(successCallback)
    148     , m_fileSystem(fileSystem)
     141PassOwnPtr<EntriesCallbacks> EntriesCallbacks::create(PassRefPtr<EntriesCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback, DirectoryReader* directoryReader, const String& basePath)
     142{
     143    return adoptPtr(new EntriesCallbacks(successCallback, errorCallback, directoryReader, basePath));
     144}
     145
     146EntriesCallbacks::EntriesCallbacks(PassRefPtr<EntriesCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback, DirectoryReader* directoryReader, const String& basePath)
     147    : FileSystemCallbacksBase(errorCallback)
     148    , m_successCallback(successCallback)
     149    , m_directoryReader(directoryReader)
    149150    , m_basePath(basePath)
    150151    , m_entries(EntryArray::create())
    151152{
     153    ASSERT(m_directoryReader);
    152154}
    153155
     
    155157{
    156158    if (isDirectory)
    157         m_entries->append(DirectoryEntry::create(m_fileSystem, DOMFilePath::append(m_basePath, name)));
     159        m_entries->append(DirectoryEntry::create(m_directoryReader->filesystem(), DOMFilePath::append(m_basePath, name)));
    158160    else
    159         m_entries->append(FileEntry::create(m_fileSystem, DOMFilePath::append(m_basePath, name)));
     161        m_entries->append(FileEntry::create(m_directoryReader->filesystem(), DOMFilePath::append(m_basePath, name)));
    160162}
    161163
    162164void EntriesCallbacks::didReadDirectoryEntries(bool hasMore)
    163165{
    164     if (m_successCallback) {
     166    m_directoryReader->setHasMore(hasMore);
     167    if (m_successCallback)
    165168        m_successCallback->handleEvent(m_entries.get());
    166         if (!m_entries->isEmpty() && !hasMore) {
    167             // If we have returned some entries and there're no more coming entries (hasMore==false), call back once more with an empty array.
    168             m_successCallback->handleEvent(EntryArray::create().get());
    169             m_successCallback.clear();
    170         }
    171         m_entries->clear();
    172     }
    173169}
    174170
  • trunk/WebCore/fileapi/FileSystemCallbacks.h

    r68411 r68735  
    4343class AsyncFileWriter;
    4444class DOMFileSystem;
     45class DirectoryReader;
    4546class ErrorCallback;
    4647class EntriesCallback;
     
    99100class EntriesCallbacks : public FileSystemCallbacksBase {
    100101public:
    101     static PassOwnPtr<EntriesCallbacks> create(PassRefPtr<EntriesCallback>, PassRefPtr<ErrorCallback>, DOMFileSystem*, const String& basePath);
     102    static PassOwnPtr<EntriesCallbacks> create(PassRefPtr<EntriesCallback>, PassRefPtr<ErrorCallback>, DirectoryReader*, const String& basePath);
    102103    virtual void didReadDirectoryEntry(const String& name, bool isDirectory);
    103104    virtual void didReadDirectoryEntries(bool hasMore);
    104105
    105106private:
    106     EntriesCallbacks(PassRefPtr<EntriesCallback>, PassRefPtr<ErrorCallback>, DOMFileSystem*, const String& basePath);
     107    EntriesCallbacks(PassRefPtr<EntriesCallback>, PassRefPtr<ErrorCallback>, DirectoryReader*, const String& basePath);
    107108    RefPtr<EntriesCallback> m_successCallback;
    108     DOMFileSystem* m_fileSystem;
     109    DirectoryReader* m_directoryReader;
    109110    String m_basePath;
    110111    RefPtr<EntryArray> m_entries;
  • trunk/WebKit/chromium/ChangeLog

    r68700 r68735  
     12010-09-29  Kinuko Yasuda  <kinuko@chromium.org>
     2
     3        Reviewed by David Levin.
     4
     5        Fix DirectoryReader's behavior to trigger only one EntriesCallback per readEntries
     6        https://bugs.webkit.org/show_bug.cgi?id=46563
     7
     8        * src/WebFileSystemCallbacksImpl.cpp:
     9        (WebKit::WebFileSystemCallbacksImpl::didReadDirectory):
     10
    1112010-09-29  Tony Chang  <tony@chromium.org>
    212
  • trunk/WebKit/chromium/src/WebFileSystemCallbacksImpl.cpp

    r68669 r68735  
    7474        m_callbacks->didReadDirectoryEntry(entries[i].name, entries[i].isDirectory);
    7575    m_callbacks->didReadDirectoryEntries(hasMore);
    76     if (!hasMore)
    77         delete this;
     76    delete this;
    7877}
    7978
Note: See TracChangeset for help on using the changeset viewer.