Commit bd6064f6 authored by Min Qin's avatar Min Qin Committed by Commit Bot

Small refactoring on downloaditemimpl

Remove BrowserThread and WebContents references

Bug: 803135
Change-Id: I791bbeb0bd3d52c497c7bad7d035aaac7440f588
Reviewed-on: https://chromium-review.googlesource.com/981328
Commit-Queue: Min Qin <qinmin@chromium.org>
Reviewed-by: default avatarXing Liu <xingliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#546008}
parent bf275594
......@@ -16,6 +16,7 @@
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/observer_list.h"
#include "base/threading/thread_checker_impl.h"
#include "base/time/time.h"
#include "components/download/public/common/download_create_info.h"
#include "components/download/public/common/download_destination_observer.h"
......@@ -36,7 +37,6 @@ class DownloadJob;
namespace content {
class BrowserContext;
class DownloadItemImplDelegate;
class WebContents;
// See download_item.h for usage.
class CONTENT_EXPORT DownloadItemImpl
......@@ -614,8 +614,7 @@ class CONTENT_EXPORT DownloadItemImpl
// INTERRUPTED state.
download::ResumeMode GetResumeMode() const;
// Helper method to get WebContents and BrowserContext of the DownloadItem.
WebContents* GetWebContents() const;
// Helper method to get BrowserContext of the DownloadItem.;
BrowserContext* GetBrowserContext() const;
static DownloadState InternalToExternalState(
......@@ -777,6 +776,8 @@ class CONTENT_EXPORT DownloadItemImpl
// Source of the download, used in metrics.
download::DownloadSource download_source_ = download::DownloadSource::UNKNOWN;
THREAD_CHECKER(thread_checker_);
base::WeakPtrFactory<DownloadItemImpl> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(DownloadItemImpl);
......
......@@ -88,4 +88,7 @@ void DownloadItemImplDelegate::DownloadRemoved(DownloadItemImpl* download) {}
void DownloadItemImplDelegate::AssertStateConsistent(
DownloadItemImpl* download) const {}
void DownloadItemImplDelegate::DownloadInterrupted(DownloadItemImpl* download) {
}
} // namespace content
......@@ -100,6 +100,9 @@ class CONTENT_EXPORT DownloadItemImplDelegate {
// Assert consistent state for delgate object at various transitions.
virtual void AssertStateConsistent(DownloadItemImpl* download) const;
// Called when the download is interrupted.
virtual void DownloadInterrupted(DownloadItemImpl* download);
private:
// For "Outlives attached DownloadItemImpl" invariant assertion.
int count_;
......
......@@ -845,6 +845,14 @@ void DownloadManagerImpl::DownloadRemoved(DownloadItemImpl* download) {
downloads_.erase(download->GetId());
}
void DownloadManagerImpl::DownloadInterrupted(DownloadItemImpl* download) {
WebContents* web_contents = DownloadItemUtils::GetWebContents(download);
if (!web_contents) {
download::RecordDownloadCountWithSource(
download::INTERRUPTED_WITHOUT_WEBCONTENTS, download->download_source());
}
}
void DownloadManagerImpl::OnUrlDownloadHandlerCreated(
download::UrlDownloadHandler::UniqueUrlDownloadHandlerPtr downloader) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
......
......@@ -234,6 +234,7 @@ class CONTENT_EXPORT DownloadManagerImpl
bool IsMostRecentDownloadItemAtFilePath(DownloadItemImpl* download) override;
void ShowDownloadInShell(DownloadItemImpl* download) override;
void DownloadRemoved(DownloadItemImpl* download) override;
void DownloadInterrupted(DownloadItemImpl* download) override;
// Helper method to start or resume a download.
void BeginDownloadInternal(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment