diff options
author | kuan@chromium.org <kuan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-27 01:46:21 +0000 |
---|---|---|
committer | kuan@chromium.org <kuan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-27 01:46:21 +0000 |
commit | 6fdecd845d875dd30274455b63c6a81fe764efa9 (patch) | |
tree | c28dd5f4f28d65dc6cb2f2afe3117dfb078e2878 /content/common | |
parent | a6a1953b8b20a9ea546d4361c7c1d12bccf65126 (diff) | |
download | chromium_src-6fdecd845d875dd30274455b63c6a81fe764efa9.zip chromium_src-6fdecd845d875dd30274455b63c6a81fe764efa9.tar.gz chromium_src-6fdecd845d875dd30274455b63c6a81fe764efa9.tar.bz2 |
add methods to URLFetcherDelegate to get download data from URLFetcherCore:
1) OnUrlFetchDownloadData to get current download buffer.
2) ShouldSendDownloadData to indicate if OnUrlFetchDownloadData should be called.
BUG=chromium-os:29905
TEST=nothing yet.
Review URL: http://codereview.chromium.org/10227007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@134207 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/common')
-rw-r--r-- | content/common/net/url_fetcher_core.cc | 21 | ||||
-rw-r--r-- | content/common/net/url_fetcher_core.h | 3 |
2 files changed, 24 insertions, 0 deletions
diff --git a/content/common/net/url_fetcher_core.cc b/content/common/net/url_fetcher_core.cc index a067ed6..0a4b7ee 100644 --- a/content/common/net/url_fetcher_core.cc +++ b/content/common/net/url_fetcher_core.cc @@ -616,6 +616,7 @@ void URLFetcherCore::OnReadCompleted(net::URLRequest* request, current_response_bytes_ += bytes_read; InformDelegateDownloadProgress(); + InformDelegateDownloadDataIfNecessary(bytes_read); if (!WriteBuffer(bytes_read)) { // If WriteBuffer() returns false, we have a pending write to @@ -881,6 +882,26 @@ void URLFetcherCore::InformDelegateDownloadProgressInDelegateThread( delegate_->OnURLFetchDownloadProgress(fetcher_, current, total); } +void URLFetcherCore::InformDelegateDownloadDataIfNecessary(int bytes_read) { + DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); + if (delegate_ && delegate_->ShouldSendDownloadData()) { + scoped_ptr<std::string> download_data( + new std::string(buffer_->data(), bytes_read)); + delegate_loop_proxy_->PostTask( + FROM_HERE, + base::Bind( + &URLFetcherCore::InformDelegateDownloadDataInDelegateThread, + this, base::Passed(&download_data))); + } +} + +void URLFetcherCore::InformDelegateDownloadDataInDelegateThread( + scoped_ptr<std::string> download_data) { + DCHECK(delegate_loop_proxy_->BelongsToCurrentThread()); + if (delegate_) + delegate_->OnURLFetchDownloadData(fetcher_, download_data.Pass()); +} + void URLFetcherCore::InformDelegateFetchIsComplete() { DCHECK(delegate_loop_proxy_->BelongsToCurrentThread()); if (delegate_) diff --git a/content/common/net/url_fetcher_core.h b/content/common/net/url_fetcher_core.h index d0e67ff..db190a4 100644 --- a/content/common/net/url_fetcher_core.h +++ b/content/common/net/url_fetcher_core.h @@ -293,6 +293,9 @@ class URLFetcherCore void InformDelegateDownloadProgress(); void InformDelegateDownloadProgressInDelegateThread(int64 current, int64 total); + void InformDelegateDownloadDataIfNecessary(int bytes_read); + void InformDelegateDownloadDataInDelegateThread( + scoped_ptr<std::string> download_data); URLFetcher* fetcher_; // Corresponding fetcher object GURL original_url_; // The URL we were asked to fetch |