Add memory space check routine before saving web storage data
authorJiyeon Kim <jiyeon0402.kim@samsung.com>
Mon, 14 Oct 2013 07:03:11 +0000 (16:03 +0900)
committereojin.ham <eojin.ham@samsung.com>
Tue, 15 Oct 2013 00:58:38 +0000 (09:58 +0900)
[Title] Add memory space check routine before saving web storage data
[Issue#] N_SE-51170
[Problem] Add time and Add custom Workout delete automatically when reopen the sample ExercisePlanner
[Cause] If phone memory reach low memory, web application cannot save any data and doesn't throuw any error
[Solution] Add memory space before saving web storage data and throw QUATA_EXCEEDED_ERR if there is not enough memory in Phone

Change-Id: Ib93534fe56f48dce0df26c4d25c173dd62c1f53a

Source/WebCore/platform/FileSystem.h
Source/WebCore/platform/efl/tizen/FileSystemTizen.cpp
Source/WebCore/storage/StorageAreaImpl.cpp

index 867f820..4097fdf 100644 (file)
@@ -232,6 +232,7 @@ bool safeCreateFile(const String&, CFDataRef);
 
 #if ENABLE(TIZEN_FILE_SYSTEM)
 bool copyFile(const String& sourcePath, const String& destinationPath);
+bool haveEnoughSpace(const String& path, unsigned requestSize);
 bool getDirectorySize(const String& path, long long& size);
 bool linkFile(const String& sourcePath, const String& destinationPath);
 bool removeDirectory(const String& path);
index 1d84bb8..7ae49f1 100644 (file)
@@ -35,6 +35,7 @@
 #include <fcntl.h>
 #include <stdio.h>
 #include <sys/stat.h>
+#include <sys/statvfs.h>
 #include <unistd.h>
 #include <wtf/text/CString.h>
 
@@ -135,5 +136,15 @@ bool renameFile(const String& sourcePath, const String& destinationPath)
     return !rename(fsRepSource.data(), fsRepDestination.data());
 }
 
+bool haveEnoughSpace(const String& path, unsigned requestSize)
+{
+    struct statvfs buf;
+    if (!statvfs(path.utf8().data(), &buf)) {
+        unsigned long availableSize = buf.f_bavail * buf.f_bsize;
+        if (availableSize > requestSize)
+            return true;
+    }
+    return false;
+}
 }
 #endif
index 694a97a..41d174d 100644 (file)
 #include "StorageTracker.h"
 #include <wtf/MainThread.h>
 
+#if ENABLE(TIZEN_WEB_STORAGE)
+#include "FileSystem.h"
+#endif
+
 namespace WebCore {
 
 StorageAreaImpl::~StorageAreaImpl()
@@ -164,6 +168,13 @@ void StorageAreaImpl::setItem(const String& key, const String& value, ExceptionC
     if (oldValue == value)
         return;
 
+#if ENABLE(TIZEN_WEB_STORAGE)
+    if (!haveEnoughSpace(m_storageSyncManager->fullDatabaseFilename(m_securityOrigin->databaseIdentifier()), key.length() + value.length())) {
+        ec = QUOTA_EXCEEDED_ERR;
+        return;
+    }
+#endif
+
     if (m_storageAreaSync)
         m_storageAreaSync->scheduleItemForSync(key, value);
     StorageEventDispatcher::dispatch(key, oldValue, value, m_storageType, m_securityOrigin.get(), frame);