OLD | NEW |
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/download/chrome_download_manager_delegate.h" | 8 #include "chrome/browser/download/chrome_download_manager_delegate.h" |
9 #include "chrome/browser/history/history_marshaling.h" | 9 #include "chrome/browser/history/history_marshaling.h" |
10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
11 #include "content/browser/download/download_item.h" | 11 #include "content/browser/download/download_item.h" |
12 #include "content/browser/download/download_persistent_store_info.h" | 12 #include "content/browser/download/download_persistent_store_info.h" |
13 | 13 |
14 DownloadHistory::DownloadHistory(Profile* profile) | 14 DownloadHistory::DownloadHistory(Profile* profile) |
15 : profile_(profile), | 15 : profile_(profile), |
16 next_fake_db_handle_(DownloadItem::kUninitializedHandle - 1) { | 16 next_fake_db_handle_(DownloadItem::kUninitializedHandle - 1) { |
17 DCHECK(profile); | 17 DCHECK(profile); |
18 } | 18 } |
19 | 19 |
20 DownloadHistory::~DownloadHistory() { | 20 DownloadHistory::~DownloadHistory() { |
21 // For any outstanding requests to | 21 // For any outstanding requests to |
22 // HistoryService::GetVisibleVisitCountToHost(), since they'll be cancelled | 22 // HistoryService::GetVisibleVisitCountToHost(), since they'll be cancelled |
23 // and thus not call back to OnGotVisitCountToHost(), we need to delete the | 23 // and thus not call back to OnGotVisitCountToHost(), we need to delete the |
24 // associated VisitedBeforeDoneCallbacks. | 24 // associated VisitedBeforeDoneCallbacks. |
25 for (VisitedBeforeRequestsMap::iterator i(visited_before_requests_.begin()); | 25 for (VisitedBeforeRequestsMap::iterator i(visited_before_requests_.begin()); |
26 i != visited_before_requests_.end(); ++i) | 26 i != visited_before_requests_.end(); ++i) |
27 delete i->second.second; | 27 delete i->second.second; |
28 } | 28 } |
29 | 29 |
30 void DownloadHistory::GetNextId( | |
31 HistoryService::DownloadNextIdCallback* callback) { | |
32 DCHECK(callback); | |
33 HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); | |
34 if (!hs) { | |
35 delete callback; | |
36 return; | |
37 } | |
38 hs->GetNextDownloadId(&history_consumer_, callback); | |
39 } | |
40 | |
41 void DownloadHistory::Load(HistoryService::DownloadQueryCallback* callback) { | 30 void DownloadHistory::Load(HistoryService::DownloadQueryCallback* callback) { |
42 DCHECK(callback); | 31 DCHECK(callback); |
43 HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); | 32 HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); |
44 if (!hs) { | 33 if (!hs) { |
45 delete callback; | 34 delete callback; |
46 return; | 35 return; |
47 } | 36 } |
48 hs->QueryDownloads(&history_consumer_, callback); | 37 hs->QueryDownloads(&history_consumer_, callback); |
49 | 38 |
50 // This is the initial load, so do a cleanup of corrupt in-progress entries. | 39 // This is the initial load, so do a cleanup of corrupt in-progress entries. |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 VisitedBeforeRequestsMap::iterator request = | 144 VisitedBeforeRequestsMap::iterator request = |
156 visited_before_requests_.find(handle); | 145 visited_before_requests_.find(handle); |
157 DCHECK(request != visited_before_requests_.end()); | 146 DCHECK(request != visited_before_requests_.end()); |
158 int32 download_id = request->second.first; | 147 int32 download_id = request->second.first; |
159 VisitedBeforeDoneCallback* callback = request->second.second; | 148 VisitedBeforeDoneCallback* callback = request->second.second; |
160 visited_before_requests_.erase(request); | 149 visited_before_requests_.erase(request); |
161 callback->Run(download_id, found_visits && count && | 150 callback->Run(download_id, found_visits && count && |
162 (first_visit.LocalMidnight() < base::Time::Now().LocalMidnight())); | 151 (first_visit.LocalMidnight() < base::Time::Now().LocalMidnight())); |
163 delete callback; | 152 delete callback; |
164 } | 153 } |
OLD | NEW |