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

Unified Diff: storage/browser/blob/blob_memory_controller.h

Issue 2552153002: [BlobStorage] Enabling disk paging and direct storage. (Closed)
Patch Set: Marijn's comments Created 3 years, 11 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
Index: storage/browser/blob/blob_memory_controller.h
diff --git a/storage/browser/blob/blob_memory_controller.h b/storage/browser/blob/blob_memory_controller.h
index 6f9e15f277b75c8122930bb622ba2c668788bafc..ecd41ac475e188cec98bdb264d61ef0986c173c5 100644
--- a/storage/browser/blob/blob_memory_controller.h
+++ b/storage/browser/blob/blob_memory_controller.h
@@ -16,7 +16,7 @@
#include <utility>
#include <vector>
-#include "base/callback.h"
+#include "base/callback_forward.h"
#include "base/callback_helpers.h"
#include "base/containers/mru_cache.h"
#include "base/files/file.h"
@@ -33,6 +33,10 @@ namespace base {
class TaskRunner;
}
+namespace content {
+class ChromeBlobStorageContext;
+}
+
namespace storage {
class ShareableBlobDataItem;
class ShareableFileReference;
@@ -156,20 +160,44 @@ class STORAGE_EXPORT BlobMemoryController {
size_t memory_usage() const { return blob_memory_used_; }
uint64_t disk_usage() const { return disk_used_; }
+ base::WeakPtr<BlobMemoryController> GetWeakPtr();
+
const BlobStorageLimits& limits() const { return limits_; }
void set_limits_for_testing(const BlobStorageLimits& limits) {
+ manual_limits_set_ = true;
limits_ = limits;
}
+ using DiskSpaceFuncPtr = int64_t (*)(const base::FilePath&);
+
+ void set_testing_disk_space(DiskSpaceFuncPtr disk_space_function) {
+ disk_space_function_ = disk_space_function;
+ }
+
+ protected:
Mark P 2017/01/10 23:57:00 nit: why did you add this?
dmurph 2017/01/11 01:49:22 rmeoved.
private:
class FileQuotaAllocationTask;
class MemoryQuotaAllocationTask;
+ // So this (and only this) class can call CalculateBlobStorageLimits().
+ friend class content::ChromeBlobStorageContext;
+
+ // Schedules a task on the file runner to calculate blob storage quota limits.
+ // This should not be called more than once in a browser run as we record UMA
Mark P 2017/01/10 23:57:00 "A browser run" sounds to me like something that c
dmurph 2017/01/11 01:49:22 Done.
+ // stats that we expect to only be called once.
Mark P 2017/01/10 23:57:00 nit: called -> emitted (or recorded)
dmurph 2017/01/11 01:49:22 Done.
+ void CalculateBlobStorageLimits();
+
using PendingMemoryQuotaTaskList =
std::list<std::unique_ptr<MemoryQuotaAllocationTask>>;
using PendingFileQuotaTaskList =
std::list<std::unique_ptr<FileQuotaAllocationTask>>;
+ void OnStorageLimitsCalculated(BlobStorageLimits limits);
+
+ // Adjusts the effective disk usage based on the available space. We try to
+ // keep at least BlobSorageLimits::min_available_disk_space() free.
+ void AdjustDiskUsage(uint64_t avail_disk_space);
+
base::WeakPtr<QuotaAllocationTask> AppendMemoryTask(
uint64_t total_bytes_needed,
std::vector<scoped_refptr<ShareableBlobDataItem>> unreserved_memory_items,
@@ -189,7 +217,7 @@ class STORAGE_EXPORT BlobMemoryController {
scoped_refptr<ShareableFileReference> file_reference,
std::vector<scoped_refptr<ShareableBlobDataItem>> items,
size_t total_items_size,
- FileCreationInfo result);
+ std::pair<FileCreationInfo, int64_t /* disk_avail */> result);
size_t GetAvailableMemoryForBlobs() const;
uint64_t GetAvailableFileSpaceForBlobs() const;
@@ -209,6 +237,9 @@ class STORAGE_EXPORT BlobMemoryController {
// changes.
void RecordTracingCounters() const;
+ // Store that we set manual limits so we don't accidentally override them with
+ // our configuration task.
+ bool manual_limits_set_ = false;
BlobStorageLimits limits_;
// Memory bookkeeping. These numbers are all disjoint.
@@ -233,6 +264,8 @@ class STORAGE_EXPORT BlobMemoryController {
bool file_paging_enabled_ = false;
base::FilePath blob_storage_dir_;
scoped_refptr<base::TaskRunner> file_runner_;
+ // This defaults to calling base::SysInfo::AmountOfFreeDiskSpace.
+ DiskSpaceFuncPtr disk_space_function_;
// Lifetime of the ShareableBlobDataItem objects is handled externally in the
// BlobStorageContext class.

Powered by Google App Engine
This is Rietveld 408576698