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

Side by Side Diff: chrome/browser/download/download_history.cc

Issue 7053004: Fix leak of callback object in r86518. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/download/download_history.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 "chrome/browser/download/download_history.h" 5 #include "chrome/browser/download/download_history.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "chrome/browser/history/download_history_info.h" 8 #include "chrome/browser/history/download_history_info.h"
9 #include "chrome/browser/history/history_marshaling.h" 9 #include "chrome/browser/history/history_marshaling.h"
10 #include "chrome/browser/download/download_item.h" 10 #include "chrome/browser/download/download_item.h"
11 #include "chrome/browser/profiles/profile.h" 11 #include "chrome/browser/profiles/profile.h"
12 12
13 // Our download table ID starts at 1, so we use 0 to represent a download that 13 // Our download table ID starts at 1, so we use 0 to represent a download that
14 // has started, but has not yet had its data persisted in the table. We use fake 14 // has started, but has not yet had its data persisted in the table. We use fake
15 // database handles in incognito mode starting at -1 and progressively getting 15 // database handles in incognito mode starting at -1 and progressively getting
16 // more negative. 16 // more negative.
17 // static 17 // static
18 const int DownloadHistory::kUninitializedHandle = 0; 18 const int DownloadHistory::kUninitializedHandle = 0;
19 19
20 DownloadHistory::DownloadHistory(Profile* profile) 20 DownloadHistory::DownloadHistory(Profile* profile)
21 : profile_(profile), 21 : profile_(profile),
22 next_fake_db_handle_(kUninitializedHandle - 1) { 22 next_fake_db_handle_(kUninitializedHandle - 1) {
23 DCHECK(profile); 23 DCHECK(profile);
24 } 24 }
25 25
26 DownloadHistory::~DownloadHistory() { 26 DownloadHistory::~DownloadHistory() {
27 // For any outstanding requests to HistoryService::GetVisitCountToHost(),
28 // since they'll be cancelled and thus not call back to
29 // OnGotVisitCountToHost(), we need to delete the associated
30 // VisitedBeforeDoneCallbacks.
31 for (VisitedBeforeRequestsMap::iterator i(visited_before_requests_.begin());
32 i != visited_before_requests_.end(); ++i)
33 delete i->second.second;
27 } 34 }
28 35
29 void DownloadHistory::Load(HistoryService::DownloadQueryCallback* callback) { 36 void DownloadHistory::Load(HistoryService::DownloadQueryCallback* callback) {
30 DCHECK(callback); 37 DCHECK(callback);
31 HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); 38 HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS);
32 if (!hs) { 39 if (!hs) {
33 delete callback; 40 delete callback;
34 return; 41 return;
35 } 42 }
36 hs->QueryDownloads(&history_consumer_, callback); 43 hs->QueryDownloads(&history_consumer_, callback);
(...skipping 12 matching lines...) Expand all
49 HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); 56 HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS);
50 if (hs) { 57 if (hs) {
51 HistoryService::Handle handle = hs->GetVisitCountToHost(referrer_url, 58 HistoryService::Handle handle = hs->GetVisitCountToHost(referrer_url,
52 &history_consumer_, 59 &history_consumer_,
53 NewCallback(this, &DownloadHistory::OnGotVisitCountToHost)); 60 NewCallback(this, &DownloadHistory::OnGotVisitCountToHost));
54 visited_before_requests_[handle] = std::make_pair(download_id, callback); 61 visited_before_requests_[handle] = std::make_pair(download_id, callback);
55 return; 62 return;
56 } 63 }
57 } 64 }
58 callback->Run(download_id, false); 65 callback->Run(download_id, false);
66 delete callback;
59 } 67 }
60 68
61 void DownloadHistory::AddEntry( 69 void DownloadHistory::AddEntry(
62 DownloadItem* download_item, 70 DownloadItem* download_item,
63 HistoryService::DownloadCreateCallback* callback) { 71 HistoryService::DownloadCreateCallback* callback) {
64 DCHECK(download_item); 72 DCHECK(download_item);
65 // Do not store the download in the history database for a few special cases: 73 // Do not store the download in the history database for a few special cases:
66 // - incognito mode (that is the point of this mode) 74 // - incognito mode (that is the point of this mode)
67 // - extensions (users don't think of extension installation as 'downloading') 75 // - extensions (users don't think of extension installation as 'downloading')
68 // - temporary download, like in drag-and-drop 76 // - temporary download, like in drag-and-drop
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 int count, 146 int count,
139 base::Time first_visit) { 147 base::Time first_visit) {
140 VisitedBeforeRequestsMap::iterator request = 148 VisitedBeforeRequestsMap::iterator request =
141 visited_before_requests_.find(handle); 149 visited_before_requests_.find(handle);
142 DCHECK(request != visited_before_requests_.end()); 150 DCHECK(request != visited_before_requests_.end());
143 int32 download_id = request->second.first; 151 int32 download_id = request->second.first;
144 VisitedBeforeDoneCallback* callback = request->second.second; 152 VisitedBeforeDoneCallback* callback = request->second.second;
145 visited_before_requests_.erase(request); 153 visited_before_requests_.erase(request);
146 callback->Run(download_id, found_visits && count && 154 callback->Run(download_id, found_visits && count &&
147 (first_visit.LocalMidnight() < base::Time::Now().LocalMidnight())); 155 (first_visit.LocalMidnight() < base::Time::Now().LocalMidnight()));
156 delete callback;
148 } 157 }
OLDNEW
« no previous file with comments | « chrome/browser/download/download_history.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698