0

Use base::TimeDelta in chrome_pdf::Timer.

Change-Id: Ib087b7ea70bae6bad8c7512cdc7f6c5d84b58661
Reviewed-on: https://chromium-review.googlesource.com/809292
Reviewed-by: dsinclair <dsinclair@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#521873}
This commit is contained in:
Lei Zhang
2017-12-05 22:48:53 +00:00
committed by Commit Bot
parent 363560ef6a
commit f74659eceb
3 changed files with 8 additions and 6 deletions

@ -9,8 +9,7 @@
namespace chrome_pdf {
Timer::Timer(int delay_in_milliseconds)
: delay_(delay_in_milliseconds), callback_factory_(this) {
Timer::Timer(base::TimeDelta delay) : delay_(delay), callback_factory_(this) {
PostCallback();
}
@ -19,7 +18,8 @@ Timer::~Timer() = default;
void Timer::PostCallback() {
pp::CompletionCallback callback =
callback_factory_.NewCallback(&Timer::TimerProc);
pp::Module::Get()->core()->CallOnMainThread(delay_, callback, 0);
pp::Module::Get()->core()->CallOnMainThread(delay_.InMilliseconds(), callback,
0);
}
void Timer::TimerProc(int32_t /*result*/) {

@ -6,6 +6,7 @@
#define PDF_TIMER_H_
#include "base/macros.h"
#include "base/time/time.h"
#include "ppapi/utility/completion_callback_factory.h"
namespace chrome_pdf {
@ -15,7 +16,7 @@ namespace chrome_pdf {
// base::MessageLoop, on which it is based.
class Timer {
public:
explicit Timer(int delay_in_milliseconds);
explicit Timer(base::TimeDelta delay);
virtual ~Timer();
virtual void OnTimer() = 0;
@ -24,7 +25,7 @@ class Timer {
void PostCallback();
void TimerProc(int32_t result);
int delay_;
const base::TimeDelta delay_;
pp::CompletionCallbackFactory<Timer> callback_factory_;
DISALLOW_COPY_AND_ASSIGN(Timer);

@ -19,8 +19,9 @@
namespace chrome_pdf {
namespace {
// We should read with delay to prevent block UI thread, and reduce CPU usage.
const int kReadDelayMs = 2;
constexpr base::TimeDelta kReadDelayMs = base::TimeDelta::FromMilliseconds(2);
pp::URLRequestInfo MakeRangeRequest(pp::Instance* plugin_instance,
const std::string& url,