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

Unified Diff: content/browser/download/download_item_impl.cc

Issue 10665049: Make DownloadHistory observe manager, items (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 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: content/browser/download/download_item_impl.cc
diff --git a/content/browser/download/download_item_impl.cc b/content/browser/download/download_item_impl.cc
index e7eb3f337a365854ab528e10ebddc698dfc5871f..a7964783c96dd94bb91a6d89543344b690f05c3f 100644
--- a/content/browser/download/download_item_impl.cc
+++ b/content/browser/download/download_item_impl.cc
@@ -87,8 +87,6 @@ const char* DebugDownloadStateString(DownloadItem::DownloadState state) {
return "COMPLETE";
case DownloadItem::CANCELLED:
return "CANCELLED";
- case DownloadItem::REMOVING:
- return "REMOVING";
case DownloadItem::INTERRUPTED:
return "INTERRUPTED";
default:
@@ -163,14 +161,12 @@ DownloadItemImpl::DownloadItemImpl(DownloadItemImplDelegate* delegate,
danger_type_(content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS),
start_time_(info.start_time),
end_time_(info.end_time),
- db_handle_(info.db_handle),
delegate_(delegate),
is_paused_(false),
open_when_complete_(false),
file_externally_removed_(false),
safety_state_(SAFE),
auto_opened_(false),
- is_persisted_(true),
is_otr_(false),
is_temporary_(false),
all_data_saved_(false),
@@ -219,14 +215,12 @@ DownloadItemImpl::DownloadItemImpl(
state_(IN_PROGRESS),
danger_type_(content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS),
start_time_(info.start_time),
- db_handle_(DownloadItem::kUninitializedHandle),
delegate_(delegate),
is_paused_(false),
open_when_complete_(false),
file_externally_removed_(false),
safety_state_(SAFE),
auto_opened_(false),
- is_persisted_(false),
is_otr_(is_otr),
is_temporary_(!info.save_info.file_path.empty()),
all_data_saved_(false),
@@ -276,14 +270,12 @@ DownloadItemImpl::DownloadItemImpl(DownloadItemImplDelegate* delegate,
state_(IN_PROGRESS),
danger_type_(content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS),
start_time_(base::Time::Now()),
- db_handle_(DownloadItem::kUninitializedHandle),
delegate_(delegate),
is_paused_(false),
open_when_complete_(false),
file_externally_removed_(false),
safety_state_(SAFE),
auto_opened_(false),
- is_persisted_(false),
is_otr_(is_otr),
is_temporary_(false),
all_data_saved_(false),
@@ -299,10 +291,7 @@ DownloadItemImpl::DownloadItemImpl(DownloadItemImplDelegate* delegate,
DownloadItemImpl::~DownloadItemImpl() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
-
- TransitionTo(REMOVING);
- STLDeleteContainerPairSecondPointers(
- external_data_map_.begin(), external_data_map_.end());
+ FOR_EACH_OBSERVER(Observer, observers_, OnDownloadDestroyed(this));
delegate_->AssertStateConsistent(this);
delegate_->Detach();
}
@@ -654,11 +643,15 @@ void DownloadItemImpl::Remove() {
Cancel(true);
delegate_->AssertStateConsistent(this);
- TransitionTo(REMOVING);
+ NotifyRemoved();
delegate_->DownloadRemoved(this);
// We have now been deleted.
}
+void DownloadItemImpl::NotifyRemoved() {
+ FOR_EACH_OBSERVER(Observer, observers_, OnDownloadRemoved(this));
+}
+
bool DownloadItemImpl::TimeRemaining(base::TimeDelta* remaining) const {
if (total_bytes_ <= 0)
return false; // We never received the content_length for this download.
@@ -827,20 +820,6 @@ bool DownloadItemImpl::IsDangerous() const {
#endif
}
-DownloadPersistentStoreInfo DownloadItemImpl::GetPersistentStoreInfo() const {
- // TODO(asanka): Persist GetTargetFilePath() as well.
- return DownloadPersistentStoreInfo(GetFullPath(),
- GetURL(),
- GetReferrerUrl(),
- GetStartTime(),
- GetEndTime(),
- GetReceivedBytes(),
- GetTotalBytes(),
- GetState(),
- GetDbHandle(),
- GetOpened());
-}
-
WebContents* DownloadItemImpl::GetWebContents() const {
// TODO(rdsmith): Remove null check after removing GetWebContents() from
// paths that might be used by DownloadItems created from history import.
@@ -972,7 +951,7 @@ void DownloadItemImpl::Init(bool active,
if (!active) {
bound_net_log_.AddEvent(
net::NetLog::TYPE_DOWNLOAD_ITEM_IN_HISTORY,
- net::NetLog::Int64Callback("db_handle", db_handle_));
+ net::NetLog::Int64Callback("id", GetId()));
bound_net_log_.EndEvent(net::NetLog::TYPE_DOWNLOAD_ITEM_ACTIVE);
}
@@ -1036,7 +1015,6 @@ std::string DownloadItemImpl::DebugString(bool verbose) const {
if (verbose) {
description += base::StringPrintf(
- " db_handle = %" PRId64
" total = %" PRId64
" received = %" PRId64
" reason = %s"
@@ -1048,7 +1026,6 @@ std::string DownloadItemImpl::DebugString(bool verbose) const {
" url_chain = \n\t\"%s\"\n\t"
" full_path = \"%" PRFilePath "\""
" target_path = \"%" PRFilePath "\"",
- GetDbHandle(),
GetTotalBytes(),
GetReceivedBytes(),
InterruptReasonDebugString(last_reason_).c_str(),
@@ -1070,131 +1047,123 @@ std::string DownloadItemImpl::DebugString(bool verbose) const {
}
bool DownloadItemImpl::AllDataSaved() const { return all_data_saved_; }
+
DownloadItem::DownloadState DownloadItemImpl::GetState() const {
return state_;
}
+
const std::vector<GURL>& DownloadItemImpl::GetUrlChain() const {
return url_chain_;
}
+
const GURL& DownloadItemImpl::GetOriginalUrl() const {
return url_chain_.front();
}
+
const GURL& DownloadItemImpl::GetReferrerUrl() const { return referrer_url_; }
+
std::string DownloadItemImpl::GetSuggestedFilename() const {
return suggested_filename_;
}
+
std::string DownloadItemImpl::GetContentDisposition() const {
return content_disposition_;
}
+
std::string DownloadItemImpl::GetMimeType() const { return mime_type_; }
+
std::string DownloadItemImpl::GetOriginalMimeType() const {
return original_mime_type_;
}
+
std::string DownloadItemImpl::GetReferrerCharset() const {
return referrer_charset_;
}
+
std::string DownloadItemImpl::GetRemoteAddress() const {
return remote_address_;
}
+
int64 DownloadItemImpl::GetTotalBytes() const { return total_bytes_; }
+
void DownloadItemImpl::SetTotalBytes(int64 total_bytes) {
total_bytes_ = total_bytes;
}
+
const std::string& DownloadItemImpl::GetHash() const { return hash_; }
+
int64 DownloadItemImpl::GetReceivedBytes() const { return received_bytes_; }
+
const std::string& DownloadItemImpl::GetHashState() const {
return hash_state_;
}
-int32 DownloadItemImpl::GetId() const { return download_id_.local(); }
-DownloadId DownloadItemImpl::GetGlobalId() const { return download_id_; }
-base::Time DownloadItemImpl::GetStartTime() const { return start_time_; }
-base::Time DownloadItemImpl::GetEndTime() const { return end_time_; }
-void DownloadItemImpl::SetIsPersisted() {
- is_persisted_ = true;
-}
+int32 DownloadItemImpl::GetId() const { return download_id_.local(); }
-bool DownloadItemImpl::IsPersisted() const {
- return is_persisted_;
-}
+DownloadId DownloadItemImpl::GetGlobalId() const { return download_id_; }
-void DownloadItemImpl::SetDbHandle(int64 handle) {
- db_handle_ = handle;
+base::Time DownloadItemImpl::GetStartTime() const { return start_time_; }
- bound_net_log_.AddEvent(
- net::NetLog::TYPE_DOWNLOAD_ITEM_IN_HISTORY,
- net::NetLog::Int64Callback("db_handle", db_handle_));
-}
+base::Time DownloadItemImpl::GetEndTime() const { return end_time_; }
-int64 DownloadItemImpl::GetDbHandle() const { return db_handle_; }
bool DownloadItemImpl::IsPaused() const { return is_paused_; }
+
bool DownloadItemImpl::GetOpenWhenComplete() const {
return open_when_complete_;
}
+
void DownloadItemImpl::SetOpenWhenComplete(bool open) {
open_when_complete_ = open;
}
+
bool DownloadItemImpl::GetFileExternallyRemoved() const {
return file_externally_removed_;
}
+
DownloadItem::SafetyState DownloadItemImpl::GetSafetyState() const {
return safety_state_;
}
+
bool DownloadItemImpl::IsOtr() const { return is_otr_; }
+
bool DownloadItemImpl::GetAutoOpened() { return auto_opened_; }
+
FilePath DownloadItemImpl::GetTargetName() const {
return target_path_.BaseName();
}
+
const FilePath& DownloadItemImpl::GetForcedFilePath() const {
// TODO(asanka): Get rid of GetForcedFilePath(). We should instead just
// require that clients respect GetTargetFilePath() if it is already set.
return forced_file_path_;
}
+
bool DownloadItemImpl::HasUserGesture() const {
return has_user_gesture_;
};
+
content::PageTransition DownloadItemImpl::GetTransitionType() const {
return transition_type_;
};
+
bool DownloadItemImpl::IsTemporary() const { return is_temporary_; }
+
void DownloadItemImpl::SetIsTemporary(bool temporary) {
is_temporary_ = temporary;
}
+
void DownloadItemImpl::SetOpened(bool opened) { opened_ = opened; }
+
bool DownloadItemImpl::GetOpened() const { return opened_; }
+
const std::string& DownloadItemImpl::GetLastModifiedTime() const {
return last_modified_time_;
}
+
const std::string& DownloadItemImpl::GetETag() const { return etag_; }
+
content::DownloadInterruptReason DownloadItemImpl::GetLastReason() const {
return last_reason_;
}
-void DownloadItemImpl::MockDownloadOpenForTesting() { open_enabled_ = false; }
-
-DownloadItem::ExternalData*
-DownloadItemImpl::GetExternalData(const void* key) {
- // The behavior of the const overload is identical with the exception of the
- // constness of |this| and the return value.
- return const_cast<DownloadItem::ExternalData*>(
- static_cast<const DownloadItemImpl&>(*this).GetExternalData(key));
-}
-
-const DownloadItem::ExternalData*
-DownloadItemImpl::GetExternalData(const void* key) const {
- std::map<const void*, ExternalData*>::const_iterator it =
- external_data_map_.find(key);
- return (it == external_data_map_.end()) ? NULL : it->second;
-}
-
-void DownloadItemImpl::SetExternalData(
- const void* key, DownloadItem::ExternalData* data) {
- std::map<const void*, ExternalData*>::iterator it =
- external_data_map_.find(key);
- if (it == external_data_map_.end()) {
- external_data_map_[key] = data;
- } else if (it->second != data) {
- delete it->second;
- it->second = data;
- }
-}
+void DownloadItemImpl::MockDownloadOpenForTesting() { open_enabled_ = false; }

Powered by Google App Engine
This is Rietveld 408576698