Chromium Code Reviews| Index: content/browser/devtools/protocol/storage_handler.cc |
| diff --git a/content/browser/devtools/protocol/storage_handler.cc b/content/browser/devtools/protocol/storage_handler.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ff9114bf12ba4455c8cc2ce4514e9f590cf9f24d |
| --- /dev/null |
| +++ b/content/browser/devtools/protocol/storage_handler.cc |
| @@ -0,0 +1,90 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "content/browser/devtools/protocol/storage_handler.h" |
| + |
| +#include <string> |
| + |
| +#include "base/strings/string_split.h" |
| +#include "content/browser/devtools/protocol/devtools_protocol_dispatcher.h" |
| +#include "content/public/browser/render_frame_host.h" |
| +#include "content/public/browser/render_process_host.h" |
| +#include "content/public/browser/storage_partition.h" |
| + |
| +namespace content { |
| +namespace devtools { |
| +namespace storage { |
| + |
| +namespace { |
| +static const char kAppCache[] = "appcache"; |
| +static const char kCookies[] = "cookies"; |
| +static const char kFileSystems[] = "filesystems"; |
| +static const char kIndexedDB[] = "indexeddb"; |
| +static const char kLocalStorage[] = "local_storage"; |
| +static const char kShaderCache[] = "shader_cache"; |
| +static const char kWebSQL[] = "websql"; |
| +static const char kWebRTCIdentity[] = "webrdc_identity"; |
| +static const char kServiceWorkers[] = "service_workers"; |
| +static const char kCacheStorage[] = "cache_storage"; |
| +static const char kAll[] = "all"; |
| +} |
| + |
| +typedef DevToolsProtocolClient::Response Response; |
| + |
| +StorageHandler::StorageHandler() |
| + : host_(nullptr) { |
| +} |
| + |
| +StorageHandler::~StorageHandler() = default; |
| + |
| +void StorageHandler::SetRenderFrameHost(RenderFrameHost* host) { |
| + host_ = host; |
| +} |
| + |
| +Response StorageHandler::ClearDataForOrigin( |
| + const std::string& storage_types, |
| + const std::string& origin) { |
| + if (!host_) |
| + return Response::InternalError("Not connected to host"); |
| + StoragePartition* partition = host_->GetProcess()->GetStoragePartition(); |
| + |
| + uint32_t remove_mask = 0; |
| + if (storage_types.find(kAppCache) != std::string::npos) |
|
caseq
2016/05/05 23:23:42
This approach will break when one of the option wo
pfeldman
2016/05/06 07:24:37
It is efficient though and accounts for the same n
|
| + remove_mask |= StoragePartition::REMOVE_DATA_MASK_APPCACHE; |
| + if (storage_types.find(kCookies) != std::string::npos) |
| + remove_mask |= StoragePartition::REMOVE_DATA_MASK_COOKIES; |
| + if (storage_types.find(kFileSystems) != std::string::npos) |
| + remove_mask |= StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS; |
| + if (storage_types.find(kIndexedDB) != std::string::npos) |
| + remove_mask |= StoragePartition::REMOVE_DATA_MASK_INDEXEDDB; |
| + if (storage_types.find(kLocalStorage) != std::string::npos) |
| + remove_mask |= StoragePartition::REMOVE_DATA_MASK_LOCAL_STORAGE; |
| + if (storage_types.find(kShaderCache) != std::string::npos) |
| + remove_mask |= StoragePartition::REMOVE_DATA_MASK_SHADER_CACHE; |
| + if (storage_types.find(kWebSQL) != std::string::npos) |
| + remove_mask |= StoragePartition::REMOVE_DATA_MASK_WEBSQL; |
| + if (storage_types.find(kWebRTCIdentity) != std::string::npos) |
| + remove_mask |= StoragePartition::REMOVE_DATA_MASK_WEBRTC_IDENTITY; |
| + if (storage_types.find(kServiceWorkers) != std::string::npos) |
| + remove_mask |= StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS; |
| + if (storage_types.find(kCacheStorage) != std::string::npos) |
| + remove_mask |= StoragePartition::REMOVE_DATA_MASK_CACHE_STORAGE; |
| + if (storage_types.find(kAll) != std::string::npos) |
| + remove_mask |= StoragePartition::REMOVE_DATA_MASK_ALL; |
| + |
| + if (!remove_mask) |
| + return Response::InvalidParams("No valid storage type specified"); |
| + |
| + partition->ClearDataForOrigin( |
| + remove_mask, |
| + StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL, |
| + GURL(origin), |
| + partition->GetURLRequestContext(), |
| + base::Bind(&base::DoNothing)); |
| + return Response::OK(); |
| +} |
| + |
| +} // namespace storage |
| +} // namespace devtools |
| +} // namespace content |