| OLD | NEW |
| 1 // Copyright (c) 2010 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_create_info.h" | 8 #include "chrome/browser/history/download_create_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" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 33 delete callback; | 33 delete callback; |
| 34 return; | 34 return; |
| 35 } | 35 } |
| 36 hs->QueryDownloads(&history_consumer_, callback); | 36 hs->QueryDownloads(&history_consumer_, callback); |
| 37 | 37 |
| 38 // This is the initial load, so do a cleanup of corrupt in-progress entries. | 38 // This is the initial load, so do a cleanup of corrupt in-progress entries. |
| 39 hs->CleanUpInProgressEntries(); | 39 hs->CleanUpInProgressEntries(); |
| 40 } | 40 } |
| 41 | 41 |
| 42 void DownloadHistory::AddEntry( | 42 void DownloadHistory::AddEntry( |
| 43 const DownloadCreateInfo& info, | |
| 44 DownloadItem* download_item, | 43 DownloadItem* download_item, |
| 45 HistoryService::DownloadCreateCallback* callback) { | 44 HistoryService::DownloadCreateCallback* callback) { |
| 45 DCHECK(download_item != NULL); |
| 46 // Do not store the download in the history database for a few special cases: | 46 // Do not store the download in the history database for a few special cases: |
| 47 // - incognito mode (that is the point of this mode) | 47 // - incognito mode (that is the point of this mode) |
| 48 // - extensions (users don't think of extension installation as 'downloading') | 48 // - extensions (users don't think of extension installation as 'downloading') |
| 49 // - temporary download, like in drag-and-drop | 49 // - temporary download, like in drag-and-drop |
| 50 // - history service is not available (e.g. in tests) | 50 // - history service is not available (e.g. in tests) |
| 51 // We have to make sure that these handles don't collide with normal db | 51 // We have to make sure that these handles don't collide with normal db |
| 52 // handles, so we use a negative value. Eventually, they could overlap, but | 52 // handles, so we use a negative value. Eventually, they could overlap, but |
| 53 // you'd have to do enough downloading that your ISP would likely stab you in | 53 // you'd have to do enough downloading that your ISP would likely stab you in |
| 54 // the neck first. YMMV. | 54 // the neck first. YMMV. |
| 55 // TODO(paulg) see bug 958058. EXPLICIT_ACCESS below is wrong. | 55 // TODO(paulg) see bug 958058. EXPLICIT_ACCESS below is wrong. |
| 56 HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); | 56 HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); |
| 57 if (download_item->is_otr() || download_item->is_extension_install() || | 57 if (download_item->is_otr() || download_item->is_extension_install() || |
| 58 download_item->is_temporary() || !hs) { | 58 download_item->is_temporary() || !hs) { |
| 59 callback->RunWithParams( | 59 callback->RunWithParams( |
| 60 history::DownloadCreateRequest::TupleType(info, GetNextFakeDbHandle())); | 60 history::DownloadCreateRequest::TupleType(download_item->id(), |
| 61 GetNextFakeDbHandle())); |
| 61 delete callback; | 62 delete callback; |
| 62 return; | 63 return; |
| 63 } | 64 } |
| 64 | 65 |
| 65 hs->CreateDownload(info, &history_consumer_, callback); | 66 hs->CreateDownload(DownloadHistoryInfo(*download_item), |
| 67 &history_consumer_, |
| 68 callback); |
| 66 } | 69 } |
| 67 | 70 |
| 68 void DownloadHistory::UpdateEntry(DownloadItem* download_item) { | 71 void DownloadHistory::UpdateEntry(DownloadItem* download_item) { |
| 69 // Don't store info in the database if the download was initiated while in | 72 // Don't store info in the database if the download was initiated while in |
| 70 // incognito mode or if it hasn't been initialized in our database table. | 73 // incognito mode or if it hasn't been initialized in our database table. |
| 71 if (download_item->db_handle() <= kUninitializedHandle) | 74 if (download_item->db_handle() <= kUninitializedHandle) |
| 72 return; | 75 return; |
| 73 | 76 |
| 74 // TODO(paulg) see bug 958058. EXPLICIT_ACCESS below is wrong. | 77 // TODO(paulg) see bug 958058. EXPLICIT_ACCESS below is wrong. |
| 75 HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); | 78 HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 const base::Time remove_end) { | 111 const base::Time remove_end) { |
| 109 // TODO(paulg) see bug 958058. EXPLICIT_ACCESS below is wrong. | 112 // TODO(paulg) see bug 958058. EXPLICIT_ACCESS below is wrong. |
| 110 HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); | 113 HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); |
| 111 if (hs) | 114 if (hs) |
| 112 hs->RemoveDownloadsBetween(remove_begin, remove_end); | 115 hs->RemoveDownloadsBetween(remove_begin, remove_end); |
| 113 } | 116 } |
| 114 | 117 |
| 115 int64 DownloadHistory::GetNextFakeDbHandle() { | 118 int64 DownloadHistory::GetNextFakeDbHandle() { |
| 116 return next_fake_db_handle_--; | 119 return next_fake_db_handle_--; |
| 117 } | 120 } |
| OLD | NEW |