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

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

Issue 2785943005: DevTools: Fix Network.clearBrowserCookies (Closed)
Patch Set: 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 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 185
186 void DeletedCookieOnIO(std::unique_ptr<DeleteCookieCallback> callback) { 186 void DeletedCookieOnIO(std::unique_ptr<DeleteCookieCallback> callback) {
187 DCHECK_CURRENTLY_ON(BrowserThread::IO); 187 DCHECK_CURRENTLY_ON(BrowserThread::IO);
188 BrowserThread::PostTask( 188 BrowserThread::PostTask(
189 BrowserThread::UI, 189 BrowserThread::UI,
190 FROM_HERE, 190 FROM_HERE,
191 base::Bind(&DeleteCookieCallback::sendSuccess, 191 base::Bind(&DeleteCookieCallback::sendSuccess,
192 base::Passed(std::move(callback)))); 192 base::Passed(std::move(callback))));
193 } 193 }
194 194
195 void ClearedCookiesOnIO(int num_deleted) {
phulce 2017/03/31 16:40:42 It'd be nice to communicate this over the protocol
dgozman 2017/03/31 22:57:55 You can mark it "async" in protocol_config.json, i
phulce 2017/03/31 23:54:32 done
196 DCHECK_CURRENTLY_ON(BrowserThread::IO);
197 }
198
199 void ClearCookiesOnIO(ResourceContext* resource_context,
200 net::URLRequestContextGetter* context_getter) {
201 DCHECK_CURRENTLY_ON(BrowserThread::IO);
202 net::URLRequestContext* request_context =
203 context_getter->GetURLRequestContext();
204 request_context->cookie_store()->DeleteAllAsync(
205 base::Bind(&ClearedCookiesOnIO));
206 }
207
195 void DeleteCookieOnIO( 208 void DeleteCookieOnIO(
196 ResourceContext* resource_context, 209 ResourceContext* resource_context,
197 net::URLRequestContextGetter* context_getter, 210 net::URLRequestContextGetter* context_getter,
198 const GURL& url, 211 const GURL& url,
199 const std::string& cookie_name, 212 const std::string& cookie_name,
200 std::unique_ptr<DeleteCookieCallback> callback) { 213 std::unique_ptr<DeleteCookieCallback> callback) {
201 DCHECK_CURRENTLY_ON(BrowserThread::IO); 214 DCHECK_CURRENTLY_ON(BrowserThread::IO);
202 net::URLRequestContext* request_context = 215 net::URLRequestContext* request_context =
203 GetRequestContextOnIO(resource_context, context_getter, url); 216 GetRequestContextOnIO(resource_context, context_getter, url);
204 request_context->cookie_store()->DeleteCookieAsync( 217 request_context->cookie_store()->DeleteCookieAsync(
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 return Response::FallThrough(); 445 return Response::FallThrough();
433 } 446 }
434 447
435 Response NetworkHandler::ClearBrowserCache() { 448 Response NetworkHandler::ClearBrowserCache() {
436 if (host_) 449 if (host_)
437 GetContentClient()->browser()->ClearCache(host_); 450 GetContentClient()->browser()->ClearCache(host_);
438 return Response::OK(); 451 return Response::OK();
439 } 452 }
440 453
441 Response NetworkHandler::ClearBrowserCookies() { 454 Response NetworkHandler::ClearBrowserCookies() {
442 if (host_) 455 if (!host_) {
443 GetContentClient()->browser()->ClearCookies(host_); 456 return Response::InternalError();
457 }
458
459 BrowserThread::PostTask(
460 BrowserThread::IO, FROM_HERE,
461 base::Bind(&ClearCookiesOnIO,
462 base::Unretained(host_->GetSiteInstance()
463 ->GetBrowserContext()
464 ->GetResourceContext()),
465 base::Unretained(host_->GetProcess()
466 ->GetStoragePartition()
467 ->GetURLRequestContext())));
444 return Response::OK(); 468 return Response::OK();
445 } 469 }
446 470
447 void NetworkHandler::GetCookies(Maybe<Array<String>> protocol_urls, 471 void NetworkHandler::GetCookies(Maybe<Array<String>> protocol_urls,
448 std::unique_ptr<GetCookiesCallback> callback) { 472 std::unique_ptr<GetCookiesCallback> callback) {
449 if (!host_) { 473 if (!host_) {
450 callback->sendFailure(Response::InternalError()); 474 callback->sendFailure(Response::InternalError());
451 return; 475 return;
452 } 476 }
453 477
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
720 static_cast<double>(base::Time::kMicrosecondsPerSecond), 744 static_cast<double>(base::Time::kMicrosecondsPerSecond),
721 Page::ResourceTypeEnum::Document, error_string, cancelled); 745 Page::ResourceTypeEnum::Document, error_string, cancelled);
722 } 746 }
723 747
724 std::string NetworkHandler::UserAgentOverride() const { 748 std::string NetworkHandler::UserAgentOverride() const {
725 return enabled_ ? user_agent_ : std::string(); 749 return enabled_ ? user_agent_ : std::string();
726 } 750 }
727 751
728 } // namespace protocol 752 } // namespace protocol
729 } // namespace content 753 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698