Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1418)

Side by Side Diff: chrome/browser/download/download_history.cc

Issue 8503018: Split DownloadItem into an ABC, an Impl, and a Mock. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: merge Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 // Do not store the download in the history database for a few special cases: 65 // Do not store the download in the history database for a few special cases:
66 // - incognito mode (that is the point of this mode) 66 // - incognito mode (that is the point of this mode)
67 // - extensions (users don't think of extension installation as 'downloading') 67 // - extensions (users don't think of extension installation as 'downloading')
68 // - temporary download, like in drag-and-drop 68 // - temporary download, like in drag-and-drop
69 // - history service is not available (e.g. in tests) 69 // - history service is not available (e.g. in tests)
70 // We have to make sure that these handles don't collide with normal db 70 // We have to make sure that these handles don't collide with normal db
71 // handles, so we use a negative value. Eventually, they could overlap, but 71 // handles, so we use a negative value. Eventually, they could overlap, but
72 // you'd have to do enough downloading that your ISP would likely stab you in 72 // you'd have to do enough downloading that your ISP would likely stab you in
73 // the neck first. YMMV. 73 // the neck first. YMMV.
74 HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); 74 HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS);
75 if (download_item->is_otr() || 75 if (download_item->IsOtr() ||
76 ChromeDownloadManagerDelegate::IsExtensionDownload(download_item) || 76 ChromeDownloadManagerDelegate::IsExtensionDownload(download_item) ||
77 download_item->is_temporary() || !hs) { 77 download_item->IsTemporary() || !hs) {
78 callback.Run(download_item->id(), GetNextFakeDbHandle()); 78 callback.Run(download_item->GetId(), GetNextFakeDbHandle());
79 return; 79 return;
80 } 80 }
81 81
82 int32 id = download_item->id(); 82 int32 id = download_item->GetId();
83 DownloadPersistentStoreInfo history_info = 83 DownloadPersistentStoreInfo history_info =
84 download_item->GetPersistentStoreInfo(); 84 download_item->GetPersistentStoreInfo();
85 hs->CreateDownload(id, history_info, &history_consumer_, callback); 85 hs->CreateDownload(id, history_info, &history_consumer_, callback);
86 } 86 }
87 87
88 void DownloadHistory::UpdateEntry(DownloadItem* download_item) { 88 void DownloadHistory::UpdateEntry(DownloadItem* download_item) {
89 // Don't store info in the database if the download was initiated while in 89 // Don't store info in the database if the download was initiated while in
90 // incognito mode or if it hasn't been initialized in our database table. 90 // incognito mode or if it hasn't been initialized in our database table.
91 if (download_item->db_handle() <= DownloadItem::kUninitializedHandle) 91 if (download_item->GetDbHandle() <= DownloadItem::kUninitializedHandle)
92 return; 92 return;
93 93
94 HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); 94 HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS);
95 if (!hs) 95 if (!hs)
96 return; 96 return;
97 hs->UpdateDownload(download_item->GetPersistentStoreInfo()); 97 hs->UpdateDownload(download_item->GetPersistentStoreInfo());
98 } 98 }
99 99
100 void DownloadHistory::UpdateDownloadPath(DownloadItem* download_item, 100 void DownloadHistory::UpdateDownloadPath(DownloadItem* download_item,
101 const FilePath& new_path) { 101 const FilePath& new_path) {
102 // No update necessary if the download was initiated while in incognito mode. 102 // No update necessary if the download was initiated while in incognito mode.
103 if (download_item->db_handle() <= DownloadItem::kUninitializedHandle) 103 if (download_item->GetDbHandle() <= DownloadItem::kUninitializedHandle)
104 return; 104 return;
105 105
106 HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); 106 HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS);
107 if (hs) 107 if (hs)
108 hs->UpdateDownloadPath(new_path, download_item->db_handle()); 108 hs->UpdateDownloadPath(new_path, download_item->GetDbHandle());
109 } 109 }
110 110
111 void DownloadHistory::RemoveEntry(DownloadItem* download_item) { 111 void DownloadHistory::RemoveEntry(DownloadItem* download_item) {
112 // No update necessary if the download was initiated while in incognito mode. 112 // No update necessary if the download was initiated while in incognito mode.
113 if (download_item->db_handle() <= DownloadItem::kUninitializedHandle) 113 if (download_item->GetDbHandle() <= DownloadItem::kUninitializedHandle)
114 return; 114 return;
115 115
116 HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); 116 HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS);
117 if (hs) 117 if (hs)
118 hs->RemoveDownload(download_item->db_handle()); 118 hs->RemoveDownload(download_item->GetDbHandle());
119 } 119 }
120 120
121 void DownloadHistory::RemoveEntriesBetween(const base::Time remove_begin, 121 void DownloadHistory::RemoveEntriesBetween(const base::Time remove_begin,
122 const base::Time remove_end) { 122 const base::Time remove_end) {
123 HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); 123 HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS);
124 if (hs) 124 if (hs)
125 hs->RemoveDownloadsBetween(remove_begin, remove_end); 125 hs->RemoveDownloadsBetween(remove_begin, remove_end);
126 } 126 }
127 127
128 int64 DownloadHistory::GetNextFakeDbHandle() { 128 int64 DownloadHistory::GetNextFakeDbHandle() {
129 return next_fake_db_handle_--; 129 return next_fake_db_handle_--;
130 } 130 }
131 131
132 void DownloadHistory::OnGotVisitCountToHost(HistoryService::Handle handle, 132 void DownloadHistory::OnGotVisitCountToHost(HistoryService::Handle handle,
133 bool found_visits, 133 bool found_visits,
134 int count, 134 int count,
135 base::Time first_visit) { 135 base::Time first_visit) {
136 VisitedBeforeRequestsMap::iterator request = 136 VisitedBeforeRequestsMap::iterator request =
137 visited_before_requests_.find(handle); 137 visited_before_requests_.find(handle);
138 DCHECK(request != visited_before_requests_.end()); 138 DCHECK(request != visited_before_requests_.end());
139 int32 download_id = request->second.first; 139 int32 download_id = request->second.first;
140 VisitedBeforeDoneCallback callback = request->second.second; 140 VisitedBeforeDoneCallback callback = request->second.second;
141 visited_before_requests_.erase(request); 141 visited_before_requests_.erase(request);
142 callback.Run(download_id, found_visits && count && 142 callback.Run(download_id, found_visits && count &&
143 (first_visit.LocalMidnight() < base::Time::Now().LocalMidnight())); 143 (first_visit.LocalMidnight() < base::Time::Now().LocalMidnight()));
144 } 144 }
OLDNEW
« no previous file with comments | « chrome/browser/download/download_extension_api.cc ('k') | chrome/browser/download/download_item_model.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698