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

Unified Diff: webkit/media/buffered_resource_loader.cc

Issue 10692106: Split BufferedResourceLoader's network callback into separate loading state and progress callbacks. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add bug #s 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: webkit/media/buffered_resource_loader.cc
diff --git a/webkit/media/buffered_resource_loader.cc b/webkit/media/buffered_resource_loader.cc
index cfeda51d00cd0073e1171262f51190fa469e966e..424c0d0d2dd70bfc7cceec6b20bbaf69990fd466 100644
--- a/webkit/media/buffered_resource_loader.cc
+++ b/webkit/media/buffered_resource_loader.cc
@@ -142,17 +142,21 @@ BufferedResourceLoader::~BufferedResourceLoader() {}
void BufferedResourceLoader::Start(
const StartCB& start_cb,
- const base::Closure& event_cb,
+ const LoadingCB& loading_cb,
+ const ProgressCB& progress_cb,
WebFrame* frame) {
// Make sure we have not started.
DCHECK(start_cb_.is_null());
- DCHECK(event_cb_.is_null());
+ DCHECK(loading_cb_.is_null());
+ DCHECK(progress_cb_.is_null());
DCHECK(!start_cb.is_null());
- DCHECK(!event_cb.is_null());
+ DCHECK(!loading_cb.is_null());
+ DCHECK(!progress_cb.is_null());
CHECK(frame);
start_cb_ = start_cb;
- event_cb_ = event_cb;
+ loading_cb_ = loading_cb;
+ progress_cb_ = progress_cb;
if (first_byte_position_ != kPositionNotSpecified) {
// TODO(hclam): server may not support range request so |offset_| may not
@@ -193,12 +197,14 @@ void BufferedResourceLoader::Start(
// Start the resource loading.
loader->loadAsynchronously(request, this);
active_loader_.reset(new ActiveLoader(loader.Pass()));
+ loading_cb_.Run(kLoading);
}
void BufferedResourceLoader::Stop() {
// Reset callbacks.
start_cb_.Reset();
- event_cb_.Reset();
+ loading_cb_.Reset();
+ progress_cb_.Reset();
read_cb_.Reset();
// Cancel and reset any active loaders.
@@ -303,10 +309,6 @@ void BufferedResourceLoader::Read(
DoneRead(kCacheMiss, 0);
}
-int64 BufferedResourceLoader::GetBufferedPosition() {
- return offset_ + buffer_.forward_bytes() - 1;
-}
-
int64 BufferedResourceLoader::content_length() {
return content_length_;
}
@@ -467,8 +469,8 @@ void BufferedResourceLoader::didReceiveData(
offset_ += first_offset_ + excess;
}
- // Notify that we have received some data.
- NotifyNetworkEvent();
+ // Notify latest progress and buffered offset.
+ progress_cb_.Run(offset_ + buffer_.forward_bytes() - 1);
Log();
}
@@ -493,7 +495,7 @@ void BufferedResourceLoader::didFinishLoading(
// We're done with the loader.
active_loader_.reset();
- NotifyNetworkEvent();
+ loading_cb_.Run(kLoadingFinished);
// If we didn't know the |instance_size_| we do now.
if (instance_size_ == kPositionNotSpecified) {
@@ -534,7 +536,7 @@ void BufferedResourceLoader::didFail(
// Keep it alive until we exit this method so that |error| remains valid.
scoped_ptr<ActiveLoader> active_loader = active_loader_.Pass();
loader_failed_ = true;
- NotifyNetworkEvent();
+ loading_cb_.Run(kLoadingFailed);
// Don't leave start callbacks hanging around.
if (!start_cb_.is_null()) {
@@ -608,7 +610,7 @@ void BufferedResourceLoader::UpdateDeferBehavior() {
void BufferedResourceLoader::SetDeferred(bool deferred) {
active_loader_->SetDeferred(deferred);
- NotifyNetworkEvent();
+ loading_cb_.Run(deferred ? kLoadingDeferred : kLoading);
}
bool BufferedResourceLoader::ShouldEnableDefer() const {
@@ -821,11 +823,6 @@ void BufferedResourceLoader::DoneStart(Status status) {
base::ResetAndReturn(&start_cb_).Run(status);
}
-void BufferedResourceLoader::NotifyNetworkEvent() {
- if (!event_cb_.is_null())
- event_cb_.Run();
-}
-
bool BufferedResourceLoader::IsRangeRequest() const {
return first_byte_position_ != kPositionNotSpecified;
}

Powered by Google App Engine
This is Rietveld 408576698