diff options
author | jianli@chromium.org <jianli@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-10 00:00:32 +0000 |
---|---|---|
committer | jianli@chromium.org <jianli@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-10 00:00:32 +0000 |
commit | 8af9d0341d6c00ee537adc089f938b120d1d8d34 (patch) | |
tree | 334fcf5a09c2b3e12face9d46ae4f25ee62921eb /app/os_exchange_data_provider_win.cc | |
parent | 8d292399e6dcdfa776a1de94da07841bf1487f5b (diff) | |
download | chromium_src-8af9d0341d6c00ee537adc089f938b120d1d8d34.zip chromium_src-8af9d0341d6c00ee537adc089f938b120d1d8d34.tar.gz chromium_src-8af9d0341d6c00ee537adc089f938b120d1d8d34.tar.bz2 |
Refactor DragDownloadFile so that it can be used by both Windows and MacOSX.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/572014
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@38545 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'app/os_exchange_data_provider_win.cc')
-rw-r--r-- | app/os_exchange_data_provider_win.cc | 71 |
1 files changed, 28 insertions, 43 deletions
diff --git a/app/os_exchange_data_provider_win.cc b/app/os_exchange_data_provider_win.cc index dc28597..8f953d1 100644 --- a/app/os_exchange_data_provider_win.cc +++ b/app/os_exchange_data_provider_win.cc @@ -455,17 +455,17 @@ bool OSExchangeDataProviderWin::HasCustomFormat(CLIPFORMAT format) const { } void OSExchangeDataProviderWin::SetDownloadFileInfo( - OSExchangeData::DownloadFileInfo* download) { + const OSExchangeData::DownloadFileInfo& download) { // If the filename is not provided, set stoarge to NULL to indicate that // the delay rendering will be used. STGMEDIUM* storage = NULL; - if (!download->filename.empty()) - storage = GetStorageForFileName(download->filename.value()); + if (!download.filename.empty()) + storage = GetStorageForFileName(download.filename.value()); // Add CF_HDROP. DataObjectImpl::StoredDataInfo* info = new DataObjectImpl::StoredDataInfo( ClipboardUtil::GetCFHDropFormat()->cfFormat, storage); - info->downloads.push_back(download); + info->downloader = download.downloader; data_->contents_.push_back(info); } @@ -560,35 +560,18 @@ DataObjectImpl::~DataObjectImpl() { void DataObjectImpl::StopDownloads() { for (StoredData::iterator iter = contents_.begin(); iter != contents_.end(); ++iter) { - for (size_t i = 0; i < (*iter)->downloads.size(); ++i) { - if ((*iter)->downloads[i]->downloader) { - (*iter)->downloads[i]->downloader->Stop(); - (*iter)->downloads[i]->downloader = 0; - } - delete (*iter)->downloads[i]; + if ((*iter)->downloader.get()) { + (*iter)->downloader->Stop(); + (*iter)->downloader = 0; } - (*iter)->downloads.clear(); } } -void DataObjectImpl::OnDataReady( - int format, - const std::vector<OSExchangeData::DownloadFileInfo*>& downloads) { - // Find and update the data corresponding to the format. - CLIPFORMAT clip_format = static_cast<CLIPFORMAT>(format); - DCHECK(clip_format == ClipboardUtil::GetCFHDropFormat()->cfFormat); +void DataObjectImpl::OnDownloadCompleted(const FilePath& file_path) { + CLIPFORMAT hdrop_format = ClipboardUtil::GetCFHDropFormat()->cfFormat; DataObjectImpl::StoredData::iterator iter = contents_.begin(); for (; iter != contents_.end(); ++iter) { - if ((*iter)->format_etc.cfFormat == clip_format) { - // Update the downloads. - DCHECK(downloads.size() == (*iter)->downloads.size()); - for (size_t i = 0; i < (*iter)->downloads.size(); ++i) { - OSExchangeData::DownloadFileInfo* old_download = (*iter)->downloads[i]; - (*iter)->downloads[i] = downloads[i]; - (*iter)->downloads[i]->downloader = old_download->downloader; - delete old_download; - } - + if ((*iter)->format_etc.cfFormat == hdrop_format) { // Release the old storage. if ((*iter)->owns_medium) { ReleaseStgMedium((*iter)->medium); @@ -597,7 +580,7 @@ void DataObjectImpl::OnDataReady( // Update the storage. (*iter)->owns_medium = true; - (*iter)->medium = GetStorageForFileName(downloads[0]->filename.value()); + (*iter)->medium = GetStorageForFileName(file_path.value()); break; } @@ -605,6 +588,9 @@ void DataObjectImpl::OnDataReady( DCHECK(iter != contents_.end()); } +void DataObjectImpl::OnDownloadAborted() { +} + HRESULT DataObjectImpl::GetData(FORMATETC* format_etc, STGMEDIUM* medium) { if (is_aborting_) return DV_E_FORMATETC; @@ -629,7 +615,12 @@ HRESULT DataObjectImpl::GetData(FORMATETC* format_etc, STGMEDIUM* medium) { if (is_left_button_down) return DV_E_FORMATETC; - wait_for_data = true; + // In async mode, we do not want to start waiting for the data before + // the async operation is started. This is because we want to postpone + // until Shell kicks off a background thread to do the work so that + // we do not block the UI thread. + if (!in_async_mode_ || async_operation_started_) + wait_for_data = true; } else { // If the left button is up and the target has not requested the data // yet, it probably means that the target does not support delay- @@ -648,18 +639,11 @@ HRESULT DataObjectImpl::GetData(FORMATETC* format_etc, STGMEDIUM* medium) { if (observer_) observer_->OnWaitForData(); - // Now we can start the downloads. Each download will wait till the - // necessary data is ready and then return the control. - for (size_t i = 0; i < (*iter)->downloads.size(); ++i) { - if ((*iter)->downloads[i]->downloader) { - if (!(*iter)->downloads[i]->downloader->Start( - this, format_etc->cfFormat)) { - // If any of the download fails to start, abort the whole - // process. - is_aborting_ = true; - StopDownloads(); - return DV_E_FORMATETC; - } + // Now we can start the download. + if ((*iter)->downloader.get()) { + if (!(*iter)->downloader->Start(this)) { + is_aborting_ = true; + return DV_E_FORMATETC; } } @@ -788,12 +772,12 @@ HRESULT DataObjectImpl::QueryInterface(const IID& iid, void** object) { } ULONG DataObjectImpl::AddRef() { - base::RefCounted<OSExchangeData::DownloadFileObserver>::AddRef(); + base::RefCountedThreadSafe<DownloadFileObserver>::AddRef(); return 0; } ULONG DataObjectImpl::Release() { - base::RefCounted<OSExchangeData::DownloadFileObserver>::Release(); + base::RefCountedThreadSafe<DownloadFileObserver>::Release(); return 0; } @@ -918,6 +902,7 @@ static STGMEDIUM* GetStorageForFileDescriptor( return storage; } + /////////////////////////////////////////////////////////////////////////////// // OSExchangeData, public: |