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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 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 #include "content/browser/devtools/protocol/usage_and_quota_query.h" 5 #include "content/browser/devtools/protocol/usage_and_quota_query.h"
6 6
7 #include "net/base/net_util.h" 7 #include "net/base/net_util.h"
8 8
9 namespace content { 9 namespace content {
10 namespace devtools { 10 namespace devtools {
11 namespace page { 11 namespace page {
12 12
13 namespace {
14
15 class UsageQuery : public base::RefCounted<UsageQuery> {
16 public:
17 using Callback = base::Callback<void(const std::vector<UsageItem>&)>;
18
19 UsageQuery(scoped_refptr<storage::QuotaManager> quota_manager,
20 const std::string& host,
21 storage::StorageType storage_type,
22 const Callback& callback)
23 : quota_manager_(quota_manager),
24 host_(host),
25 storage_type_(storage_type),
26 callback_(callback) {
27 AddRef();
28 GetForClient(storage::QuotaClient::kFileSystem,
29 usage_item::kIdFilesystem);
30 GetForClient(storage::QuotaClient::kDatabase,
31 usage_item::kIdDatabase);
32 GetForClient(storage::QuotaClient::kAppcache,
33 usage_item::kIdAppcache);
34 GetForClient(storage::QuotaClient::kIndexedDatabase,
35 usage_item::kIdIndexeddatabase);
36 Release();
37 }
38
39 private:
40 friend class base::RefCounted<UsageQuery>;
41
42 ~UsageQuery() {
43 callback_.Run(usage_list_);
44 }
45
46 void GetForClient(storage::QuotaClient::ID client_id,
47 const std::string& client_name) {
48 if (!quota_manager_->IsTrackingHostUsage(storage_type_, client_id))
49 return;
50 quota_manager_->GetHostUsage(
51 host_, storage_type_, client_id,
52 base::Bind(&UsageQuery::DidGetForClient, this, client_name));
53 }
54
55 void DidGetForClient(const std::string& client_name, int64 value) {
56 UsageItem usage_item;
57 usage_item.set_id(client_name);
58 usage_item.set_value(value);
59 usage_list_.push_back(usage_item);
60 }
61
62 scoped_refptr<storage::QuotaManager> quota_manager_;
63 std::string host_;
64 storage::StorageType storage_type_;
65 std::vector<UsageItem> usage_list_;
66 Callback callback_;
67 };
68
69 } // namespace
70
71 UsageAndQuotaQuery::UsageAndQuotaQuery( 13 UsageAndQuotaQuery::UsageAndQuotaQuery(
72 scoped_refptr<storage::QuotaManager> quota_manager, 14 scoped_refptr<storage::QuotaManager> quota_manager,
73 const GURL& security_origin, 15 const GURL& security_origin,
74 const Callback& callback) 16 const Callback& callback)
75 : quota_manager_(quota_manager), 17 : quota_manager_(quota_manager),
76 security_origin_(security_origin), 18 security_origin_(security_origin),
77 callback_(callback) { 19 callback_(callback),
20 temporary_quota_(0.0),
21 persistent_quota_(0.0) {
78 AddRef(); 22 AddRef();
79 quota_manager->GetUsageAndQuotaForWebApps( 23 quota_manager->GetUsageAndQuotaForWebApps(
80 security_origin, 24 security_origin,
81 storage::kStorageTypeTemporary, 25 storage::kStorageTypeTemporary,
82 base::Bind(&UsageAndQuotaQuery::DidGetTemporaryQuota, this)); 26 base::Bind(&UsageAndQuotaQuery::DidGetTemporaryQuota, this));
83 quota_manager->GetPersistentHostQuota( 27 quota_manager->GetPersistentHostQuota(
84 net::GetHostOrSpecFromURL(security_origin), 28 net::GetHostOrSpecFromURL(security_origin),
85 base::Bind(&UsageAndQuotaQuery::DidGetPersistentQuota, this)); 29 base::Bind(&UsageAndQuotaQuery::DidGetPersistentQuota, this));
86 GetHostUsage(storage::kStorageTypeTemporary, 30 GetHostUsage(&temporary_usage_, storage::kStorageTypeTemporary);
87 base::Bind(&Usage::set_temporary, base::Unretained(&usage_))); 31 GetHostUsage(&persistent_usage_, storage::kStorageTypePersistent);
88 GetHostUsage(storage::kStorageTypePersistent, 32 GetHostUsage(&syncable_usage_, storage::kStorageTypeSyncable);
89 base::Bind(&Usage::set_persistent, base::Unretained(&usage_)));
90 GetHostUsage(storage::kStorageTypeSyncable,
91 base::Bind(&Usage::set_syncable, base::Unretained(&usage_)));
92 Release(); 33 Release();
93 } 34 }
94 35
95 UsageAndQuotaQuery::~UsageAndQuotaQuery() { 36 UsageAndQuotaQuery::~UsageAndQuotaQuery() {
96 scoped_ptr<QueryUsageAndQuotaResponse> response( 37 callback_.Run(QueryUsageAndQuotaResponse::Create()
97 new QueryUsageAndQuotaResponse); 38 ->set_quota(Quota::Create()->set_temporary(temporary_quota_)
98 response->set_quota(quota_); 39 ->set_persistent(persistent_quota_))
99 response->set_usage(usage_); 40 ->set_usage(Usage::Create()->set_temporary(temporary_usage_)
100 callback_.Run(response.Pass()); 41 ->set_persistent(persistent_usage_)
42 ->set_syncable(syncable_usage_)));
101 } 43 }
102 44
103 void UsageAndQuotaQuery::DidGetTemporaryQuota(storage::QuotaStatusCode status, 45 void UsageAndQuotaQuery::DidGetTemporaryQuota(storage::QuotaStatusCode status,
104 int64 used_bytes, 46 int64 used_bytes,
105 int64 quota_in_bytes) { 47 int64 quota_in_bytes) {
106 if (status == storage::kQuotaStatusOk) 48 if (status == storage::kQuotaStatusOk)
107 quota_.set_temporary(quota_in_bytes); 49 temporary_quota_ = quota_in_bytes;
108 } 50 }
109 51
110 void UsageAndQuotaQuery::DidGetPersistentQuota(storage::QuotaStatusCode status, 52 void UsageAndQuotaQuery::DidGetPersistentQuota(storage::QuotaStatusCode status,
111 int64 value) { 53 int64 value) {
112 if (status == storage::kQuotaStatusOk) 54 if (status == storage::kQuotaStatusOk)
113 quota_.set_persistent(value); 55 persistent_quota_ = value;
114 } 56 }
115 57
116 void UsageAndQuotaQuery::GetHostUsage( 58 void UsageAndQuotaQuery::GetHostUsage(UsageItems* list,
117 storage::StorageType storage_type, 59 storage::StorageType storage_type) {
118 const UsageItemsCallback& items_callback) { 60 GetUsageForClient(list, storage_type, storage::QuotaClient::kFileSystem,
119 // |base::Bind| is used instead of passing |items_callback| directly 61 usage_item::kIdFilesystem);
120 // so that |this| is retained. 62 GetUsageForClient(list, storage_type, storage::QuotaClient::kDatabase,
121 new UsageQuery(quota_manager_, 63 usage_item::kIdDatabase);
122 net::GetHostOrSpecFromURL(security_origin_), 64 GetUsageForClient(list, storage_type, storage::QuotaClient::kAppcache,
123 storage_type, 65 usage_item::kIdAppcache);
124 base::Bind(&UsageAndQuotaQuery::DidGetHostUsage, 66 GetUsageForClient(list, storage_type, storage::QuotaClient::kIndexedDatabase,
125 this, items_callback)); 67 usage_item::kIdIndexeddatabase);
126 } 68 }
127 69
128 void UsageAndQuotaQuery::DidGetHostUsage( 70 void UsageAndQuotaQuery::GetUsageForClient(UsageItems* list,
129 const UsageItemsCallback& items_callback, 71 storage::StorageType storage_type,
130 const std::vector<UsageItem>& usage_list) { 72 storage::QuotaClient::ID client_id,
131 items_callback.Run(usage_list); 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));
132 } 88 }
133 89
134 } // namespace page 90 } // namespace page
135 } // namespace devtools 91 } // namespace devtools
136 } // namespace content 92 } // namespace content
OLDNEW
« 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