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