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 |
30 void DownloadHistory::Load(HistoryService::DownloadQueryCallback* callback) { | 41 void DownloadHistory::Load(HistoryService::DownloadQueryCallback* callback) { |
31 DCHECK(callback); | 42 DCHECK(callback); |
32 HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); | 43 HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); |
33 if (!hs) { | 44 if (!hs) { |
34 delete callback; | 45 delete callback; |
35 return; | 46 return; |
36 } | 47 } |
37 hs->QueryDownloads(&history_consumer_, callback); | 48 hs->QueryDownloads(&history_consumer_, callback); |
38 | 49 |
39 // This is the initial load, so do a cleanup of corrupt in-progress entries. | 50 // 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... |
144 VisitedBeforeRequestsMap::iterator request = | 155 VisitedBeforeRequestsMap::iterator request = |
145 visited_before_requests_.find(handle); | 156 visited_before_requests_.find(handle); |
146 DCHECK(request != visited_before_requests_.end()); | 157 DCHECK(request != visited_before_requests_.end()); |
147 int32 download_id = request->second.first; | 158 int32 download_id = request->second.first; |
148 VisitedBeforeDoneCallback* callback = request->second.second; | 159 VisitedBeforeDoneCallback* callback = request->second.second; |
149 visited_before_requests_.erase(request); | 160 visited_before_requests_.erase(request); |
150 callback->Run(download_id, found_visits && count && | 161 callback->Run(download_id, found_visits && count && |
151 (first_visit.LocalMidnight() < base::Time::Now().LocalMidnight())); | 162 (first_visit.LocalMidnight() < base::Time::Now().LocalMidnight())); |
152 delete callback; | 163 delete callback; |
153 } | 164 } |
OLD | NEW |