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

Side by Side Diff: content/browser/cancelable_request.cc

Issue 6646051: Fix DCHECK, memory leak, and refactor PasswordStore to use CancelableRequest (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Include password_store_consumer.h in mac/win unittests. Created 9 years, 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/cancelable_request.h" 5 #include "content/browser/cancelable_request.h"
6 6
7 CancelableRequestProvider::CancelableRequestProvider() : next_handle_(1) { 7 const CancelableRequestProvider::Handle
8 CancelableRequestProvider::kInvalidHandle = 0;
9 const CancelableRequestProvider::Handle
10 CancelableRequestProvider::kFirstHandle = 1;
11
12 CancelableRequestProvider::CancelableRequestProvider()
13 : next_handle_(CancelableRequestProvider::kFirstHandle) {
brettw 2011/03/22 21:43:41 Indent 2 more spaces.
Sheridan Rawlins 2011/03/22 22:04:09 Done.
8 } 14 }
9 15
10 CancelableRequestProvider::~CancelableRequestProvider() { 16 CancelableRequestProvider::~CancelableRequestProvider() {
11 // There may be requests whose result callback has not been run yet. We need 17 // There may be requests whose result callback has not been run yet. We need
12 // to cancel them otherwise they may try and call us back after we've been 18 // to cancel them otherwise they may try and call us back after we've been
13 // deleted, or do other bad things. This can occur on shutdown (or profile 19 // deleted, or do other bad things. This can occur on shutdown (or profile
14 // destruction) when a request is scheduled, completed (but not dispatched), 20 // destruction) when a request is scheduled, completed (but not dispatched),
15 // then the Profile is deleted. 21 // then the Profile is deleted.
16 base::AutoLock lock(pending_request_lock_); 22 base::AutoLock lock(pending_request_lock_);
17 while (!pending_requests_.empty()) 23 while (!pending_requests_.empty())
18 CancelRequestLocked(pending_requests_.begin()); 24 CancelRequestLocked(pending_requests_.begin());
19 } 25 }
20 26
21 CancelableRequestProvider::Handle CancelableRequestProvider::AddRequest( 27 CancelableRequestProvider::Handle CancelableRequestProvider::AddRequest(
22 CancelableRequestBase* request, 28 CancelableRequestBase* request,
23 CancelableRequestConsumerBase* consumer) { 29 CancelableRequestConsumerBase* consumer) {
24 Handle handle; 30 Handle handle;
25 { 31 {
26 base::AutoLock lock(pending_request_lock_); 32 base::AutoLock lock(pending_request_lock_);
27 33
28 handle = next_handle_; 34 handle = next_handle_;
29 pending_requests_[next_handle_] = request; 35 pending_requests_[next_handle_] = request;
30 ++next_handle_; 36 ++next_handle_;
37 DCHECK_NE(kInvalidHandle, next_handle_);
31 } 38 }
32 39
33 consumer->OnRequestAdded(this, handle); 40 consumer->OnRequestAdded(this, handle);
34 41
35 request->Init(this, handle, consumer); 42 request->Init(this, handle, consumer);
36 return handle; 43 return handle;
37 } 44 }
38 45
39 void CancelableRequestProvider::CancelRequest(Handle handle) { 46 void CancelableRequestProvider::CancelRequest(Handle handle) {
40 base::AutoLock lock(pending_request_lock_); 47 base::AutoLock lock(pending_request_lock_);
41 CancelRequestLocked(pending_requests_.find(handle)); 48 CancelRequestLocked(pending_requests_.find(handle));
42 } 49 }
43 50
51 CancelableRequestProvider::Handle CancelableRequestProvider::InvalidHandle() {
52 return kInvalidHandle;
53 }
54
55 bool CancelableRequestProvider::HandleIsValid(Handle handle) {
56 return handle != kInvalidHandle;
57 }
58
44 void CancelableRequestProvider::CancelRequestLocked( 59 void CancelableRequestProvider::CancelRequestLocked(
45 const CancelableRequestMap::iterator& item) { 60 const CancelableRequestMap::iterator& item) {
46 pending_request_lock_.AssertAcquired(); 61 pending_request_lock_.AssertAcquired();
47 if (item == pending_requests_.end()) { 62 if (item == pending_requests_.end()) {
48 NOTREACHED() << "Trying to cancel an unknown request"; 63 NOTREACHED() << "Trying to cancel an unknown request";
49 return; 64 return;
50 } 65 }
51 66
52 item->second->consumer()->OnRequestRemoved(this, item->first); 67 item->second->consumer()->OnRequestRemoved(this, item->first);
53 item->second->set_canceled(); 68 item->second->set_canceled();
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 } 112 }
98 113
99 void CancelableRequestBase::Init(CancelableRequestProvider* provider, 114 void CancelableRequestBase::Init(CancelableRequestProvider* provider,
100 CancelableRequestProvider::Handle handle, 115 CancelableRequestProvider::Handle handle,
101 CancelableRequestConsumerBase* consumer) { 116 CancelableRequestConsumerBase* consumer) {
102 DCHECK(handle_ == 0 && provider_ == NULL && consumer_ == NULL); 117 DCHECK(handle_ == 0 && provider_ == NULL && consumer_ == NULL);
103 provider_ = provider; 118 provider_ = provider;
104 consumer_ = consumer; 119 consumer_ = consumer;
105 handle_ = handle; 120 handle_ = handle;
106 } 121 }
OLDNEW
« content/browser/cancelable_request.h ('K') | « content/browser/cancelable_request.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698