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

Unified Diff: content/browser/devtools/protocol/usage_and_quota_query.cc

Issue 642263004: [DevTools] Make generated protocol structs wrappers around DictionaryValue (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix that will be needed for browser protocol Created 6 years, 1 month 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
« no previous file with comments | « content/browser/devtools/protocol/usage_and_quota_query.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/devtools/protocol/usage_and_quota_query.cc
diff --git a/content/browser/devtools/protocol/usage_and_quota_query.cc b/content/browser/devtools/protocol/usage_and_quota_query.cc
index 2936fe1e079a244ed6983746ced2e28eaebdbffe..3a1fff065059e727a21cf388fcb497a66218db20 100644
--- a/content/browser/devtools/protocol/usage_and_quota_query.cc
+++ b/content/browser/devtools/protocol/usage_and_quota_query.cc
@@ -10,71 +10,15 @@ namespace content {
namespace devtools {
namespace page {
-namespace {
-
-class UsageQuery : public base::RefCounted<UsageQuery> {
- public:
- using Callback = base::Callback<void(const std::vector<UsageItem>&)>;
-
- UsageQuery(scoped_refptr<storage::QuotaManager> quota_manager,
- const std::string& host,
- storage::StorageType storage_type,
- const Callback& callback)
- : quota_manager_(quota_manager),
- host_(host),
- storage_type_(storage_type),
- callback_(callback) {
- AddRef();
- GetForClient(storage::QuotaClient::kFileSystem,
- usage_item::kIdFilesystem);
- GetForClient(storage::QuotaClient::kDatabase,
- usage_item::kIdDatabase);
- GetForClient(storage::QuotaClient::kAppcache,
- usage_item::kIdAppcache);
- GetForClient(storage::QuotaClient::kIndexedDatabase,
- usage_item::kIdIndexeddatabase);
- Release();
- }
-
- private:
- friend class base::RefCounted<UsageQuery>;
-
- ~UsageQuery() {
- callback_.Run(usage_list_);
- }
-
- void GetForClient(storage::QuotaClient::ID client_id,
- const std::string& client_name) {
- if (!quota_manager_->IsTrackingHostUsage(storage_type_, client_id))
- return;
- quota_manager_->GetHostUsage(
- host_, storage_type_, client_id,
- base::Bind(&UsageQuery::DidGetForClient, this, client_name));
- }
-
- void DidGetForClient(const std::string& client_name, int64 value) {
- UsageItem usage_item;
- usage_item.set_id(client_name);
- usage_item.set_value(value);
- usage_list_.push_back(usage_item);
- }
-
- scoped_refptr<storage::QuotaManager> quota_manager_;
- std::string host_;
- storage::StorageType storage_type_;
- std::vector<UsageItem> usage_list_;
- Callback callback_;
-};
-
-} // namespace
-
UsageAndQuotaQuery::UsageAndQuotaQuery(
scoped_refptr<storage::QuotaManager> quota_manager,
const GURL& security_origin,
const Callback& callback)
: quota_manager_(quota_manager),
security_origin_(security_origin),
- callback_(callback) {
+ callback_(callback),
+ temporary_quota_(0.0),
+ persistent_quota_(0.0) {
AddRef();
quota_manager->GetUsageAndQuotaForWebApps(
security_origin,
@@ -83,52 +27,64 @@ UsageAndQuotaQuery::UsageAndQuotaQuery(
quota_manager->GetPersistentHostQuota(
net::GetHostOrSpecFromURL(security_origin),
base::Bind(&UsageAndQuotaQuery::DidGetPersistentQuota, this));
- GetHostUsage(storage::kStorageTypeTemporary,
- base::Bind(&Usage::set_temporary, base::Unretained(&usage_)));
- GetHostUsage(storage::kStorageTypePersistent,
- base::Bind(&Usage::set_persistent, base::Unretained(&usage_)));
- GetHostUsage(storage::kStorageTypeSyncable,
- base::Bind(&Usage::set_syncable, base::Unretained(&usage_)));
+ GetHostUsage(&temporary_usage_, storage::kStorageTypeTemporary);
+ GetHostUsage(&persistent_usage_, storage::kStorageTypePersistent);
+ GetHostUsage(&syncable_usage_, storage::kStorageTypeSyncable);
Release();
}
UsageAndQuotaQuery::~UsageAndQuotaQuery() {
- scoped_ptr<QueryUsageAndQuotaResponse> response(
- new QueryUsageAndQuotaResponse);
- response->set_quota(quota_);
- response->set_usage(usage_);
- callback_.Run(response.Pass());
+ callback_.Run(QueryUsageAndQuotaResponse::Create()
+ ->set_quota(Quota::Create()->set_temporary(temporary_quota_)
+ ->set_persistent(persistent_quota_))
+ ->set_usage(Usage::Create()->set_temporary(temporary_usage_)
+ ->set_persistent(persistent_usage_)
+ ->set_syncable(syncable_usage_)));
}
void UsageAndQuotaQuery::DidGetTemporaryQuota(storage::QuotaStatusCode status,
int64 used_bytes,
int64 quota_in_bytes) {
if (status == storage::kQuotaStatusOk)
- quota_.set_temporary(quota_in_bytes);
+ temporary_quota_ = quota_in_bytes;
}
void UsageAndQuotaQuery::DidGetPersistentQuota(storage::QuotaStatusCode status,
int64 value) {
if (status == storage::kQuotaStatusOk)
- quota_.set_persistent(value);
+ persistent_quota_ = value;
+}
+
+void UsageAndQuotaQuery::GetHostUsage(UsageItems* list,
+ storage::StorageType storage_type) {
+ GetUsageForClient(list, storage_type, storage::QuotaClient::kFileSystem,
+ usage_item::kIdFilesystem);
+ GetUsageForClient(list, storage_type, storage::QuotaClient::kDatabase,
+ usage_item::kIdDatabase);
+ GetUsageForClient(list, storage_type, storage::QuotaClient::kAppcache,
+ usage_item::kIdAppcache);
+ GetUsageForClient(list, storage_type, storage::QuotaClient::kIndexedDatabase,
+ usage_item::kIdIndexeddatabase);
}
-void UsageAndQuotaQuery::GetHostUsage(
- storage::StorageType storage_type,
- const UsageItemsCallback& items_callback) {
- // |base::Bind| is used instead of passing |items_callback| directly
- // so that |this| is retained.
- new UsageQuery(quota_manager_,
- net::GetHostOrSpecFromURL(security_origin_),
- storage_type,
- base::Bind(&UsageAndQuotaQuery::DidGetHostUsage,
- this, items_callback));
+void UsageAndQuotaQuery::GetUsageForClient(UsageItems* list,
+ storage::StorageType storage_type,
+ storage::QuotaClient::ID client_id,
+ const std::string& client_name) {
+ if (!quota_manager_->IsTrackingHostUsage(storage_type, client_id))
+ return;
+ quota_manager_->GetHostUsage(
+ net::GetHostOrSpecFromURL(security_origin_),
+ storage_type,
+ client_id,
+ base::Bind(&UsageAndQuotaQuery::DidGetUsageForClient,
+ this, list, client_name));
}
-void UsageAndQuotaQuery::DidGetHostUsage(
- const UsageItemsCallback& items_callback,
- const std::vector<UsageItem>& usage_list) {
- items_callback.Run(usage_list);
+void UsageAndQuotaQuery::DidGetUsageForClient(UsageItems* list,
+ const std::string& client_name,
+ int64 value) {
+ list->push_back(UsageItem::Create()->set_id(client_name)->set_value(value));
}
} // namespace page
« no previous file with comments | « content/browser/devtools/protocol/usage_and_quota_query.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698