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_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" |
11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
12 | 12 |
13 // Our download table ID starts at 1, so we use 0 to represent a download that | 13 // Our download table ID starts at 1, so we use 0 to represent a download that |
14 // has started, but has not yet had its data persisted in the table. We use fake | 14 // has started, but has not yet had its data persisted in the table. We use fake |
15 // database handles in incognito mode starting at -1 and progressively getting | 15 // database handles in incognito mode starting at -1 and progressively getting |
16 // more negative. | 16 // more negative. |
17 // static | 17 // static |
18 const int DownloadHistory::kUninitializedHandle = 0; | 18 const int DownloadHistory::kUninitializedHandle = 0; |
(...skipping 14 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); | |
Randy Smith (Not in Mondays)
2011/05/20 19:49:29
nit: Why not DCHECK(download_item), as is used in
ahendrickson
2011/05/20 22:12:45
Done.
| |
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 DownloadHistoryInfo history_info = download_item->history_info(); |
67 hs->CreateDownload(history_info, | |
68 &history_consumer_, | |
69 callback); | |
66 } | 70 } |
67 | 71 |
68 void DownloadHistory::UpdateEntry(DownloadItem* download_item) { | 72 void DownloadHistory::UpdateEntry(DownloadItem* download_item) { |
69 // Don't store info in the database if the download was initiated while in | 73 // 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. | 74 // incognito mode or if it hasn't been initialized in our database table. |
71 if (download_item->db_handle() <= kUninitializedHandle) | 75 if (download_item->db_handle() <= kUninitializedHandle) |
72 return; | 76 return; |
73 | 77 |
74 // TODO(paulg) see bug 958058. EXPLICIT_ACCESS below is wrong. | 78 // TODO(paulg) see bug 958058. EXPLICIT_ACCESS below is wrong. |
75 HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); | 79 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) { | 112 const base::Time remove_end) { |
109 // TODO(paulg) see bug 958058. EXPLICIT_ACCESS below is wrong. | 113 // TODO(paulg) see bug 958058. EXPLICIT_ACCESS below is wrong. |
110 HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); | 114 HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); |
111 if (hs) | 115 if (hs) |
112 hs->RemoveDownloadsBetween(remove_begin, remove_end); | 116 hs->RemoveDownloadsBetween(remove_begin, remove_end); |
113 } | 117 } |
114 | 118 |
115 int64 DownloadHistory::GetNextFakeDbHandle() { | 119 int64 DownloadHistory::GetNextFakeDbHandle() { |
116 return next_fake_db_handle_--; | 120 return next_fake_db_handle_--; |
117 } | 121 } |
OLD | NEW |