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..679bc07aecffa6c9da2beb28869fff2c865bd16b 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,165 @@ void RendererOverridesHandler::ScreenshotCaptured( |
| } |
| } |
| +// Quota and Usage ------------------------------------------ |
| + |
| +namespace { |
| + |
| +typedef base::Callback<void(scoped_ptr<base::DictionaryValue>)> |
| + ResponseCallback; |
| + |
| +void QueryUsageAndQuotaCompletedOnIOThread( |
| + base::DictionaryValue* usage, |
| + base::DictionaryValue* quota, |
| + ResponseCallback callback) { |
| + |
| + scoped_ptr<base::DictionaryValue> response_data(new base::DictionaryValue); |
| + response_data->Set("usage", usage->DeepCopy()); |
| + response_data->Set("quota", quota->DeepCopy()); |
| + |
| + BrowserThread::PostTask( |
| + BrowserThread::UI, FROM_HERE, |
| + base::Bind(callback, base::Passed(&response_data))); |
| +} |
| + |
| +void DidGetHostUsage( |
| + base::DictionaryValue* dictionary, |
| + const char* item_name, |
| + const base::Closure& barrier, |
| + int64 value) { |
| + dictionary->SetDouble(item_name, value); |
| + 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::DictionaryValue* usage = new base::DictionaryValue; |
| + base::DictionaryValue* quota = new base::DictionaryValue; |
| + |
| + static const int kExpectedResults = 9; |
| + |
| + base::Closure barrier = BarrierClosure( |
| + kExpectedResults, |
| + base::Bind(&QueryUsageAndQuotaCompletedOnIOThread, |
| + base::Owned(usage), |
|
pfeldman
2013/09/19 15:15:34
Then you could remove base::Owned and get rid of t
SeRya
2013/09/19 17:24:52
Done.
|
| + base::Owned(quota), |
| + callback)); |
| + std::string host = net::GetHostOrSpecFromURL(security_origin); |
| + |
| + quota_manager->GetAvailableSpace( |
| + base::Bind(&DidGetQuotaValue, quota, "availableSpace", barrier)); |
| + |
| + quota_manager->GetUsageAndQuotaForWebApps( |
| + security_origin, |
| + quota::kStorageTypeTemporary, |
| + base::Bind(&DidGetUsageAndQuotaForWebApps, quota, |
| + "temporaryHostQuota", barrier)); |
| + |
| + quota_manager->GetPersistentHostQuota( |
| + host, |
| + base::Bind(&DidGetQuotaValue, quota, "persistentHostQuota", barrier)); |
| + |
| + quota_manager->GetHostUsage(host, quota::kStorageTypeTemporary, |
| + quota::QuotaClient::kFileSystem, |
| + base::Bind(&DidGetHostUsage, usage, |
| + "temporaryFileSystemUsage", |
|
pfeldman
2013/09/19 15:15:34
Could you share a protocol.json? If it mentions th
SeRya
2013/09/19 17:24:52
https://codereview.chromium.org/23264011/diff/4001
|
| + barrier)); |
| + |
| + quota_manager->GetHostUsage(host, quota::kStorageTypePersistent, |
| + quota::QuotaClient::kFileSystem, |
| + base::Bind(&DidGetHostUsage, usage, |
| + "persistentFileSystemUsage", |
| + barrier)); |
| + |
| + quota_manager->GetHostUsage(host, quota::kStorageTypeSyncable, |
| + quota::QuotaClient::kFileSystem, |
| + base::Bind(&DidGetHostUsage, usage, |
| + "syncableFileSystemUsage", |
| + barrier)); |
| + |
| + quota_manager->GetHostUsage(host, quota::kStorageTypeTemporary, |
| + quota::QuotaClient::kDatabase, |
| + base::Bind(&DidGetHostUsage, usage, |
| + "databaseUsage", |
| + barrier)); |
| + |
| + quota_manager->GetHostUsage(host, quota::kStorageTypeTemporary, |
| + quota::QuotaClient::kAppcache, |
| + base::Bind(&DidGetHostUsage, usage, |
| + "appcacheUsage", |
| + barrier)); |
| + |
| + quota_manager->GetHostUsage(host, quota::kStorageTypeTemporary, |
| + quota::QuotaClient::kIndexedDatabase, |
| + base::Bind(&DidGetHostUsage, usage, |
| + "indexedDatabaseUsage", |
| + 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 ------------------------------------------------------ |