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

Side by Side Diff: content/browser/devtools/protocol/storage_handler.cc

Issue 1949373002: DevTools: introduce Storage.clearDataForOrigin protocol command. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months 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
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "content/browser/devtools/protocol/storage_handler.h"
6
7 #include <string>
8
9 #include "base/strings/string_split.h"
10 #include "content/browser/devtools/protocol/devtools_protocol_dispatcher.h"
11 #include "content/public/browser/render_frame_host.h"
12 #include "content/public/browser/render_process_host.h"
13 #include "content/public/browser/storage_partition.h"
14
15 namespace content {
16 namespace devtools {
17 namespace storage {
18
19 namespace {
20 static const char kAppCache[] = "appcache";
21 static const char kCookies[] = "cookies";
22 static const char kFileSystems[] = "filesystems";
23 static const char kIndexedDB[] = "indexeddb";
24 static const char kLocalStorage[] = "local_storage";
25 static const char kShaderCache[] = "shader_cache";
26 static const char kWebSQL[] = "websql";
27 static const char kWebRTCIdentity[] = "webrdc_identity";
28 static const char kServiceWorkers[] = "service_workers";
29 static const char kCacheStorage[] = "cache_storage";
30 static const char kAll[] = "all";
31 }
32
33 typedef DevToolsProtocolClient::Response Response;
34
35 StorageHandler::StorageHandler()
36 : host_(nullptr) {
37 }
38
39 StorageHandler::~StorageHandler() = default;
40
41 void StorageHandler::SetRenderFrameHost(RenderFrameHost* host) {
42 host_ = host;
43 }
44
45 Response StorageHandler::ClearDataForOrigin(
46 const std::string& storage_types,
47 const std::string& origin) {
48 if (!host_)
49 return Response::InternalError("Not connected to host");
50 StoragePartition* partition = host_->GetProcess()->GetStoragePartition();
51
52 uint32_t remove_mask = 0;
53 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
54 remove_mask |= StoragePartition::REMOVE_DATA_MASK_APPCACHE;
55 if (storage_types.find(kCookies) != std::string::npos)
56 remove_mask |= StoragePartition::REMOVE_DATA_MASK_COOKIES;
57 if (storage_types.find(kFileSystems) != std::string::npos)
58 remove_mask |= StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS;
59 if (storage_types.find(kIndexedDB) != std::string::npos)
60 remove_mask |= StoragePartition::REMOVE_DATA_MASK_INDEXEDDB;
61 if (storage_types.find(kLocalStorage) != std::string::npos)
62 remove_mask |= StoragePartition::REMOVE_DATA_MASK_LOCAL_STORAGE;
63 if (storage_types.find(kShaderCache) != std::string::npos)
64 remove_mask |= StoragePartition::REMOVE_DATA_MASK_SHADER_CACHE;
65 if (storage_types.find(kWebSQL) != std::string::npos)
66 remove_mask |= StoragePartition::REMOVE_DATA_MASK_WEBSQL;
67 if (storage_types.find(kWebRTCIdentity) != std::string::npos)
68 remove_mask |= StoragePartition::REMOVE_DATA_MASK_WEBRTC_IDENTITY;
69 if (storage_types.find(kServiceWorkers) != std::string::npos)
70 remove_mask |= StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS;
71 if (storage_types.find(kCacheStorage) != std::string::npos)
72 remove_mask |= StoragePartition::REMOVE_DATA_MASK_CACHE_STORAGE;
73 if (storage_types.find(kAll) != std::string::npos)
74 remove_mask |= StoragePartition::REMOVE_DATA_MASK_ALL;
75
76 if (!remove_mask)
77 return Response::InvalidParams("No valid storage type specified");
78
79 partition->ClearDataForOrigin(
80 remove_mask,
81 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL,
82 GURL(origin),
83 partition->GetURLRequestContext(),
84 base::Bind(&base::DoNothing));
85 return Response::OK();
86 }
87
88 } // namespace storage
89 } // namespace devtools
90 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698