Index: content/browser/download/download_id.h |
diff --git a/content/browser/download/download_id.h b/content/browser/download/download_id.h |
index 187a79ce1450ca51c51acd7a31d41d9982e333c7..d9726bfce83fc5dabb77e50edf3918150bad768a 100644 |
--- a/content/browser/download/download_id.h |
+++ b/content/browser/download/download_id.h |
@@ -2,17 +2,16 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_ID_H_ |
-#define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_ID_H_ |
+#ifndef CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ID_H_ |
+#define CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ID_H_ |
#pragma once |
#include <iosfwd> |
+#include <string> |
#include "base/hash_tables.h" |
#include "content/common/content_export.h" |
-class DownloadManager; |
- |
// DownloadId combines per-profile Download ids with an indication of which |
// profile in order to be globally unique. DownloadIds are not persistent across |
// sessions, but their local() field is. |
@@ -20,8 +19,11 @@ class DownloadId { |
public: |
static DownloadId Invalid() { return DownloadId(NULL, -1); } |
- DownloadId(const DownloadManager* manager, int32 local_id) |
- : manager_(manager), |
+ // Domain separates spaces of local ids. |
+ typedef const void* Domain; |
+ |
+ DownloadId(Domain domain, int32 local_id) |
+ : domain_(domain), |
local_id_(local_id) { |
} |
@@ -30,43 +32,40 @@ class DownloadId { |
// Returns true if this DownloadId has been allocated and could possibly refer |
// to a DownloadItem that exists. |
- bool IsValid() const { return ((manager_ != NULL) && (local_id_ >= 0)); } |
+ bool IsValid() const { return ((domain_ != NULL) && (local_id_ >= 0)); } |
// The following methods (operator==, hash(), copy, and assign) provide |
// support for STL containers such as hash_map. |
bool operator==(const DownloadId& that) const { |
return ((that.local_id_ == local_id_) && |
- (that.manager_ == manager_)); |
+ (that.domain_ == domain_)); |
} |
bool operator<(const DownloadId& that) const { |
- // Even though DownloadManager* < DownloadManager* is not well defined and |
+ // Even though Domain::operator< is not well defined and |
// GCC does not require it for hash_map, MSVC requires operator< for |
// hash_map. We don't ifdef it out here because we will probably make a |
// set<DownloadId> at some point, when GCC will require it. |
- return ((manager_ < that.manager_) || |
- ((manager_ == that.manager_) && (local_id_ < that.local_id_))); |
+ return ((domain_ < that.domain_) || |
+ ((domain_ == that.domain_) && (local_id_ < that.local_id_))); |
} |
size_t hash() const { |
- // The top half of manager is unlikely to be distinct, and the user is |
+ // The top half of domain_ is unlikely to be distinct, and the user is |
// unlikely to have >64K downloads. If these assumptions are incorrect, then |
// DownloadFileManager's hash_map might have a few collisions, but it will |
// use operator== to safely disambiguate. |
- return reinterpret_cast<size_t>(manager_) + |
+ return reinterpret_cast<size_t>(domain_) + |
(static_cast<size_t>(local_id_) << (4 * sizeof(size_t))); |
} |
+ std::string DebugString() const; |
+ |
private: |
- // DownloadId is used mostly off the UI thread, so manager's methods can't be |
- // called, but the pointer can be compared. |
- const DownloadManager* manager_; |
+ Domain domain_; |
int32 local_id_; |
- friend CONTENT_EXPORT std::ostream& operator<<(std::ostream& out, |
- const DownloadId& global_id); |
- |
// Allow copy and assign. |
}; |
@@ -88,4 +87,4 @@ inline size_t hash_value(const DownloadId& id) { |
} |
#endif // COMPILER |
} |
-#endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_ID_H_ |
+#endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ID_H_ |