Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1580)

Unified Diff: Source/modules/filesystem/SyncCallbackHelper.h

Issue 22673003: Replace EntryArraySync type by an EntrySync[] (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Use traits classes to simplify the code Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/modules/filesystem/EntryArraySync.idl ('k') | Source/modules/modules.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/modules/filesystem/SyncCallbackHelper.h
diff --git a/Source/modules/filesystem/SyncCallbackHelper.h b/Source/modules/filesystem/SyncCallbackHelper.h
index 7ef045d065dd128df8caf1e84e3e67eeec851ced..c1eedc7a9efa3f6903056bd667a4de61526f2204 100644
--- a/Source/modules/filesystem/SyncCallbackHelper.h
+++ b/Source/modules/filesystem/SyncCallbackHelper.h
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2010 Google Inc. All rights reserved.
+ * Copyright (C) 2013 Samsung Electronics. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
@@ -35,9 +36,10 @@
#include "core/fileapi/FileError.h"
#include "core/html/VoidCallback.h"
#include "modules/filesystem/DirectoryEntry.h"
+#include "modules/filesystem/DirectoryReaderSync.h"
#include "modules/filesystem/EntriesCallback.h"
-#include "modules/filesystem/EntryArraySync.h"
#include "modules/filesystem/EntryCallback.h"
+#include "modules/filesystem/EntrySync.h"
#include "modules/filesystem/ErrorCallback.h"
#include "modules/filesystem/FileEntry.h"
#include "modules/filesystem/FileSystemCallback.h"
@@ -47,11 +49,32 @@
namespace WebCore {
-class AsyncFileSystem;
-class DirectoryEntrySync;
-class EntryArraySync;
-class EntrySync;
-class FileEntrySync;
+template <typename ResultType, typename CallbackArg>
+struct HelperResultType {
kinuko 2013/08/09 02:15:54 nit: these helper classes can be in an anonymous n
do-not-use 2013/08/09 06:39:21 This would apparently be against coding style: "So
+ typedef PassRefPtr<ResultType> ReturnType;
+ typedef RefPtr<ResultType> StorageType;
+
+ static ReturnType createFromCallbackArg(CallbackArg argument)
+ {
+ return ResultType::create(argument);
+ }
+};
+
+template <>
+struct HelperResultType<EntrySyncVector, const EntryVector&> {
+ typedef EntrySyncVector ReturnType;
+ typedef EntrySyncVector StorageType;
+
+ static EntrySyncVector createFromCallbackArg(const EntryVector& entries)
+ {
+ EntrySyncVector result;
+ size_t entryCount = entries.size();
+ result.reserveInitialCapacity(entryCount);
+ for (size_t i = 0; i < entryCount; ++i)
+ result.uncheckedAppend(EntrySync::create(entries[i].get()));
+ return result;
+ }
+};
// A helper template for FileSystemSync implementation.
template <typename SuccessCallback, typename ObserverType, typename CallbackArg, typename ResultType>
@@ -59,6 +82,10 @@ class SyncCallbackHelper {
WTF_MAKE_NONCOPYABLE(SyncCallbackHelper);
public:
typedef SyncCallbackHelper<SuccessCallback, ObserverType, CallbackArg, ResultType> HelperType;
+ typedef HelperResultType<ResultType, CallbackArg> ResultTypeTrait;
+ typedef typename ResultTypeTrait::StorageType ResultStorageType;
+ typedef typename ResultTypeTrait::ReturnType ResultReturnType;
+
SyncCallbackHelper(ObserverType* observer = 0)
: m_observer(observer)
, m_successCallback(SuccessCallbackImpl::create(this))
@@ -68,7 +95,7 @@ public:
{
}
- PassRefPtr<ResultType> getResult(ExceptionState& es)
+ ResultReturnType getResult(ExceptionState& es)
{
if (m_observer) {
while (!m_completed) {
@@ -81,7 +108,7 @@ public:
if (m_errorCode)
FileError::throwDOMException(es, m_errorCode);
- return m_result.release();
+ return m_result;
}
PassRefPtr<SuccessCallback> successCallback() { return m_successCallback; }
@@ -103,7 +130,7 @@ private:
virtual bool handleEvent(CallbackArg arg)
{
- m_helper->setResult(ResultType::create(arg));
+ m_helper->setResult(arg);
return true;
}
@@ -146,16 +173,16 @@ private:
m_completed = true;
}
- void setResult(PassRefPtr<ResultType> result)
+ void setResult(CallbackArg result)
{
- m_result = result;
+ m_result = ResultTypeTrait::createFromCallbackArg(result);
m_completed = true;
}
ObserverType* m_observer;
RefPtr<SuccessCallbackImpl> m_successCallback;
RefPtr<ErrorCallbackImpl> m_errorCallback;
- RefPtr<ResultType> m_result;
+ ResultStorageType m_result;
FileError::ErrorCode m_errorCode;
bool m_completed;
};
@@ -175,7 +202,7 @@ struct EmptyObserverType {
};
typedef SyncCallbackHelper<EntryCallback, AsyncFileSystem, Entry*, EntrySync> EntrySyncCallbackHelper;
-typedef SyncCallbackHelper<EntriesCallback, AsyncFileSystem, const EntryVector&, EntryArraySync> EntriesSyncCallbackHelper;
+typedef SyncCallbackHelper<EntriesCallback, AsyncFileSystem, const EntryVector&, EntrySyncVector> EntriesSyncCallbackHelper;
typedef SyncCallbackHelper<MetadataCallback, AsyncFileSystem, Metadata*, Metadata> MetadataSyncCallbackHelper;
typedef SyncCallbackHelper<VoidCallback, AsyncFileSystem, EmptyType*, EmptyType> VoidSyncCallbackHelper;
typedef SyncCallbackHelper<FileSystemCallback, EmptyObserverType, DOMFileSystem*, DOMFileSystemSync> FileSystemSyncCallbackHelper;
« no previous file with comments | « Source/modules/filesystem/EntryArraySync.idl ('k') | Source/modules/modules.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698