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

Unified Diff: chrome/browser/download/download_manager.h

Issue 7237034: sql::MetaTable.next_download_id, DownloadManager::GetNextId() (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: sql::MetaTable.next_download_id, DownloadId, DownloadManager::GetNextId() 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.h
diff --git a/chrome/browser/download/download_manager.h b/chrome/browser/download/download_manager.h
index 3c7284fe48d10ba03aefea938e73b30024ac9eb0..594cff539ee4cd9e2b991540c400d6b69f793b2f 100644
--- a/chrome/browser/download/download_manager.h
+++ b/chrome/browser/download/download_manager.h
@@ -34,6 +34,7 @@
#include <vector>
#include "base/basictypes.h"
+#include "base/callback.h"
#include "base/file_path.h"
#include "base/gtest_prod_util.h"
#include "base/hash_tables.h"
@@ -44,6 +45,7 @@
#include "base/time.h"
#include "chrome/browser/download/download_item.h"
#include "chrome/browser/download/download_request_handle.h"
+#include "chrome/browser/download/download_state_info.h"
#include "chrome/browser/download/download_status_updater_delegate.h"
#include "chrome/browser/ui/shell_dialogs.h"
#include "content/browser/browser_thread.h"
@@ -59,6 +61,9 @@ class TabContents;
struct DownloadCreateInfo;
struct DownloadHistoryInfo;
struct DownloadSaveInfo;
+namespace base {
+class Lock;
+} // namespace base
// Browser's download manager: manages all downloads and destination view.
class DownloadManager
@@ -112,6 +117,20 @@ class DownloadManager
void SearchDownloads(const string16& query,
std::vector<DownloadItem*>* result);
+ // Returns the next download id in a DownloadId and increments the counter.
+ // May be called on any thread. The incremented counter is not persisted until
+ // your new DownloadItem is stored in the history.
Randy Smith (Not in Mondays) 2011/07/25 20:20:12 nit: It's not really the incremented counter that'
benjhayden 2011/07/27 19:40:54 Done.
+ DownloadId GetNextId();
+
+ // Instead of passing a DownloadManager* between threads and hoping users only
+ // call GetNextId(), you can pass this thunk around instead. Use it like "id
+ // = next_id_thunk.Run();" Pass the thunk around by const ref and store it by
Randy Smith (Not in Mondays) 2011/07/25 20:20:12 nit: I may be targeting a less-smart class of deve
Randy Smith (Not in Mondays) 2011/07/25 20:20:12 I'm a bit worried by this. My understanding was t
benjhayden 2011/07/27 19:40:54 Done.
benjhayden 2011/07/27 19:40:54 I'm not sure exactly what you're asking. If you're
Randy Smith (Not in Mondays) 2011/07/28 21:03:16 I think I wasn't understanding how base::Callback
benjhayden 2011/08/03 17:44:46 Done.
+ // copy per the base::Callback interface. If you change GetNextIdThunkType
+ // from base::Callback, then you should think about how you're changing the
+ // ref-count of DownloadManager.
+ typedef base::Callback<DownloadId(void)> GetNextIdThunkType;
+ GetNextIdThunkType GetNextIdThunk();
Randy Smith (Not in Mondays) 2011/07/25 20:20:12 If you want to pass it around by const ref, is the
benjhayden 2011/07/27 19:40:54 Error: returning reference to temporary.
+
// Returns true if initialized properly.
bool Init(Profile* profile);
@@ -350,6 +369,9 @@ class DownloadManager
// Add a DownloadItem to history_downloads_.
void AddDownloadItemToHistory(DownloadItem* item, int64 db_handle);
+ // The DownloadHistory grabbed the next_id counter from the sql MetaTable.
+ void OnHistoryGetNextId(int next_id);
+
// |downloads_| is the owning set for all downloads known to the
// DownloadManager. This includes downloads started by the user in
// this session, downloads initialized from the history system, and
@@ -403,6 +425,9 @@ class DownloadManager
// Observers that want to be notified of changes to the set of downloads.
ObserverList<Observer> observers_;
+ base::Lock next_id_lock_;
+ int next_id_;
+
// The current active profile.
Profile* profile_;

Powered by Google App Engine
This is Rietveld 408576698