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

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

Issue 2785943005: DevTools: Fix Network.clearBrowserCookies (Closed)
Patch Set: turn into async Created 3 years, 8 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/devtools/protocol/network_handler.h" 5 #include "content/browser/devtools/protocol/network_handler.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/barrier_closure.h" 9 #include "base/barrier_closure.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 30 matching lines...) Expand all
41 41
42 namespace content { 42 namespace content {
43 namespace protocol { 43 namespace protocol {
44 namespace { 44 namespace {
45 45
46 using ProtocolCookieArray = Array<Network::Cookie>; 46 using ProtocolCookieArray = Array<Network::Cookie>;
47 using GetCookiesCallback = Network::Backend::GetCookiesCallback; 47 using GetCookiesCallback = Network::Backend::GetCookiesCallback;
48 using GetAllCookiesCallback = Network::Backend::GetAllCookiesCallback; 48 using GetAllCookiesCallback = Network::Backend::GetAllCookiesCallback;
49 using SetCookieCallback = Network::Backend::SetCookieCallback; 49 using SetCookieCallback = Network::Backend::SetCookieCallback;
50 using DeleteCookieCallback = Network::Backend::DeleteCookieCallback; 50 using DeleteCookieCallback = Network::Backend::DeleteCookieCallback;
51 using ClearBrowserCookiesCallback =
52 Network::Backend::ClearBrowserCookiesCallback;
51 53
52 net::URLRequestContext* GetRequestContextOnIO( 54 net::URLRequestContext* GetRequestContextOnIO(
53 ResourceContext* resource_context, 55 ResourceContext* resource_context,
54 net::URLRequestContextGetter* context_getter, 56 net::URLRequestContextGetter* context_getter,
55 const GURL& url) { 57 const GURL& url) {
56 DCHECK_CURRENTLY_ON(BrowserThread::IO); 58 DCHECK_CURRENTLY_ON(BrowserThread::IO);
57 net::URLRequestContext* context = 59 net::URLRequestContext* context =
58 GetContentClient()->browser()->OverrideRequestContextForURL( 60 GetContentClient()->browser()->OverrideRequestContextForURL(
59 url, resource_context); 61 url, resource_context);
60 if (!context) 62 if (!context)
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 178
177 std::unique_ptr<GetCookiesCallback> callback_; 179 std::unique_ptr<GetCookiesCallback> callback_;
178 std::unique_ptr<GetAllCookiesCallback> all_callback_; 180 std::unique_ptr<GetAllCookiesCallback> all_callback_;
179 int callback_count_ = 0; 181 int callback_count_ = 0;
180 std::unordered_map<std::string, net::CanonicalCookie> cookies_; 182 std::unordered_map<std::string, net::CanonicalCookie> cookies_;
181 183
182 private: 184 private:
183 friend class base::RefCountedThreadSafe<CookieRetriever>; 185 friend class base::RefCountedThreadSafe<CookieRetriever>;
184 }; 186 };
185 187
188 void ClearedCookiesOnIO(std::unique_ptr<ClearBrowserCookiesCallback> callback,
189 int num_deleted) {
190 DCHECK_CURRENTLY_ON(BrowserThread::IO);
191 callback->sendSuccess(num_deleted);
pfeldman 2017/04/01 00:23:23 We should get back to UI!
phulce 2017/04/03 17:04:04 Like in an alert post-confirmation?
192 }
193
194 void ClearCookiesOnIO(ResourceContext* resource_context,
195 net::URLRequestContextGetter* context_getter,
196 std::unique_ptr<ClearBrowserCookiesCallback> callback) {
197 DCHECK_CURRENTLY_ON(BrowserThread::IO);
198 net::URLRequestContext* request_context =
199 context_getter->GetURLRequestContext();
200 request_context->cookie_store()->DeleteAllAsync(
201 base::Bind(&ClearedCookiesOnIO, base::Passed(std::move(callback))));
202 }
203
186 void DeletedCookieOnIO(std::unique_ptr<DeleteCookieCallback> callback) { 204 void DeletedCookieOnIO(std::unique_ptr<DeleteCookieCallback> callback) {
187 DCHECK_CURRENTLY_ON(BrowserThread::IO); 205 DCHECK_CURRENTLY_ON(BrowserThread::IO);
188 BrowserThread::PostTask( 206 BrowserThread::PostTask(
189 BrowserThread::UI, 207 BrowserThread::UI,
190 FROM_HERE, 208 FROM_HERE,
191 base::Bind(&DeleteCookieCallback::sendSuccess, 209 base::Bind(&DeleteCookieCallback::sendSuccess,
192 base::Passed(std::move(callback)))); 210 base::Passed(std::move(callback))));
193 } 211 }
194 212
195 void DeleteCookieOnIO( 213 void DeleteCookieOnIO(
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 user_agent_ = std::string(); 449 user_agent_ = std::string();
432 return Response::FallThrough(); 450 return Response::FallThrough();
433 } 451 }
434 452
435 Response NetworkHandler::ClearBrowserCache() { 453 Response NetworkHandler::ClearBrowserCache() {
436 if (host_) 454 if (host_)
437 GetContentClient()->browser()->ClearCache(host_); 455 GetContentClient()->browser()->ClearCache(host_);
438 return Response::OK(); 456 return Response::OK();
439 } 457 }
440 458
441 Response NetworkHandler::ClearBrowserCookies() { 459 void NetworkHandler::ClearBrowserCookies(
442 if (host_) 460 std::unique_ptr<ClearBrowserCookiesCallback> callback) {
443 GetContentClient()->browser()->ClearCookies(host_); 461 if (!host_) {
444 return Response::OK(); 462 callback->sendFailure(Response::InternalError());
463 return;
464 }
465
466 BrowserThread::PostTask(
467 BrowserThread::IO, FROM_HERE,
468 base::Bind(&ClearCookiesOnIO,
469 base::Unretained(host_->GetSiteInstance()
470 ->GetBrowserContext()
471 ->GetResourceContext()),
472 base::Unretained(host_->GetProcess()
473 ->GetStoragePartition()
474 ->GetURLRequestContext()),
475 base::Passed(std::move(callback))));
445 } 476 }
446 477
447 void NetworkHandler::GetCookies(Maybe<Array<String>> protocol_urls, 478 void NetworkHandler::GetCookies(Maybe<Array<String>> protocol_urls,
448 std::unique_ptr<GetCookiesCallback> callback) { 479 std::unique_ptr<GetCookiesCallback> callback) {
449 if (!host_) { 480 if (!host_) {
450 callback->sendFailure(Response::InternalError()); 481 callback->sendFailure(Response::InternalError());
451 return; 482 return;
452 } 483 }
453 484
454 std::vector<GURL> urls = ComputeCookieURLs(host_, protocol_urls); 485 std::vector<GURL> urls = ComputeCookieURLs(host_, protocol_urls);
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
720 static_cast<double>(base::Time::kMicrosecondsPerSecond), 751 static_cast<double>(base::Time::kMicrosecondsPerSecond),
721 Page::ResourceTypeEnum::Document, error_string, cancelled); 752 Page::ResourceTypeEnum::Document, error_string, cancelled);
722 } 753 }
723 754
724 std::string NetworkHandler::UserAgentOverride() const { 755 std::string NetworkHandler::UserAgentOverride() const {
725 return enabled_ ? user_agent_ : std::string(); 756 return enabled_ ? user_agent_ : std::string();
726 } 757 }
727 758
728 } // namespace protocol 759 } // namespace protocol
729 } // namespace content 760 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/devtools/protocol/network_handler.h ('k') | content/browser/devtools/protocol_config.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698