| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef WEBKIT_FILEAPI_QUOTA_FILE_UTIL_H_ | 5 #ifndef WEBKIT_FILEAPI_QUOTA_FILE_UTIL_H_ |
| 6 #define WEBKIT_FILEAPI_QUOTA_FILE_UTIL_H_ | 6 #define WEBKIT_FILEAPI_QUOTA_FILE_UTIL_H_ |
| 7 | 7 |
| 8 #include "base/memory/scoped_ptr.h" |
| 8 #include "webkit/fileapi/file_system_file_util.h" | 9 #include "webkit/fileapi/file_system_file_util.h" |
| 9 #include "webkit/fileapi/file_system_operation_context.h" | 10 #include "webkit/fileapi/file_system_operation_context.h" |
| 10 #pragma once | 11 #pragma once |
| 11 | 12 |
| 12 namespace fileapi { | 13 namespace fileapi { |
| 13 | 14 |
| 14 class QuotaFileUtil : public FileSystemFileUtil { | 15 class QuotaFileUtil : public FileSystemFileUtil { |
| 15 public: | 16 public: |
| 16 static QuotaFileUtil* GetInstance(); | 17 static const int64 kNoLimit; |
| 17 virtual ~QuotaFileUtil() {} | |
| 18 | 18 |
| 19 static const int64 kNoLimit; | 19 // |underlying_file_util| is owned by the instance. It will be deleted by |
| 20 // the owner instance. For example, it can be instanciated as follows: |
| 21 // FileSystemFileUtil* file_util = new QuotaFileUtil(new SomeFileUtil()); |
| 22 // |
| 23 // To instanciate an object whose underlying file_util is FileSystemFileUtil, |
| 24 // QuotaFileUtil::CreateDefault() can be used. |
| 25 explicit QuotaFileUtil(FileSystemFileUtil* underlying_file_util); |
| 26 virtual ~QuotaFileUtil(); |
| 27 |
| 28 // Creates a QuotaFileUtil instance with an underlying FileSystemFileUtil |
| 29 // instance. |
| 30 static QuotaFileUtil* CreateDefault(); |
| 20 | 31 |
| 21 // TODO(dmikurube): Make this function variable by the constructor. | 32 // TODO(dmikurube): Make this function variable by the constructor. |
| 22 int64 ComputeFilePathCost(const FilePath& file_path) const; | 33 int64 ComputeFilePathCost(const FilePath& file_path) const; |
| 23 | 34 |
| 24 virtual base::PlatformFileError CreateOrOpen( | 35 virtual base::PlatformFileError CreateOrOpen( |
| 25 FileSystemOperationContext* fs_context, | 36 FileSystemOperationContext* fs_context, |
| 26 const FilePath& file_path, int file_flags, | 37 const FilePath& file_path, int file_flags, |
| 27 PlatformFile* file_handle, bool* created) OVERRIDE; | 38 PlatformFile* file_handle, bool* created) OVERRIDE; |
| 28 | 39 |
| 29 virtual base::PlatformFileError EnsureFileExists( | 40 virtual base::PlatformFileError EnsureFileExists( |
| (...skipping 19 matching lines...) Expand all Loading... |
| 49 | 60 |
| 50 virtual base::PlatformFileError DeleteSingleDirectory( | 61 virtual base::PlatformFileError DeleteSingleDirectory( |
| 51 FileSystemOperationContext* fs_context, | 62 FileSystemOperationContext* fs_context, |
| 52 const FilePath& file_path) OVERRIDE; | 63 const FilePath& file_path) OVERRIDE; |
| 53 | 64 |
| 54 virtual base::PlatformFileError Truncate( | 65 virtual base::PlatformFileError Truncate( |
| 55 FileSystemOperationContext* fs_context, | 66 FileSystemOperationContext* fs_context, |
| 56 const FilePath& path, | 67 const FilePath& path, |
| 57 int64 length) OVERRIDE; | 68 int64 length) OVERRIDE; |
| 58 | 69 |
| 59 friend struct DefaultSingletonTraits<QuotaFileUtil>; | 70 private: |
| 60 DISALLOW_COPY_AND_ASSIGN(QuotaFileUtil); | 71 scoped_ptr<FileSystemFileUtil> underlying_file_util_; |
| 61 | 72 |
| 62 protected: | |
| 63 QuotaFileUtil() {} | |
| 64 | |
| 65 private: | |
| 66 // TODO(dmikurube): Make these constants variable by the constructor. | 73 // TODO(dmikurube): Make these constants variable by the constructor. |
| 67 // | 74 // |
| 68 // These values are based on Obfuscation DB. See crbug.com/86114 for the | 75 // These values are based on Obfuscation DB. See crbug.com/86114 for the |
| 69 // source of these numbers. These should be revisited if | 76 // source of these numbers. These should be revisited if |
| 70 // * the underlying tables change, | 77 // * the underlying tables change, |
| 71 // * indexes in levelDB change, or | 78 // * indexes in levelDB change, or |
| 72 // * another path name indexer is provided in addition to levelDB. | 79 // * another path name indexer is provided in addition to levelDB. |
| 73 // | 80 // |
| 74 // When these values are changed, the usage cache should be bumped up. | 81 // When these values are changed, the usage cache should be bumped up. |
| 75 static const int64 kFilePathCostPerChar; | 82 static const int64 kFilePathCostPerChar; |
| 76 static const int64 kFilePathCostPerFile; | 83 static const int64 kFilePathCostPerFile; |
| 77 | 84 |
| 78 bool CanCopyFile( | 85 bool CanCopyFile( |
| 79 FileSystemOperationContext* fs_context, | 86 FileSystemOperationContext* fs_context, |
| 80 const FilePath& src_file_path, | 87 const FilePath& src_file_path, |
| 81 const FilePath& dest_file_path, | 88 const FilePath& dest_file_path, |
| 82 int64 allowed_bytes_growth, | 89 int64 allowed_bytes_growth, |
| 83 int64* growth) const; | 90 int64* growth) const; |
| 91 |
| 92 DISALLOW_COPY_AND_ASSIGN(QuotaFileUtil); |
| 84 }; | 93 }; |
| 85 | 94 |
| 86 } // namespace fileapi | 95 } // namespace fileapi |
| 87 | 96 |
| 88 #endif // WEBKIT_FILEAPI_QUOTA_FILE_UTIL_H_ | 97 #endif // WEBKIT_FILEAPI_QUOTA_FILE_UTIL_H_ |
| OLD | NEW |