Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Allow partitions to have app set quotas OS-14197 #3

Open
wants to merge 9 commits into
base: upstream_main
Choose a base branch
from

Conversation

gecko19
Copy link

@gecko19 gecko19 commented Dec 28, 2022

Description of Change
Allow the passing of a quota to the session.fromPartition() API.
This patch allows partitions to have a quota size, which in turn persuades
the storage manager to run a garbage collector(at specific times) to free
reclaimable storage space.

Checklist

Release Notes
notes: Allow the passing of a quota to the session.fromPartition() API.

This patch allows partitions to have a quota size,
which in turn perusades the storage manager to run
a garbage collector(at specific times) to free
reclaimable storage space.
content::StoragePartitionConfig::CreateDefault(this, quota_size));
}
return BrowserContext::GetDefaultStoragePartition();
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about this:

content::StoragePartition* partition = BrowserContext::GetDefaultStoragePartition();
partition->GetQuotaManager()->SetQuotaSettings(storage::GetHardCodedSettings(quota));
return partition;

You can then avoid modifying StoragePartitionConfig.

Copy link
Author

@gecko19 gecko19 Jan 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about this:

content::StoragePartition* partition = BrowserContext::GetDefaultStoragePartition();
partition->GetQuotaManager()->SetQuotaSettings(storage::GetHardCodedSettings(quota));
return partition;

You can then avoid modifying StoragePartitionConfig.

I had a try with these changes. To have SetQuotaSettings() callable, the header file storage/browser/quota/quota_manager.h had to be added.

Since the SetQuotaSettings call can be done only on the IOThread, I tried the snippet below, but then there was a DCHECK fault since the IOthread is not accessible within the electron layer.

 content::StoragePartition* partition = BrowserContext::GetDefaultStoragePartition();
 base::WeakPtrFactory<storage::QuotaManager> quota_weak_factory_{partition->GetQuotaManager()};
 content::GetIOThreadTaskRunner({})->PostTask(
          FROM_HERE, base::BindOnce(&storage::QuotaManager::SetQuotaSettings,
          quota_weak_factory_.GetWeakPtr(),storage::GetHardCodedSettings(quota_size)));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the exact DCHECK error? ElectronBrowserContext::~ElectronBrowserContext() has these lines:
BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, std::move(resource_context_));

spec/api-net-spec.ts Outdated Show resolved Hide resolved
Copy link

@caneraltinbasak caneraltinbasak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a general change:
You have used quota = 0 as default quota setting. To my undestanding quota=0 means, you cannot write anything. There is no empty space or you have no right to write.

That is why I asked you to use absl::optional. Then we can differentiate between 0, a value and not defined. Sorry I wasn't very clear when I asked you to use absl::optional.

spec/api-net-spec.ts Outdated Show resolved Hide resolved
@@ -31,6 +31,30 @@ describe('session module', () => {
});
});

describe('session.fromPartition(partition, options)', () => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also need test to make sure default values are used when quotasize option is not defined.
We also need negative tests. Like defining negative numbers, too large numbers, 0 etc.

Copy link
Author

@gecko19 gecko19 Apr 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did try to add a test which queries the disk free space of the specified path. However, this test then cannot be run on all platforms and hence would fail. The procedure I followed was to use the childProcess to run df <path>, but that has to be further extracted and again this would not work on Windows which then would then fail the test and not allow the patch to land upstream.

@gecko19 gecko19 changed the base branch from main to upstream_main March 30, 2023 17:53
@caneraltinbasak caneraltinbasak changed the title OS-14197: Allow partitions to have app set quotas feat: Allow partitions to have app set quotas OS-14197 Apr 3, 2023
@caneraltinbasak caneraltinbasak changed the base branch from upstream_main to 23-x-y-bs April 3, 2023 08:22
@gecko19 gecko19 changed the base branch from 23-x-y-bs to upstream_main April 3, 2023 09:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants