| 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/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" |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 } | 90 } |
| 91 | 91 |
| 92 int32 id = download_item->id(); | 92 int32 id = download_item->id(); |
| 93 DownloadHistoryInfo history_info = download_item->GetHistoryInfo(); | 93 DownloadHistoryInfo history_info = download_item->GetHistoryInfo(); |
| 94 hs->CreateDownload(id, history_info, &history_consumer_, callback); | 94 hs->CreateDownload(id, history_info, &history_consumer_, callback); |
| 95 } | 95 } |
| 96 | 96 |
| 97 void DownloadHistory::UpdateEntry(DownloadItem* download_item) { | 97 void DownloadHistory::UpdateEntry(DownloadItem* download_item) { |
| 98 // Don't store info in the database if the download was initiated while in | 98 // Don't store info in the database if the download was initiated while in |
| 99 // incognito mode or if it hasn't been initialized in our database table. | 99 // incognito mode or if it hasn't been initialized in our database table. |
| 100 if (download_item->db_handle() <= kUninitializedHandle) | 100 if (download_item->id() <= kUninitializedHandle) |
| 101 return; | 101 return; |
| 102 | 102 |
| 103 HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); | 103 HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); |
| 104 if (!hs) | 104 if (!hs) |
| 105 return; | 105 return; |
| 106 | 106 |
| 107 hs->UpdateDownload(download_item->received_bytes(), | 107 hs->UpdateDownload(download_item->received_bytes(), |
| 108 download_item->state(), | 108 download_item->state(), |
| 109 download_item->db_handle()); | 109 download_item->id()); |
| 110 } | 110 } |
| 111 | 111 |
| 112 void DownloadHistory::UpdateDownloadPath(DownloadItem* download_item, | 112 void DownloadHistory::UpdateDownloadPath(DownloadItem* download_item, |
| 113 const FilePath& new_path) { | 113 const FilePath& new_path) { |
| 114 // No update necessary if the download was initiated while in incognito mode. | 114 // No update necessary if the download was initiated while in incognito mode. |
| 115 if (download_item->db_handle() <= kUninitializedHandle) | 115 if (download_item->id() <= kUninitializedHandle) |
| 116 return; | 116 return; |
| 117 | 117 |
| 118 HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); | 118 HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); |
| 119 if (hs) | 119 if (hs) |
| 120 hs->UpdateDownloadPath(new_path, download_item->db_handle()); | 120 hs->UpdateDownloadPath(new_path, download_item->id()); |
| 121 } | 121 } |
| 122 | 122 |
| 123 void DownloadHistory::RemoveEntry(DownloadItem* download_item) { | 123 void DownloadHistory::RemoveEntry(DownloadItem* download_item) { |
| 124 // No update necessary if the download was initiated while in incognito mode. | 124 // No update necessary if the download was initiated while in incognito mode. |
| 125 if (download_item->db_handle() <= kUninitializedHandle) | 125 if (download_item->id() <= kUninitializedHandle) |
| 126 return; | 126 return; |
| 127 | 127 |
| 128 HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); | 128 HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); |
| 129 if (hs) | 129 if (hs) |
| 130 hs->RemoveDownload(download_item->db_handle()); | 130 hs->RemoveDownload(download_item->id()); |
| 131 } | 131 } |
| 132 | 132 |
| 133 void DownloadHistory::RemoveEntriesBetween(const base::Time remove_begin, | 133 void DownloadHistory::RemoveEntriesBetween(const base::Time remove_begin, |
| 134 const base::Time remove_end) { | 134 const base::Time remove_end) { |
| 135 HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); | 135 HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); |
| 136 if (hs) | 136 if (hs) |
| 137 hs->RemoveDownloadsBetween(remove_begin, remove_end); | 137 hs->RemoveDownloadsBetween(remove_begin, remove_end); |
| 138 } | 138 } |
| 139 | 139 |
| 140 int64 DownloadHistory::GetNextFakeDbHandle() { | 140 int64 DownloadHistory::GetNextFakeDbHandle() { |
| 141 return next_fake_db_handle_--; | 141 return next_fake_db_handle_--; |
| 142 } | 142 } |
| 143 | 143 |
| 144 void DownloadHistory::OnGotVisitCountToHost(HistoryService::Handle handle, | 144 void DownloadHistory::OnGotVisitCountToHost(HistoryService::Handle handle, |
| 145 bool found_visits, | 145 bool found_visits, |
| 146 int count, | 146 int count, |
| 147 base::Time first_visit) { | 147 base::Time first_visit) { |
| 148 VisitedBeforeRequestsMap::iterator request = | 148 VisitedBeforeRequestsMap::iterator request = |
| 149 visited_before_requests_.find(handle); | 149 visited_before_requests_.find(handle); |
| 150 DCHECK(request != visited_before_requests_.end()); | 150 DCHECK(request != visited_before_requests_.end()); |
| 151 int32 download_id = request->second.first; | 151 int32 download_id = request->second.first; |
| 152 VisitedBeforeDoneCallback* callback = request->second.second; | 152 VisitedBeforeDoneCallback* callback = request->second.second; |
| 153 visited_before_requests_.erase(request); | 153 visited_before_requests_.erase(request); |
| 154 callback->Run(download_id, found_visits && count && | 154 callback->Run(download_id, found_visits && count && |
| 155 (first_visit.LocalMidnight() < base::Time::Now().LocalMidnight())); | 155 (first_visit.LocalMidnight() < base::Time::Now().LocalMidnight())); |
| 156 delete callback; | 156 delete callback; |
| 157 } | 157 } |
| OLD | NEW |