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

Unified Diff: chrome/browser/download/download_file_manager.cc

Issue 7237034: sql::MetaTable.next_download_id, DownloadManager::GetNextId() (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: " Created 9 years, 5 months 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/download/download_file_manager.cc
diff --git a/chrome/browser/download/download_file_manager.cc b/chrome/browser/download/download_file_manager.cc
index ac0c55e77280f179710eebf67d64d808f3d7c601..91983730a447c6d8fbcf7b146be9d900715383ad 100644
--- a/chrome/browser/download/download_file_manager.cc
+++ b/chrome/browser/download/download_file_manager.cc
@@ -37,8 +37,7 @@ const int kUpdatePeriodMs = 500;
} // namespace
DownloadFileManager::DownloadFileManager(ResourceDispatcherHost* rdh)
- : next_id_(0),
- resource_dispatcher_host_(rdh) {
+ : resource_dispatcher_host_(rdh) {
}
DownloadFileManager::~DownloadFileManager() {
@@ -75,9 +74,9 @@ void DownloadFileManager::CreateDownloadFile(DownloadCreateInfo* info,
return;
}
- int32 id = info->download_id;
- DCHECK(GetDownloadFile(id) == NULL);
- downloads_[id] = download_file.release();
+ DownloadId global_id(download_manager, info->download_id);
+ DCHECK(GetDownloadFile(global_id) == NULL);
+ downloads_[global_id] = download_file.release();
// The file is now ready, we can un-pause the request and start saving data.
info->request_handle.ResumeRequest();
@@ -87,11 +86,11 @@ void DownloadFileManager::CreateDownloadFile(DownloadCreateInfo* info,
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
NewRunnableMethod(download_manager,
- &DownloadManager::StartDownload, id));
+ &DownloadManager::StartDownload, info->download_id));
}
-DownloadFile* DownloadFileManager::GetDownloadFile(int id) {
- DownloadFileMap::iterator it = downloads_.find(id);
+DownloadFile* DownloadFileManager::GetDownloadFile(DownloadId global_id) {
+ DownloadFileMap::iterator it = downloads_.find(global_id);
return it == downloads_.end() ? NULL : it->second;
}
@@ -112,24 +111,17 @@ void DownloadFileManager::UpdateInProgressDownloads() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
for (DownloadFileMap::iterator i = downloads_.begin();
i != downloads_.end(); ++i) {
- int id = i->first;
+ DownloadId global_id = i->first;
DownloadFile* download_file = i->second;
DownloadManager* manager = download_file->GetDownloadManager();
if (manager) {
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
NewRunnableMethod(manager, &DownloadManager::UpdateDownload,
- id, download_file->bytes_so_far()));
+ global_id.local(), download_file->bytes_so_far()));
}
}
}
-// Called on the IO thread once the ResourceDispatcherHost has decided that a
-// request is a download.
-int DownloadFileManager::GetNextId() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- return next_id_++;
-}
-
void DownloadFileManager::StartDownload(DownloadCreateInfo* info) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(info);
@@ -164,7 +156,8 @@ void DownloadFileManager::StartDownload(DownloadCreateInfo* info) {
// download (in the UI thread), we may receive a few more updates before the IO
// thread gets the cancel message: we just delete the data since the
// DownloadFile has been deleted.
-void DownloadFileManager::UpdateDownload(int id, DownloadBuffer* buffer) {
+void DownloadFileManager::UpdateDownload(
+ DownloadId global_id, DownloadBuffer* buffer) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
std::vector<DownloadBuffer::Contents> contents;
{
@@ -172,7 +165,7 @@ void DownloadFileManager::UpdateDownload(int id, DownloadBuffer* buffer) {
contents.swap(buffer->contents);
}
- DownloadFile* download_file = GetDownloadFile(id);
+ DownloadFile* download_file = GetDownloadFile(global_id);
for (size_t i = 0; i < contents.size(); ++i) {
net::IOBuffer* data = contents[i].first;
const int data_len = contents[i].second;
@@ -183,16 +176,16 @@ void DownloadFileManager::UpdateDownload(int id, DownloadBuffer* buffer) {
}
void DownloadFileManager::OnResponseCompleted(
- int id,
+ DownloadId global_id,
DownloadBuffer* buffer,
int os_error,
const std::string& security_info) {
- VLOG(20) << __FUNCTION__ << "()" << " id = " << id
+ VLOG(20) << __FUNCTION__ << "()" << " id = " << global_id
<< " os_error = " << os_error
<< " security_info = \"" << security_info << "\"";
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
delete buffer;
- DownloadFile* download_file = GetDownloadFile(id);
+ DownloadFile* download_file = GetDownloadFile(global_id);
if (!download_file)
return;
@@ -200,7 +193,7 @@ void DownloadFileManager::OnResponseCompleted(
DownloadManager* download_manager = download_file->GetDownloadManager();
if (!download_manager) {
- CancelDownload(id);
+ CancelDownload(global_id);
return;
}
@@ -212,7 +205,7 @@ void DownloadFileManager::OnResponseCompleted(
BrowserThread::UI, FROM_HERE,
NewRunnableMethod(
download_manager, &DownloadManager::OnResponseCompleted,
- id, download_file->bytes_so_far(), os_error, hash));
+ global_id.local(), download_file->bytes_so_far(), os_error, hash));
// We need to keep the download around until the UI thread has finalized
// the name.
}
@@ -220,10 +213,10 @@ void DownloadFileManager::OnResponseCompleted(
// This method will be sent via a user action, or shutdown on the UI thread, and
// run on the download thread. Since this message has been sent from the UI
// thread, the download may have already completed and won't exist in our map.
-void DownloadFileManager::CancelDownload(int id) {
- VLOG(20) << __FUNCTION__ << "()" << " id = " << id;
+void DownloadFileManager::CancelDownload(DownloadId global_id) {
+ VLOG(20) << __FUNCTION__ << "()" << " id = " << global_id;
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
- DownloadFileMap::iterator it = downloads_.find(id);
+ DownloadFileMap::iterator it = downloads_.find(global_id);
if (it == downloads_.end())
return;
@@ -232,24 +225,24 @@ void DownloadFileManager::CancelDownload(int id) {
<< " download_file = " << download_file->DebugString();
download_file->Cancel();
- EraseDownload(id);
+ EraseDownload(global_id);
}
-void DownloadFileManager::CompleteDownload(int id) {
+void DownloadFileManager::CompleteDownload(DownloadId global_id) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
- if (!ContainsKey(downloads_, id))
+ if (!ContainsKey(downloads_, global_id))
return;
- DownloadFile* download_file = downloads_[id];
+ DownloadFile* download_file = downloads_[global_id];
VLOG(20) << " " << __FUNCTION__ << "()"
- << " id = " << id
+ << " id = " << global_id
<< " download_file = " << download_file->DebugString();
download_file->Detach();
- EraseDownload(id);
+ EraseDownload(global_id);
}
void DownloadFileManager::OnDownloadManagerShutdown(DownloadManager* manager) {
@@ -269,7 +262,7 @@ void DownloadFileManager::OnDownloadManagerShutdown(DownloadManager* manager) {
for (std::set<DownloadFile*>::iterator i = to_remove.begin();
i != to_remove.end(); ++i) {
- downloads_.erase((*i)->id());
+ downloads_.erase(DownloadId((*i)->GetDownloadManager(), (*i)->id()));
Randy Smith (Not in Mondays) 2011/07/28 21:03:16 Shouldn't DownloadFile have a global id? It feels
benjhayden 2011/08/03 17:44:46 SGTM.
Randy Smith (Not in Mondays) 2011/08/03 21:10:29 (I'm taking "at the level" to mean "in the context
benjhayden 2011/08/04 17:15:00 Done.
delete *i;
}
}
@@ -283,12 +276,12 @@ void DownloadFileManager::OnDownloadManagerShutdown(DownloadManager* manager) {
// 1. tmp -> foo.crdownload (not final, safe)
// 2. tmp-> Unconfirmed.xxx.crdownload (not final, dangerous)
void DownloadFileManager::RenameInProgressDownloadFile(
- int id, const FilePath& full_path) {
- VLOG(20) << __FUNCTION__ << "()" << " id = " << id
+ DownloadId global_id, const FilePath& full_path) {
+ VLOG(20) << __FUNCTION__ << "()" << " id = " << global_id
<< " full_path = \"" << full_path.value() << "\"";
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
- DownloadFile* download_file = GetDownloadFile(id);
+ DownloadFile* download_file = GetDownloadFile(global_id);
if (!download_file)
return;
@@ -298,7 +291,7 @@ void DownloadFileManager::RenameInProgressDownloadFile(
if (!download_file->Rename(full_path)) {
// Error. Between the time the UI thread generated 'full_path' to the time
// this code runs, something happened that prevents us from renaming.
- CancelDownloadOnRename(id);
+ CancelDownloadOnRename(global_id);
}
}
@@ -310,13 +303,15 @@ void DownloadFileManager::RenameInProgressDownloadFile(
// 1. foo.crdownload -> foo (final, safe)
// 2. Unconfirmed.xxx.crdownload -> xxx (final, validated)
void DownloadFileManager::RenameCompletingDownloadFile(
- int id, const FilePath& full_path, bool overwrite_existing_file) {
- VLOG(20) << __FUNCTION__ << "()" << " id = " << id
+ DownloadId global_id,
+ const FilePath& full_path,
+ bool overwrite_existing_file) {
+ VLOG(20) << __FUNCTION__ << "()" << " id = " << global_id
<< " overwrite_existing_file = " << overwrite_existing_file
<< " full_path = \"" << full_path.value() << "\"";
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
- DownloadFile* download_file = GetDownloadFile(id);
+ DownloadFile* download_file = GetDownloadFile(global_id);
if (!download_file)
return;
@@ -346,7 +341,7 @@ void DownloadFileManager::RenameCompletingDownloadFile(
if (!download_file->Rename(new_path)) {
// Error. Between the time the UI thread generated 'full_path' to the time
// this code runs, something happened that prevents us from renaming.
- CancelDownloadOnRename(id);
+ CancelDownloadOnRename(global_id);
return;
}
@@ -356,19 +351,17 @@ void DownloadFileManager::RenameCompletingDownloadFile(
download_file->AnnotateWithSourceInformation();
#endif
- BrowserThread::PostTask(
- BrowserThread::UI, FROM_HERE,
- NewRunnableMethod(
- download_manager, &DownloadManager::OnDownloadRenamedToFinalName, id,
- new_path, uniquifier));
+ BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, NewRunnableMethod(
+ download_manager, &DownloadManager::OnDownloadRenamedToFinalName,
+ global_id.local(), new_path, uniquifier));
}
// Called only from RenameInProgressDownloadFile and
// RenameCompletingDownloadFile on the FILE thread.
-void DownloadFileManager::CancelDownloadOnRename(int id) {
+void DownloadFileManager::CancelDownloadOnRename(DownloadId global_id) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
- DownloadFile* download_file = GetDownloadFile(id);
+ DownloadFile* download_file = GetDownloadFile(global_id);
if (!download_file)
return;
@@ -381,25 +374,24 @@ void DownloadFileManager::CancelDownloadOnRename(int id) {
return;
}
- BrowserThread::PostTask(
- BrowserThread::UI, FROM_HERE,
- NewRunnableMethod(download_manager,
- &DownloadManager::DownloadCancelled, id));
+ BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, NewRunnableMethod(
+ download_manager, &DownloadManager::DownloadCancelled,
+ global_id.local()));
}
-void DownloadFileManager::EraseDownload(int id) {
+void DownloadFileManager::EraseDownload(DownloadId global_id) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
- if (!ContainsKey(downloads_, id))
+ if (!ContainsKey(downloads_, global_id))
return;
- DownloadFile* download_file = downloads_[id];
+ DownloadFile* download_file = downloads_[global_id];
VLOG(20) << " " << __FUNCTION__ << "()"
- << " id = " << id
+ << " id = " << global_id
<< " download_file = " << download_file->DebugString();
- downloads_.erase(id);
+ downloads_.erase(global_id);
delete download_file;

Powered by Google App Engine
This is Rietveld 408576698