summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorbenjhayden@chromium.org <benjhayden@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-08 18:18:37 +0000
committerbenjhayden@chromium.org <benjhayden@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-08 18:18:37 +0000
commitd59d40cee5aff1d505099d467bd4c9c342f01347 (patch)
tree17c3cf573da5cf73cb49f513cb069e5ae33cbb7a /chrome/browser
parentd91d67e111d6ec31e92f49310fb5b4b96db77c4f (diff)
downloadchromium_src-d59d40cee5aff1d505099d467bd4c9c342f01347.zip
chromium_src-d59d40cee5aff1d505099d467bd4c9c342f01347.tar.gz
chromium_src-d59d40cee5aff1d505099d467bd4c9c342f01347.tar.bz2
Make DownloadItem derive SupportsUserData instead of re-implementing it.
Reviewers: aa: webstore_installer.* Done: sky: mock_download_item.h achuith: gdata_download_observer.cc rdsmith, asanka: * Review URL: https://chromiumcodereview.appspot.com/10833058 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@150589 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/chromeos/gdata/gdata_download_observer.cc77
-rw-r--r--chrome/browser/download/chrome_download_manager_delegate.cc10
-rw-r--r--chrome/browser/download/download_completion_blocker.h3
-rw-r--r--chrome/browser/extensions/webstore_installer.cc4
-rw-r--r--chrome/browser/extensions/webstore_installer.h5
5 files changed, 51 insertions, 48 deletions
diff --git a/chrome/browser/chromeos/gdata/gdata_download_observer.cc b/chrome/browser/chromeos/gdata/gdata_download_observer.cc
index c6299d0..173209c 100644
--- a/chrome/browser/chromeos/gdata/gdata_download_observer.cc
+++ b/chrome/browser/chromeos/gdata/gdata_download_observer.cc
@@ -6,6 +6,7 @@
#include "base/callback.h"
#include "base/file_util.h"
+#include "base/supports_user_data.h"
#include "chrome/browser/chromeos/gdata/gdata.pb.h"
#include "chrome/browser/chromeos/gdata/gdata_documents_service.h"
#include "chrome/browser/chromeos/gdata/gdata_file_system_interface.h"
@@ -27,18 +28,18 @@ namespace {
// Threshold file size after which we stream the file.
const int64 kStreamingFileSize = 1 << 20; // 1MB
-// Keys for DownloadItem::ExternalData.
+// Keys for base::SupportsUserData::Data.
const char kUploadingKey[] = "Uploading";
const char kGDataPathKey[] = "GDataPath";
-// External Data stored in DownloadItem for ongoing uploads.
-class UploadingExternalData : public DownloadCompletionBlocker {
+// User Data stored in DownloadItem for ongoing uploads.
+class UploadingUserData : public DownloadCompletionBlocker {
public:
- explicit UploadingExternalData(GDataUploader* uploader)
+ explicit UploadingUserData(GDataUploader* uploader)
: uploader_(uploader),
upload_id_(-1) {
}
- virtual ~UploadingExternalData() {}
+ virtual ~UploadingUserData() {}
GDataUploader* uploader() { return uploader_; }
void set_upload_id(int upload_id) { upload_id_ = upload_id; }
@@ -54,14 +55,14 @@ class UploadingExternalData : public DownloadCompletionBlocker {
FilePath virtual_dir_path_;
scoped_ptr<DocumentEntry> entry_;
- DISALLOW_COPY_AND_ASSIGN(UploadingExternalData);
+ DISALLOW_COPY_AND_ASSIGN(UploadingUserData);
};
-// External Data stored in DownloadItem for gdata path.
-class GDataExternalData : public DownloadItem::ExternalData {
+// User Data stored in DownloadItem for gdata path.
+class GDataUserData : public base::SupportsUserData::Data {
public:
- explicit GDataExternalData(const FilePath& path) : file_path_(path) {}
- virtual ~GDataExternalData() {}
+ explicit GDataUserData(const FilePath& path) : file_path_(path) {}
+ virtual ~GDataUserData() {}
const FilePath& file_path() const { return file_path_; }
@@ -69,16 +70,16 @@ class GDataExternalData : public DownloadItem::ExternalData {
FilePath file_path_;
};
-// Extracts UploadingExternalData* from |download|.
-UploadingExternalData* GetUploadingExternalData(DownloadItem* download) {
- return static_cast<UploadingExternalData*>(
- download->GetExternalData(&kUploadingKey));
+// Extracts UploadingUserData* from |download|.
+UploadingUserData* GetUploadingUserData(DownloadItem* download) {
+ return static_cast<UploadingUserData*>(
+ download->GetUserData(&kUploadingKey));
}
-// Extracts GDataExternalData* from |download|.
-GDataExternalData* GetGDataExternalData(DownloadItem* download) {
- return static_cast<GDataExternalData*>(
- download->GetExternalData(&kGDataPathKey));
+// Extracts GDataUserData* from |download|.
+GDataUserData* GetGDataUserData(DownloadItem* download) {
+ return static_cast<GDataUserData*>(
+ download->GetUserData(&kGDataPathKey));
}
void RunSubstituteGDataDownloadCallback(
@@ -233,15 +234,15 @@ void GDataDownloadObserver::SetDownloadParams(const FilePath& gdata_path,
return;
if (gdata::util::IsUnderGDataMountPoint(gdata_path)) {
- download->SetExternalData(&kGDataPathKey,
- new GDataExternalData(gdata_path));
+ download->SetUserData(&kGDataPathKey,
+ new GDataUserData(gdata_path));
download->SetDisplayName(gdata_path.BaseName());
download->SetIsTemporary(true);
} else if (IsGDataDownload(download)) {
// This may have been previously set if the default download folder is
// /drive, and the user has now changed the download target to a local
// folder.
- download->SetExternalData(&kGDataPathKey, NULL);
+ download->SetUserData(&kGDataPathKey, NULL);
download->SetDisplayName(gdata_path);
// TODO(achuith): This is not quite right.
download->SetIsTemporary(false);
@@ -250,7 +251,7 @@ void GDataDownloadObserver::SetDownloadParams(const FilePath& gdata_path,
// static
FilePath GDataDownloadObserver::GetGDataPath(DownloadItem* download) {
- GDataExternalData* data = GetGDataExternalData(download);
+ GDataUserData* data = GetGDataUserData(download);
// If data is NULL, we've somehow lost the gdata path selected by the file
// picker.
DCHECK(data);
@@ -259,9 +260,9 @@ FilePath GDataDownloadObserver::GetGDataPath(DownloadItem* download) {
// static
bool GDataDownloadObserver::IsGDataDownload(DownloadItem* download) {
- // We use the existence of the GDataExternalData object in download as a
+ // We use the existence of the GDataUserData object in download as a
// signal that this is a GDataDownload.
- return !!GetGDataExternalData(download);
+ return !!GetGDataUserData(download);
}
// static
@@ -275,7 +276,7 @@ bool GDataDownloadObserver::IsReadyToComplete(
// 2. The upload has completed.
if (!IsGDataDownload(download))
return true;
- UploadingExternalData* upload_data = GetUploadingExternalData(download);
+ UploadingUserData* upload_data = GetUploadingUserData(download);
DCHECK(upload_data);
if (upload_data->is_complete())
return true;
@@ -285,7 +286,7 @@ bool GDataDownloadObserver::IsReadyToComplete(
// static
int64 GDataDownloadObserver::GetUploadedBytes(DownloadItem* download) {
- UploadingExternalData* upload_data = GetUploadingExternalData(download);
+ UploadingUserData* upload_data = GetUploadingUserData(download);
if (!upload_data || !upload_data->uploader())
return 0;
return upload_data->uploader()->GetUploadedBytes(upload_data->upload_id());
@@ -294,7 +295,7 @@ int64 GDataDownloadObserver::GetUploadedBytes(DownloadItem* download) {
// static
int GDataDownloadObserver::PercentComplete(DownloadItem* download) {
// Progress is unknown until the upload starts.
- if (!GetUploadingExternalData(download))
+ if (!GetUploadingUserData(download))
return -1;
int64 complete = GetUploadedBytes(download);
// Once AllDataSaved() is true, we can use the GetReceivedBytes() as the total
@@ -400,8 +401,8 @@ void GDataDownloadObserver::RemovePendingDownload(DownloadItem* download) {
}
void GDataDownloadObserver::DetachFromDownload(DownloadItem* download) {
- download->SetExternalData(&kUploadingKey, NULL);
- download->SetExternalData(&kGDataPathKey, NULL);
+ download->SetUserData(&kUploadingKey, NULL);
+ download->SetUserData(&kGDataPathKey, NULL);
download->RemoveObserver(this);
}
@@ -412,9 +413,9 @@ void GDataDownloadObserver::UploadDownloadItem(DownloadItem* download) {
if (!ShouldUpload(download))
return;
- // Initialize uploading external data.
- download->SetExternalData(&kUploadingKey,
- new UploadingExternalData(gdata_uploader_));
+ // Initialize uploading userdata.
+ download->SetUserData(&kUploadingKey,
+ new UploadingUserData(gdata_uploader_));
// Create UploadFileInfo structure for the download item.
CreateUploadFileInfo(download);
@@ -423,9 +424,9 @@ void GDataDownloadObserver::UploadDownloadItem(DownloadItem* download) {
void GDataDownloadObserver::UpdateUpload(DownloadItem* download) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- UploadingExternalData* upload_data = GetUploadingExternalData(download);
+ UploadingUserData* upload_data = GetUploadingUserData(download);
if (!upload_data) {
- DVLOG(1) << "No UploadingExternalData for download " << download->GetId();
+ DVLOG(1) << "No UploadingUserData for download " << download->GetId();
return;
}
@@ -441,7 +442,7 @@ bool GDataDownloadObserver::ShouldUpload(DownloadItem* download) {
return (pending_downloads_.count(download->GetId()) != 0) &&
(download->AllDataSaved() ||
download->GetReceivedBytes() > kStreamingFileSize) &&
- (GetUploadingExternalData(download) == NULL);
+ (GetUploadingUserData(download) == NULL);
}
void GDataDownloadObserver::CreateUploadFileInfo(DownloadItem* download) {
@@ -512,7 +513,7 @@ void GDataDownloadObserver::StartUpload(
DVLOG(1) << "Starting upload for download ID " << download_id;
DownloadItem* download_item = iter->second;
- UploadingExternalData* upload_data = GetUploadingExternalData(download_item);
+ UploadingUserData* upload_data = GetUploadingUserData(download_item);
DCHECK(upload_data);
upload_data->set_virtual_dir_path(upload_file_info->gdata_path.DirName());
@@ -538,7 +539,7 @@ void GDataDownloadObserver::OnUploadComplete(
DVLOG(1) << "Completing upload for download ID " << download_id;
DownloadItem* download_item = iter->second;
- UploadingExternalData* upload_data = GetUploadingExternalData(download_item);
+ UploadingUserData* upload_data = GetUploadingUserData(download_item);
DCHECK(upload_data);
// Take ownership of the DocumentEntry from UploadFileInfo. This is used by
@@ -553,7 +554,7 @@ void GDataDownloadObserver::OnUploadComplete(
void GDataDownloadObserver::MoveFileToGDataCache(DownloadItem* download) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- UploadingExternalData* upload_data = GetUploadingExternalData(download);
+ UploadingUserData* upload_data = GetUploadingUserData(download);
if (!upload_data) {
NOTREACHED();
return;
diff --git a/chrome/browser/download/chrome_download_manager_delegate.cc b/chrome/browser/download/chrome_download_manager_delegate.cc
index fc95cbf..3a909c7 100644
--- a/chrome/browser/download/chrome_download_manager_delegate.cc
+++ b/chrome/browser/download/chrome_download_manager_delegate.cc
@@ -252,12 +252,12 @@ bool ChromeDownloadManagerDelegate::ShouldOpenFileBasedOnExtension(
void ChromeDownloadManagerDelegate::DisableSafeBrowsing(DownloadItem* item) {
#if defined(ENABLE_SAFE_BROWSING)
SafeBrowsingState* state = static_cast<SafeBrowsingState*>(
- item->GetExternalData(&safe_browsing_id));
+ item->GetUserData(&safe_browsing_id));
DCHECK(!state);
if (!state)
state = new SafeBrowsingState();
state->SetVerdict(DownloadProtectionService::SAFE);
- item->SetExternalData(&safe_browsing_id, state);
+ item->SetUserData(&safe_browsing_id, state);
#endif
}
@@ -266,7 +266,7 @@ bool ChromeDownloadManagerDelegate::IsDownloadReadyForCompletion(
const base::Closure& internal_complete_callback) {
#if defined(ENABLE_SAFE_BROWSING)
SafeBrowsingState* state = static_cast<SafeBrowsingState*>(
- item->GetExternalData(&safe_browsing_id));
+ item->GetUserData(&safe_browsing_id));
if (!state) {
// Begin the safe browsing download protection check.
DownloadProtectionService* service = GetDownloadProtectionService();
@@ -275,7 +275,7 @@ bool ChromeDownloadManagerDelegate::IsDownloadReadyForCompletion(
<< item->DebugString(false);
state = new SafeBrowsingState();
state->set_callback(internal_complete_callback);
- item->SetExternalData(&safe_browsing_id, state);
+ item->SetUserData(&safe_browsing_id, state);
service->CheckClientDownload(
DownloadProtectionService::DownloadInfo::FromDownloadItem(*item),
base::Bind(
@@ -609,7 +609,7 @@ void ChromeDownloadManagerDelegate::CheckClientDownloadDone(
}
SafeBrowsingState* state = static_cast<SafeBrowsingState*>(
- item->GetExternalData(&safe_browsing_id));
+ item->GetUserData(&safe_browsing_id));
state->SetVerdict(result);
}
diff --git a/chrome/browser/download/download_completion_blocker.h b/chrome/browser/download/download_completion_blocker.h
index 8f369b5..6cce983 100644
--- a/chrome/browser/download/download_completion_blocker.h
+++ b/chrome/browser/download/download_completion_blocker.h
@@ -6,13 +6,14 @@
#define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_COMPLETION_BLOCKER_H_
#include "base/callback.h"
+#include "base/supports_user_data.h"
#include "content/public/browser/download_item.h"
// A subsystem may use a DownloadCompletionBlocker in conjunction with
// DownloadManagerDelegate::ShouldCompleteDownload() in order to block the
// completion of a DownloadItem. CompleteDownload() will run the most recent
// callback set.
-class DownloadCompletionBlocker : public content::DownloadItem::ExternalData {
+class DownloadCompletionBlocker : public base::SupportsUserData::Data {
public:
DownloadCompletionBlocker();
virtual ~DownloadCompletionBlocker();
diff --git a/chrome/browser/extensions/webstore_installer.cc b/chrome/browser/extensions/webstore_installer.cc
index 1dfb39f..644b99c 100644
--- a/chrome/browser/extensions/webstore_installer.cc
+++ b/chrome/browser/extensions/webstore_installer.cc
@@ -167,7 +167,7 @@ WebstoreInstaller::Approval::~Approval() {}
const WebstoreInstaller::Approval* WebstoreInstaller::GetAssociatedApproval(
const DownloadItem& download) {
- return static_cast<const Approval*>(download.GetExternalData(kApprovalKey));
+ return static_cast<const Approval*>(download.GetUserData(kApprovalKey));
}
WebstoreInstaller::WebstoreInstaller(Profile* profile,
@@ -283,7 +283,7 @@ void WebstoreInstaller::OnDownloadStarted(DownloadId id, net::Error error) {
download_item_ = download_manager->GetActiveDownloadItem(id.local());
download_item_->AddObserver(this);
if (approval_.get())
- download_item_->SetExternalData(kApprovalKey, approval_.release());
+ download_item_->SetUserData(kApprovalKey, approval_.release());
}
void WebstoreInstaller::OnDownloadUpdated(DownloadItem* download) {
diff --git a/chrome/browser/extensions/webstore_installer.h b/chrome/browser/extensions/webstore_installer.h
index aaf95fb..10b1f5d 100644
--- a/chrome/browser/extensions/webstore_installer.h
+++ b/chrome/browser/extensions/webstore_installer.h
@@ -11,14 +11,15 @@
#include "base/compiler_specific.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
+#include "base/supports_user_data.h"
#include "base/values.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/download_id.h"
#include "content/public/browser/download_item.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
-#include "net/base/net_errors.h"
#include "googleurl/src/gurl.h"
+#include "net/base/net_errors.h"
class FilePath;
class Profile;
@@ -57,7 +58,7 @@ class WebstoreInstaller :public content::NotificationObserver,
// be skipped or modified. If one of these is present, it means that a CRX
// download was initiated by WebstoreInstaller. The Approval instance should
// be checked further for additional details.
- struct Approval : public content::DownloadItem::ExternalData {
+ struct Approval : public base::SupportsUserData::Data {
static scoped_ptr<Approval> CreateWithInstallPrompt(Profile* profile);
static scoped_ptr<Approval> CreateWithNoInstallPrompt(
Profile* profile,