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

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: use non-zero tests until http://crbug.com/77650 is addressed. 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
« no previous file with comments | « chrome/test/live_sync/live_passwords_sync_test.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 CancelableRequestProvider::CancelableRequestProvider()
8 : next_handle_(1) {
8 } 9 }
9 10
10 CancelableRequestProvider::~CancelableRequestProvider() { 11 CancelableRequestProvider::~CancelableRequestProvider() {
11 // There may be requests whose result callback has not been run yet. We need 12 // 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 13 // 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 14 // deleted, or do other bad things. This can occur on shutdown (or profile
14 // destruction) when a request is scheduled, completed (but not dispatched), 15 // destruction) when a request is scheduled, completed (but not dispatched),
15 // then the Profile is deleted. 16 // then the Profile is deleted.
16 base::AutoLock lock(pending_request_lock_); 17 base::AutoLock lock(pending_request_lock_);
17 while (!pending_requests_.empty()) 18 while (!pending_requests_.empty())
18 CancelRequestLocked(pending_requests_.begin()); 19 CancelRequestLocked(pending_requests_.begin());
19 } 20 }
20 21
21 CancelableRequestProvider::Handle CancelableRequestProvider::AddRequest( 22 CancelableRequestProvider::Handle CancelableRequestProvider::AddRequest(
22 CancelableRequestBase* request, 23 CancelableRequestBase* request,
23 CancelableRequestConsumerBase* consumer) { 24 CancelableRequestConsumerBase* consumer) {
24 Handle handle; 25 Handle handle;
25 { 26 {
26 base::AutoLock lock(pending_request_lock_); 27 base::AutoLock lock(pending_request_lock_);
27 28
28 handle = next_handle_; 29 handle = next_handle_;
29 pending_requests_[next_handle_] = request; 30 pending_requests_[next_handle_] = request;
30 ++next_handle_; 31 ++next_handle_;
32 DCHECK(next_handle_)
33 << "next_handle_ may have wrapped around to invalid state.";
31 } 34 }
32 35
33 consumer->OnRequestAdded(this, handle); 36 consumer->OnRequestAdded(this, handle);
34 37
35 request->Init(this, handle, consumer); 38 request->Init(this, handle, consumer);
36 return handle; 39 return handle;
37 } 40 }
38 41
39 void CancelableRequestProvider::CancelRequest(Handle handle) { 42 void CancelableRequestProvider::CancelRequest(Handle handle) {
40 base::AutoLock lock(pending_request_lock_); 43 base::AutoLock lock(pending_request_lock_);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 } 100 }
98 101
99 void CancelableRequestBase::Init(CancelableRequestProvider* provider, 102 void CancelableRequestBase::Init(CancelableRequestProvider* provider,
100 CancelableRequestProvider::Handle handle, 103 CancelableRequestProvider::Handle handle,
101 CancelableRequestConsumerBase* consumer) { 104 CancelableRequestConsumerBase* consumer) {
102 DCHECK(handle_ == 0 && provider_ == NULL && consumer_ == NULL); 105 DCHECK(handle_ == 0 && provider_ == NULL && consumer_ == NULL);
103 provider_ = provider; 106 provider_ = provider;
104 consumer_ = consumer; 107 consumer_ = consumer;
105 handle_ = handle; 108 handle_ = handle;
106 } 109 }
OLDNEW
« no previous file with comments | « chrome/test/live_sync/live_passwords_sync_test.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698