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

Unified Diff: chrome/browser/image_decoder.cc

Issue 1114003002: Replace the RepeatingTimer in ImageDecoder with a DelayTimer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comment Created 5 years, 8 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
« no previous file with comments | « chrome/browser/image_decoder.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/image_decoder.cc
diff --git a/chrome/browser/image_decoder.cc b/chrome/browser/image_decoder.cc
index f8f736ae63c2983a5ff57785f8e99884ae2927ad..4498f33e1f0bfdb4f0e81302e060fd7aa7f85b7f 100644
--- a/chrome/browser/image_decoder.cc
+++ b/chrome/browser/image_decoder.cc
@@ -28,7 +28,7 @@ const int kBatchModeTimeoutSeconds = 5;
} // namespace
ImageDecoder::ImageDecoder()
- : image_request_id_counter_(0), last_request_(base::TimeTicks::Now()) {
+ : image_request_id_counter_(0) {
// A single ImageDecoder instance should live for the life of the program.
// Explicitly add a reference so the object isn't deleted.
AddRef();
@@ -123,7 +123,15 @@ void ImageDecoder::DecodeImageInSandbox(
return;
}
- last_request_ = base::TimeTicks::Now();
+ if (!batch_mode_timer_) {
+ // Created here so it will call StopBatchMode() on the right thread.
+ batch_mode_timer_.reset(new base::DelayTimer<ImageDecoder>(
+ FROM_HERE,
+ base::TimeDelta::FromSeconds(kBatchModeTimeoutSeconds),
+ this,
+ &ImageDecoder::StopBatchMode));
+ }
+ batch_mode_timer_->Reset();
switch (image_codec) {
case ROBUST_JPEG_CODEC:
@@ -160,23 +168,14 @@ void ImageDecoder::StartBatchMode() {
utility_process_host_.reset();
return;
}
- batch_mode_timer_.Start(
- FROM_HERE, base::TimeDelta::FromSeconds(kBatchModeTimeoutSeconds),
- this, &ImageDecoder::StopBatchMode);
}
void ImageDecoder::StopBatchMode() {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
- if ((base::TimeTicks::Now() - last_request_)
- < base::TimeDelta::FromSeconds(kBatchModeTimeoutSeconds)) {
- return;
- }
-
if (utility_process_host_) {
utility_process_host_->EndBatchMode();
utility_process_host_.reset();
}
- batch_mode_timer_.Stop();
}
bool ImageDecoder::OnMessageReceived(
« no previous file with comments | « chrome/browser/image_decoder.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698