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..a67f1a5ab38dce8c480ce791cd4b1a98e6d6a89b 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,195 @@ void RendererOverridesHandler::ScreenshotCaptured( |
| } |
| } |
| +// Quota and Usage ------------------------------------------ |
| + |
| +typedef base::Callback<void(scoped_ptr<base::DictionaryValue>)> |
| + ResponseCallback; |
| + |
| +static void QueryAndUsageQuotaCompletedOnIOThread( |
|
pfeldman
2013/09/19 12:35:49
QueryUsageAndQuotaCompletedOnIOThread
pfeldman
2013/09/19 12:35:49
Please move into anonymous namespace.
SeRya
2013/09/19 14:54:24
Done.
SeRya
2013/09/19 14:54:24
Done.
|
| + base::DictionaryValue* usage, |
| + base::DictionaryValue* quota, |
| + ResponseCallback callback) { |
| + |
| + scoped_ptr<base::DictionaryValue> response_data(new base::DictionaryValue); |
| + response_data->Set("usage", usage->DeepCopy()); |
|
pfeldman
2013/09/19 12:35:49
Copying usage and quota leaks them, you should set
SeRya
2013/09/19 14:54:24
They don't leak because of using base::Owned (base
|
| + response_data->Set("quota", quota->DeepCopy()); |
| + |
| + BrowserThread::PostTask( |
| + BrowserThread::UI, FROM_HERE, |
| + base::Bind( |
|
pfeldman
2013/09/19 12:35:49
Does this fit 80 chars?
SeRya
2013/09/19 14:54:24
Done.
|
| + callback, |
| + base::Passed(&response_data))); |
| +} |
| + |
| +static void DidGetHostUsage( |
| + base::DictionaryValue* dictionary, |
| + const char* item_name, |
| + const base::Closure& barrier, |
| + int64 value) { |
| + dictionary->SetDouble(item_name, value); |
| + barrier.Run(); |
| +} |
| + |
| +namespace { |
| + |
| +struct GetHostUsageCommonParams { |
| + scoped_refptr<quota::QuotaManager> quota_manager; |
| + std::string host; |
| + base::DictionaryValue* usage; |
|
pfeldman
2013/09/19 12:35:49
why not scoped_ptr?
SeRya
2013/09/19 14:54:24
Because this object is owned by on_complete callba
|
| + base::Closure barrier; |
| +}; |
| + |
| +} // namespace |
| + |
| +static void GetHostUsage( |
|
pfeldman
2013/09/19 12:35:49
Please move these into anonymous namespace.
SeRya
2013/09/19 14:54:24
Done.
|
| + const GetHostUsageCommonParams& params, |
| + quota::StorageType storage_type, |
| + quota::QuotaClient::ID client_id, |
| + const char* item_name) { |
| + params.quota_manager->GetHostUsage(params.host, storage_type, client_id, |
| + base::Bind(&DidGetHostUsage, params.usage, item_name, params.barrier)); |
| +} |
| + |
| +static 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(); |
| +} |
| + |
| +static 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(); |
| +} |
| + |
| +static 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; |
| + |
| + base::Closure on_complete = base::Bind( |
| + &QueryAndUsageQuotaCompletedOnIOThread, |
| + base::Owned(usage), |
| + base::Owned(quota), |
| + callback); |
| + |
| + static const int kExpectedResults = 9; |
| + |
| + base::Closure barrier = BarrierClosure(kExpectedResults, on_complete); |
|
pfeldman
2013/09/19 12:35:49
Just inline on_complete.
SeRya
2013/09/19 14:54:24
Done.
|
| + 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( |
|
pfeldman
2013/09/19 12:35:49
No need to put them into columns according to the
SeRya
2013/09/19 14:54:24
Done.
|
| + &DidGetUsageAndQuotaForWebApps, |
| + quota, |
| + "temporaryHostQuota", |
| + barrier)); |
| + |
| + quota_manager->GetPersistentHostQuota( |
| + host, |
| + base::Bind( |
|
pfeldman
2013/09/19 12:35:49
ditto
SeRya
2013/09/19 14:54:24
Done.
|
| + &DidGetQuotaValue, |
| + quota, |
| + "persistentHostQuota", |
| + barrier)); |
| + |
| + GetHostUsageCommonParams params = { quota_manager, host, usage, barrier }; |
| + |
| + GetHostUsage( |
|
pfeldman
2013/09/19 12:35:49
Following code does the same and does not require
SeRya
2013/09/19 14:54:24
Done.
|
| + params, |
| + quota::kStorageTypeTemporary, |
| + quota::QuotaClient::kFileSystem, |
| + "temporaryFileSystemUsage"); |
| + |
| + GetHostUsage( |
| + params, |
| + quota::kStorageTypePersistent, |
| + quota::QuotaClient::kFileSystem, |
| + "persistentFileSystemUsage"); |
| + |
| + GetHostUsage( |
| + params, |
| + quota::kStorageTypeSyncable, |
| + quota::QuotaClient::kFileSystem, |
| + "syncableFileSystemUsage"); |
| + |
| + GetHostUsage( |
| + params, |
| + quota::kStorageTypeTemporary, |
| + quota::QuotaClient::kDatabase, |
| + "databaseUsage"); |
| + |
| + GetHostUsage( |
| + params, |
| + quota::kStorageTypeTemporary, |
| + quota::QuotaClient::kAppcache, |
| + "appcacheUsage"); |
| + |
| + GetHostUsage( |
| + params, |
| + quota::kStorageTypeTemporary, |
| + quota::QuotaClient::kIndexedDatabase, |
| + "indexedDatabaseUsage"); |
| +} |
| + |
| +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(); |
| + |
| + // Will be deleted when done. |
|
pfeldman
2013/09/19 12:35:49
What will be deleted when done?
SeRya
2013/09/19 14:54:24
Removed.
|
| + 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) { |
| + SendRawMessage( |
|
pfeldman
2013/09/19 12:35:49
SendAsyncResponse(command->SuccessResponse(respons
SeRya
2013/09/19 14:54:24
Done.
|
| + command->SuccessResponse(response_data.release())->Serialize()); |
| +} |
| // Input agent handlers ------------------------------------------------------ |