Chromium Code Reviews| Index: content/browser/devtools/renderer_overrides_handler.cc |
| diff --git a/content/browser/devtools/renderer_overrides_handler.cc b/content/browser/devtools/renderer_overrides_handler.cc |
| index fe35d3029b3e7c2a18f55c5248e088b94b4ca38c..90120fc6024bc19f2dd57c9387bfdbd2bb5360b1 100644 |
| --- a/content/browser/devtools/renderer_overrides_handler.cc |
| +++ b/content/browser/devtools/renderer_overrides_handler.cc |
| @@ -6,6 +6,7 @@ |
| #include <string> |
| +#include "base/barrier_closure.h" |
| #include "base/base64.h" |
| #include "base/bind.h" |
| #include "base/bind_helpers.h" |
| @@ -28,17 +29,20 @@ |
| #include "content/public/browser/render_process_host.h" |
| #include "content/public/browser/render_view_host.h" |
| #include "content/public/browser/render_widget_host_view.h" |
| +#include "content/public/browser/storage_partition.h" |
| #include "content/public/browser/web_contents.h" |
| #include "content/public/browser/web_contents_delegate.h" |
| #include "content/public/common/page_transition_types.h" |
| #include "content/public/common/referrer.h" |
| #include "ipc/ipc_sender.h" |
| +#include "net/base/net_util.h" |
| #include "third_party/WebKit/public/web/WebInputEvent.h" |
| #include "ui/gfx/codec/jpeg_codec.h" |
| #include "ui/gfx/codec/png_codec.h" |
| #include "ui/gfx/size_conversions.h" |
| #include "ui/snapshot/snapshot.h" |
| #include "url/gurl.h" |
| +#include "webkit/browser/quota/quota_manager.h" |
| using WebKit::WebGestureEvent; |
| using WebKit::WebInputEvent; |
| @@ -122,6 +126,11 @@ RendererOverridesHandler::RendererOverridesHandler(DevToolsAgentHost* agent) |
| &RendererOverridesHandler::PageStopScreencast, |
| base::Unretained(this))); |
| RegisterCommandHandler( |
| + devtools::Page::queryUsageAndQuota::kName, |
| + base::Bind( |
| + &RendererOverridesHandler::PageQueryUsageAndQuota, |
| + base::Unretained(this))); |
| + RegisterCommandHandler( |
| devtools::Input::dispatchMouseEvent::kName, |
| base::Bind( |
| &RendererOverridesHandler::InputDispatchMouseEvent, |
| @@ -525,6 +534,187 @@ void RendererOverridesHandler::ScreenshotCaptured( |
| } |
| } |
| +// Quota and Usage ------------------------------------------ |
| + |
| +namespace { |
| + |
| +typedef base::Callback<void(scoped_ptr<base::DictionaryValue>)> |
| + ResponseCallback; |
| + |
| +void QueryUsageAndQuotaCompletedOnIOThread( |
| + scoped_ptr<base::DictionaryValue> quota, |
| + scoped_ptr<base::ListValue> temporaryStorageUsage, |
| + scoped_ptr<base::ListValue> persistentStorageUsage, |
| + scoped_ptr<base::ListValue> syncableStorageUsage, |
| + ResponseCallback callback) { |
| + |
| + scoped_ptr<base::DictionaryValue> response_data(new base::DictionaryValue); |
| + response_data->Set(devtools::Page::queryUsageAndQuota::kResponseQuota, |
| + quota.release()); |
| + |
| + scoped_ptr<base::DictionaryValue> usage(new base::DictionaryValue); |
| + usage->Set(devtools::Page::Usage::kItemTemporary, |
| + temporaryStorageUsage.release()); |
| + usage->Set(devtools::Page::Usage::kItemPersistent, |
| + persistentStorageUsage.release()); |
| + usage->Set(devtools::Page::Usage::kItemSyncable, |
| + syncableStorageUsage.release()); |
| + response_data->Set(devtools::Page::queryUsageAndQuota::kResponseUsage, |
| + usage.release()); |
| + |
| + BrowserThread::PostTask( |
| + BrowserThread::UI, FROM_HERE, |
| + base::Bind(callback, base::Passed(&response_data))); |
| +} |
| + |
| +void DidGetHostUsage( |
| + base::ListValue* list, |
| + const char* client_id, |
| + const base::Closure& barrier, |
| + int64 value) { |
| + base::DictionaryValue* usage_item = new base::DictionaryValue; |
| + usage_item->SetString(devtools::Page::UsageItem::kItemID, client_id); |
|
pfeldman
2013/09/20 13:26:25
You could attach usage lists lazily and get rid of
SeRya
2013/09/20 19:39:40
Now I create in a loop.
|
| + usage_item->SetDouble(devtools::Page::UsageItem::kItemValue, value); |
| + list->Append(usage_item); |
| + barrier.Run(); |
| +} |
| + |
| +void DidGetQuotaValue( |
| + base::DictionaryValue* dictionary, |
| + const char* item_name, |
| + const base::Closure& barrier, |
| + quota::QuotaStatusCode status, |
| + int64 value) { |
| + if (status == quota::kQuotaStatusOk) |
| + dictionary->SetDouble(item_name, value); |
| + barrier.Run(); |
| +} |
| + |
| +void DidGetUsageAndQuotaForWebApps( |
| + base::DictionaryValue* quota, |
| + const char* item_name, |
| + const base::Closure& barrier, |
| + quota::QuotaStatusCode status, |
| + int64 used_bytes, |
| + int64 quota_in_bytes) { |
| + if (status == quota::kQuotaStatusOk) |
| + quota->SetDouble(item_name, quota_in_bytes); |
| + barrier.Run(); |
| +} |
| + |
| +void QueryUsageAndQuotaOnIOThread( |
| + scoped_refptr<quota::QuotaManager> quota_manager, |
| + const GURL& security_origin, |
| + const ResponseCallback& callback) { |
| + base::ListValue* temporaryStorageUsage = new base::ListValue; |
|
pfeldman
2013/09/20 13:26:25
You should create them as scoped_ptr<>s
SeRya
2013/09/20 19:39:40
Done.
|
| + base::ListValue* persistentStorageUsage = new base::ListValue; |
| + base::ListValue* syncableStorageUsage = new base::ListValue; |
| + base::DictionaryValue* quota = new base::DictionaryValue; |
| + |
| + static const int kExpectedResults = 8; |
| + |
| + // Takes owneship on usage and quota. |
| + base::Closure barrier = BarrierClosure( |
| + kExpectedResults, |
| + base::Bind(&QueryUsageAndQuotaCompletedOnIOThread, |
| + base::Passed(scoped_ptr<base::DictionaryValue>(quota)), |
| + base::Passed(scoped_ptr<base::ListValue>( |
| + temporaryStorageUsage)), |
| + base::Passed(scoped_ptr<base::ListValue>( |
| + persistentStorageUsage)), |
| + base::Passed(scoped_ptr<base::ListValue>( |
| + syncableStorageUsage)), |
| + callback)); |
| + std::string host = net::GetHostOrSpecFromURL(security_origin); |
| + |
| + quota_manager->GetUsageAndQuotaForWebApps( |
| + security_origin, |
| + quota::kStorageTypeTemporary, |
| + base::Bind(&DidGetUsageAndQuotaForWebApps, quota, |
| + devtools::Page::Quota::kItemTemporary, barrier)); |
| + |
| + quota_manager->GetPersistentHostQuota( |
| + host, |
| + base::Bind(&DidGetQuotaValue, quota, |
| + devtools::Page::Quota::kItemPersistent, |
| + barrier)); |
| + |
| + quota_manager->GetHostUsage(host, quota::kStorageTypeTemporary, |
| + quota::QuotaClient::kFileSystem, |
| + base::Bind(&DidGetHostUsage, temporaryStorageUsage, |
| + devtools::Page::UsageItem::ID::kFilesystem, |
| + barrier)); |
| + |
| + quota_manager->GetHostUsage(host, quota::kStorageTypePersistent, |
| + quota::QuotaClient::kFileSystem, |
| + base::Bind(&DidGetHostUsage, persistentStorageUsage, |
| + devtools::Page::UsageItem::ID::kFilesystem, |
| + barrier)); |
| + |
| + quota_manager->GetHostUsage(host, quota::kStorageTypeSyncable, |
| + quota::QuotaClient::kFileSystem, |
| + base::Bind(&DidGetHostUsage, syncableStorageUsage, |
| + devtools::Page::UsageItem::ID::kFilesystem, |
| + barrier)); |
| + |
| + quota_manager->GetHostUsage(host, quota::kStorageTypeTemporary, |
| + quota::QuotaClient::kDatabase, |
| + base::Bind(&DidGetHostUsage, temporaryStorageUsage, |
| + devtools::Page::UsageItem::ID::kDatabase, |
| + barrier)); |
| + |
| + quota_manager->GetHostUsage(host, quota::kStorageTypeTemporary, |
| + quota::QuotaClient::kAppcache, |
| + base::Bind(&DidGetHostUsage, temporaryStorageUsage, |
| + devtools::Page::UsageItem::ID::kAppcache, |
| + barrier)); |
| + |
| + quota_manager->GetHostUsage(host, quota::kStorageTypeTemporary, |
| + quota::QuotaClient::kIndexedDatabase, |
| + base::Bind(&DidGetHostUsage, temporaryStorageUsage, |
| + devtools::Page::UsageItem::ID::kIndexedDatabase, |
| + barrier)); |
| +} |
| + |
| +} // namespace |
| + |
| +scoped_refptr<DevToolsProtocol::Response> |
| +RendererOverridesHandler::PageQueryUsageAndQuota( |
| + scoped_refptr<DevToolsProtocol::Command> command) { |
| + base::DictionaryValue* params = command->params(); |
| + std::string security_origin; |
| + if (!params || !params->GetString( |
| + devtools::Page::queryUsageAndQuota::kParamSecurityOrigin, |
| + &security_origin)) { |
| + return command->InvalidParamResponse( |
| + devtools::Page::queryUsageAndQuota::kParamSecurityOrigin); |
| + } |
| + |
| + ResponseCallback callback = base::Bind( |
| + &RendererOverridesHandler::PageQueryUsageAndQuotaCompleted, |
| + weak_factory_.GetWeakPtr(), |
| + command); |
| + |
| + scoped_refptr<quota::QuotaManager> quota_manager = |
| + agent_->GetRenderViewHost()->GetProcess()-> |
| + GetStoragePartition()->GetQuotaManager(); |
| + |
| + BrowserThread::PostTask( |
| + BrowserThread::IO, FROM_HERE, |
| + base::Bind( |
| + &QueryUsageAndQuotaOnIOThread, |
| + quota_manager, |
| + GURL(security_origin), |
| + callback)); |
| + |
| + return command->AsyncResponsePromise(); |
| +} |
| + |
| +void RendererOverridesHandler::PageQueryUsageAndQuotaCompleted( |
| + scoped_refptr<DevToolsProtocol::Command> command, |
| + scoped_ptr<base::DictionaryValue> response_data) { |
| + SendAsyncResponse(command->SuccessResponse(response_data.release())); |
| +} |
| // Input agent handlers ------------------------------------------------------ |