| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 STORAGE_COMMON_BLOB_STORAGE_BLOB_STORAGE_CONSTANTS_H_ | 5 #ifndef STORAGE_COMMON_BLOB_STORAGE_BLOB_STORAGE_CONSTANTS_H_ |
| 6 #define STORAGE_COMMON_BLOB_STORAGE_BLOB_STORAGE_CONSTANTS_H_ | 6 #define STORAGE_COMMON_BLOB_STORAGE_BLOB_STORAGE_CONSTANTS_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| 11 #include "base/callback_forward.h" |
| 12 #include "storage/common/storage_common_export.h" |
| 13 |
| 11 namespace storage { | 14 namespace storage { |
| 12 | 15 |
| 13 // TODO(michaeln): use base::SysInfo::AmountOfPhysicalMemoryMB() in some | 16 // All sizes are in bytes. Deprecated, please use BlobStorageLimits. |
| 14 // way to come up with a better limit. | |
| 15 const int64_t kBlobStorageMaxMemoryUsage = 500 * 1024 * 1024; // Half a gig. | 17 const int64_t kBlobStorageMaxMemoryUsage = 500 * 1024 * 1024; // Half a gig. |
| 16 const size_t kBlobStorageIPCThresholdBytes = 250 * 1024; | 18 const size_t kBlobStorageIPCThresholdBytes = 250 * 1024; |
| 17 const size_t kBlobStorageMaxSharedMemoryBytes = 10 * 1024 * 1024; | 19 const size_t kBlobStorageMaxSharedMemoryBytes = 10 * 1024 * 1024; |
| 18 const uint64_t kBlobStorageMaxFileSizeBytes = 100 * 1024 * 1024; | 20 const uint64_t kBlobStorageMaxFileSizeBytes = 100 * 1024 * 1024; |
| 19 const uint64_t kBlobStorageMinFileSizeBytes = 1 * 1024 * 1024; | 21 const uint64_t kBlobStorageMinFileSizeBytes = 1 * 1024 * 1024; |
| 20 const size_t kBlobStorageMaxBlobMemorySize = | 22 const size_t kBlobStorageMaxBlobMemorySize = |
| 21 kBlobStorageMaxMemoryUsage - kBlobStorageMinFileSizeBytes; | 23 kBlobStorageMaxMemoryUsage - kBlobStorageMinFileSizeBytes; |
| 22 | 24 |
| 25 // All sizes are in bytes. |
| 26 struct BlobStorageLimits { |
| 27 size_t memory_limit_before_paging() const { |
| 28 return max_blob_in_memory_space - min_page_file_size; |
| 29 } |
| 30 |
| 31 // This is the maximum amount of memory we can send in an IPC. |
| 32 size_t max_ipc_memory_size = 250 * 1024; |
| 33 // This is the maximum size of a shared memory handle. |
| 34 size_t max_shared_memory_size = 10 * 1024 * 1024; |
| 35 |
| 36 // This is the maximum amount of memory we can use to store blobs. |
| 37 size_t max_blob_in_memory_space = 500 * 1024 * 1024; |
| 38 |
| 39 // This is the maximum amount of disk space we can use. |
| 40 // TODO(dmurph): Consider storage size of the device. |
| 41 uint64_t max_blob_disk_space = 5ull * 1024 * 1024 * 1024; |
| 42 |
| 43 // This is the minimum file size we can use when paging blob items to disk. |
| 44 // We combine items until we reach at least this size. |
| 45 uint64_t min_page_file_size = 5 * 1024 * 1024; |
| 46 // This is the maximum file size we can create. |
| 47 uint64_t max_file_size = 100 * 1024 * 1024; |
| 48 }; |
| 49 |
| 23 enum class IPCBlobItemRequestStrategy { | 50 enum class IPCBlobItemRequestStrategy { |
| 24 UNKNOWN = 0, | 51 UNKNOWN = 0, |
| 25 IPC, | 52 IPC, |
| 26 SHARED_MEMORY, | 53 SHARED_MEMORY, |
| 27 FILE, | 54 FILE, |
| 28 LAST = FILE | 55 LAST = FILE |
| 29 }; | 56 }; |
| 30 | 57 |
| 31 // These items cannot be reordered or renumbered because they're recorded to | 58 // These items cannot be reordered or renumbered because they're recorded to |
| 32 // UMA. New items must be added immediately before LAST, and LAST must be set to | 59 // UMA. New items must be added immediately before LAST, and LAST must be set to |
| 33 // the the last item. | 60 // the the last item. |
| 61 // DEPRECATED, please use BlobStatus instead. |
| 34 enum class IPCBlobCreationCancelCode { | 62 enum class IPCBlobCreationCancelCode { |
| 35 UNKNOWN = 0, | 63 UNKNOWN = 0, |
| 36 OUT_OF_MEMORY = 1, | 64 OUT_OF_MEMORY = 1, |
| 37 // We couldn't create or write to a file. File system error, like a full disk. | 65 // We couldn't create or write to a file. File system error, like a full disk. |
| 38 FILE_WRITE_FAILED = 2, | 66 FILE_WRITE_FAILED = 2, |
| 39 // The renderer was destroyed while data was in transit. | 67 // The renderer was destroyed while data was in transit. |
| 40 SOURCE_DIED_IN_TRANSIT = 3, | 68 SOURCE_DIED_IN_TRANSIT = 3, |
| 41 // The renderer destructed the blob before it was done transferring, and there | 69 // The renderer destructed the blob before it was done transferring, and there |
| 42 // were no outstanding references (no one is waiting to read) to keep the | 70 // were no outstanding references (no one is waiting to read) to keep the |
| 43 // blob alive. | 71 // blob alive. |
| 44 BLOB_DEREFERENCED_WHILE_BUILDING = 4, | 72 BLOB_DEREFERENCED_WHILE_BUILDING = 4, |
| 45 // A blob that we referenced during construction is broken, or a browser-side | 73 // A blob that we referenced during construction is broken, or a browser-side |
| 46 // builder tries to build a blob with a blob reference that isn't finished | 74 // builder tries to build a blob with a blob reference that isn't finished |
| 47 // constructing. | 75 // constructing. |
| 48 REFERENCED_BLOB_BROKEN = 5, | 76 REFERENCED_BLOB_BROKEN = 5, |
| 49 LAST = REFERENCED_BLOB_BROKEN | 77 LAST = REFERENCED_BLOB_BROKEN |
| 50 }; | 78 }; |
| 51 | 79 |
| 80 // This is the enum to rule them all in the blob system. |
| 81 // These values are used in UMA metrics, so they should not be changed. Please |
| 82 // update LAST_ERROR if you add an error condition and LAST if you add new |
| 83 // state. |
| 84 enum class BlobStatus { |
| 85 // Error case section: |
| 86 // The construction arguments are invalid. This is considered a bad ipc. |
| 87 ERR_INVALID_CONSTRUCTION_ARGUMENTS = 0, |
| 88 // We don't have enough memory for the blob. |
| 89 ERR_OUT_OF_MEMORY = 1, |
| 90 // We couldn't create or write to a file. File system error, like a full disk. |
| 91 ERR_FILE_WRITE_FAILED = 2, |
| 92 // The renderer was destroyed while data was in transit. |
| 93 ERR_SOURCE_DIED_IN_TRANSIT = 3, |
| 94 // The renderer destructed the blob before it was done transferring, and there |
| 95 // were no outstanding references (no one is waiting to read) to keep the |
| 96 // blob alive. |
| 97 ERR_BLOB_DEREFERENCED_WHILE_BUILDING = 4, |
| 98 // A blob that we referenced during construction is broken, or a browser-side |
| 99 // builder tries to build a blob with a blob reference that isn't finished |
| 100 // constructing. |
| 101 ERR_REFERENCED_BLOB_BROKEN = 5, |
| 102 LAST_ERROR = ERR_REFERENCED_BLOB_BROKEN, |
| 103 |
| 104 // Blob state section: |
| 105 // The blob has finished. |
| 106 DONE = 200, |
| 107 // The system is pending on quota being granted, the transport layer |
| 108 // populating pending data, and/or copying data from dependent blobs. See |
| 109 // InternalBlobData::BuildingState determine which of these are happening, as |
| 110 // they all can happen concurrently. |
| 111 PENDING = 201, |
| 112 LAST = PENDING |
| 113 }; |
| 114 |
| 115 using BlobStatusCallback = base::Callback<void(BlobStatus)>; |
| 116 |
| 117 // Returns if the status is an error code. |
| 118 STORAGE_COMMON_EXPORT bool BlobStatusIsError(BlobStatus status); |
| 119 |
| 120 // Returns if the status is a bad enough error to flag the IPC as bad. This is |
| 121 // only INVALID_CONSTRUCTION_ARGUMENTS. |
| 122 STORAGE_COMMON_EXPORT bool BlobStatusIsBadIPC(BlobStatus status); |
| 123 |
| 52 } // namespace storage | 124 } // namespace storage |
| 53 | 125 |
| 54 #endif // STORAGE_COMMON_BLOB_STORAGE_BLOB_STORAGE_CONSTANTS_H_ | 126 #endif // STORAGE_COMMON_BLOB_STORAGE_BLOB_STORAGE_CONSTANTS_H_ |
| OLD | NEW |