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

Unified Diff: chrome/browser/download/download_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_manager.cc
diff --git a/chrome/browser/download/download_manager.cc b/chrome/browser/download/download_manager.cc
index cb62310f9020260ca3d677cc4069385919a372ec..313e8a192a116a7206db58cda39db6704f73f80f 100644
--- a/chrome/browser/download/download_manager.cc
+++ b/chrome/browser/download/download_manager.cc
@@ -4,6 +4,7 @@
#include "chrome/browser/download/download_manager.h"
+#include "base/bind.h"
#include "base/callback.h"
#include "base/file_util.h"
#include "base/i18n/case_conversion.h"
@@ -12,6 +13,7 @@
#include "base/rand_util.h"
#include "base/stl_util.h"
#include "base/stringprintf.h"
+#include "base/synchronization/lock.h"
#include "base/sys_string_conversions.h"
#include "base/task.h"
#include "base/utf_string_conversions.h"
@@ -51,6 +53,7 @@
DownloadManager::DownloadManager(DownloadManagerDelegate* delegate,
DownloadStatusUpdater* status_updater)
: shutdown_needed_(false),
+ next_id_(0),
profile_(NULL),
file_manager_(NULL),
status_updater_(status_updater->AsWeakPtr()),
@@ -217,6 +220,30 @@ void DownloadManager::SearchDownloads(const string16& query,
original_profile->GetDownloadManager()->SearchDownloads(query, result);
}
+void DownloadManager::OnHistoryGetNextId(int next_id) {
+ DVLOG(1) << __FUNCTION__ << " " << next_id;
+ base::AutoLock lock(next_id_lock_);
+ // TODO(benjhayden) Delay Profile initialization until here, and set next_id_
+ // = next_id. The '+=' works for now because these ids are not yet persisted
+ // to the database. GetNextId() can return 0 once, then this callback can
+ // increment next_id_, and the item whose id=0 won't clash with any other
+ // items even though there may be items loaded from the history because items
+ // from the history don't have valid ids.
Randy Smith (Not in Mondays) 2011/08/03 21:10:29 Actually, what we're counting on is that GetNextId
benjhayden 2011/08/04 17:15:00 Done.
+ next_id_ += next_id;
+}
+
+DownloadId DownloadManager::GetNextId() {
+ // May be called on any thread via the GetNextIdThunk.
+ // TODO(benjhayden) If otr, forward to parent DM.
+ base::AutoLock lock(next_id_lock_);
+ return DownloadId(this, next_id_++);
+}
+
+DownloadManager::GetNextIdThunkType DownloadManager::GetNextIdThunk() {
+ // TODO(benjhayden) If otr, forward to parent DM.
+ return base::Bind(&DownloadManager::GetNextId, this);
+}
+
// Query the history service for information about all persisted downloads.
bool DownloadManager::Init(Profile* profile) {
DCHECK(profile);
@@ -225,6 +252,8 @@ bool DownloadManager::Init(Profile* profile) {
profile_ = profile;
download_history_.reset(new DownloadHistory(profile));
+ download_history_->GetNextId(NewCallback(
Randy Smith (Not in Mondays) 2011/08/03 21:10:29 You might want to note that this isn't guaranteed
benjhayden 2011/08/04 17:15:00 Done.
+ this, &DownloadManager::OnHistoryGetNextId));
download_history_->Load(
NewCallback(this, &DownloadManager::OnQueryDownloadEntriesComplete));
@@ -587,7 +616,7 @@ void DownloadManager::ContinueDownloadWithPath(DownloadItem* download,
BrowserThread::FILE, FROM_HERE,
NewRunnableMethod(
file_manager_, &DownloadFileManager::RenameInProgressDownloadFile,
- download->id(), download_path));
+ download->global_id(), download_path));
download->Rename(download_path);
@@ -791,10 +820,10 @@ void DownloadManager::OnDownloadRenamedToFinalName(int download_id,
DCHECK_EQ(0, uniquifier) << "We should not uniquify SAFE downloads twice";
}
- BrowserThread::PostTask(
- BrowserThread::FILE, FROM_HERE,
- NewRunnableMethod(
- file_manager_, &DownloadFileManager::CompleteDownload, download_id));
+ BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, NewRunnableMethod(
+ file_manager_,
+ &DownloadFileManager::CompleteDownload,
+ item->global_id()));
if (uniquifier)
item->set_path_uniquifier(uniquifier);
@@ -830,10 +859,9 @@ void DownloadManager::DownloadCancelledInternal(
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
request_handle.CancelRequest();
- BrowserThread::PostTask(
- BrowserThread::FILE, FROM_HERE,
- NewRunnableMethod(
- file_manager_, &DownloadFileManager::CancelDownload, download_id));
+ BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, NewRunnableMethod(
+ file_manager_, &DownloadFileManager::CancelDownload,
+ DownloadId(this, download_id)));
}
void DownloadManager::OnDownloadError(int32 download_id,
@@ -866,10 +894,10 @@ void DownloadManager::OnDownloadError(int32 download_id,
download_history_->UpdateEntry(download);
}
- BrowserThread::PostTask(
- BrowserThread::FILE, FROM_HERE,
- NewRunnableMethod(
- file_manager_, &DownloadFileManager::CancelDownload, download_id));
+ BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, NewRunnableMethod(
+ file_manager_,
+ &DownloadFileManager::CancelDownload,
+ download->global_id()));
}
void DownloadManager::UpdateAppIcon() {

Powered by Google App Engine
This is Rietveld 408576698