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

Side by Side Diff: content/browser/devtools/protocol/usage_and_quota_query.cc

Issue 977553003: DevTools: remove usage and quota getter from the protocol handler. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@946713002
Patch Set: removed the test. Created 5 years, 9 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 unified diff | Download patch
« no previous file with comments | « content/browser/devtools/protocol/usage_and_quota_query.h ('k') | content/content_browser.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "content/browser/devtools/protocol/usage_and_quota_query.h"
6
7 #include "net/base/net_util.h"
8
9 namespace content {
10 namespace devtools {
11 namespace page {
12
13 UsageAndQuotaQuery::UsageAndQuotaQuery(
14 scoped_refptr<storage::QuotaManager> quota_manager,
15 const GURL& security_origin,
16 const Callback& callback)
17 : quota_manager_(quota_manager),
18 security_origin_(security_origin),
19 callback_(callback),
20 temporary_quota_(0.0),
21 persistent_quota_(0.0) {
22 AddRef();
23 quota_manager->GetUsageAndQuotaForWebApps(
24 security_origin,
25 storage::kStorageTypeTemporary,
26 base::Bind(&UsageAndQuotaQuery::DidGetTemporaryQuota, this));
27 quota_manager->GetPersistentHostQuota(
28 net::GetHostOrSpecFromURL(security_origin),
29 base::Bind(&UsageAndQuotaQuery::DidGetPersistentQuota, this));
30 GetHostUsage(&temporary_usage_, storage::kStorageTypeTemporary);
31 GetHostUsage(&persistent_usage_, storage::kStorageTypePersistent);
32 GetHostUsage(&syncable_usage_, storage::kStorageTypeSyncable);
33 Release();
34 }
35
36 UsageAndQuotaQuery::~UsageAndQuotaQuery() {
37 callback_.Run(QueryUsageAndQuotaResponse::Create()
38 ->set_quota(Quota::Create()->set_temporary(temporary_quota_)
39 ->set_persistent(persistent_quota_))
40 ->set_usage(Usage::Create()->set_temporary(temporary_usage_)
41 ->set_persistent(persistent_usage_)
42 ->set_syncable(syncable_usage_)));
43 }
44
45 void UsageAndQuotaQuery::DidGetTemporaryQuota(storage::QuotaStatusCode status,
46 int64 used_bytes,
47 int64 quota_in_bytes) {
48 if (status == storage::kQuotaStatusOk)
49 temporary_quota_ = quota_in_bytes;
50 }
51
52 void UsageAndQuotaQuery::DidGetPersistentQuota(storage::QuotaStatusCode status,
53 int64 value) {
54 if (status == storage::kQuotaStatusOk)
55 persistent_quota_ = value;
56 }
57
58 void UsageAndQuotaQuery::GetHostUsage(UsageItems* list,
59 storage::StorageType storage_type) {
60 GetUsageForClient(list, storage_type, storage::QuotaClient::kFileSystem,
61 usage_item::kIdFilesystem);
62 GetUsageForClient(list, storage_type, storage::QuotaClient::kDatabase,
63 usage_item::kIdDatabase);
64 GetUsageForClient(list, storage_type, storage::QuotaClient::kAppcache,
65 usage_item::kIdAppcache);
66 GetUsageForClient(list, storage_type, storage::QuotaClient::kIndexedDatabase,
67 usage_item::kIdIndexeddatabase);
68 }
69
70 void UsageAndQuotaQuery::GetUsageForClient(UsageItems* list,
71 storage::StorageType storage_type,
72 storage::QuotaClient::ID client_id,
73 const std::string& client_name) {
74 if (!quota_manager_->IsTrackingHostUsage(storage_type, client_id))
75 return;
76 quota_manager_->GetHostUsage(
77 net::GetHostOrSpecFromURL(security_origin_),
78 storage_type,
79 client_id,
80 base::Bind(&UsageAndQuotaQuery::DidGetUsageForClient,
81 this, list, client_name));
82 }
83
84 void UsageAndQuotaQuery::DidGetUsageForClient(UsageItems* list,
85 const std::string& client_name,
86 int64 value) {
87 list->push_back(UsageItem::Create()->set_id(client_name)->set_value(value));
88 }
89
90 } // namespace page
91 } // namespace devtools
92 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/devtools/protocol/usage_and_quota_query.h ('k') | content/content_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698