Skip to content

Commit

Permalink
Use base::Timer within pdf plugin instead of chrome_pdf::Timer.
Browse files Browse the repository at this point in the history
Change-Id: I7bb88a19e280140a2a8126f1199aa4321fdf56ef
Reviewed-on: https://chromium-review.googlesource.com/1102425
Commit-Queue: Art Snake <art-snake@yandex-team.ru>
Reviewed-by: dsinclair <dsinclair@chromium.org>
Cr-Commit-Position: refs/heads/master@{#572237}
  • Loading branch information
art-snake authored and Commit Bot committed Jul 3, 2018
1 parent 1f42285 commit 54e088f
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 149 deletions.
2 changes: 0 additions & 2 deletions pdf/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ if (enable_pdf) {
"preview_mode_client.h",
"range_set.cc",
"range_set.h",
"timer.cc",
"timer.h",
"url_loader_wrapper.h",
"url_loader_wrapper_impl.cc",
"url_loader_wrapper_impl.h",
Expand Down
27 changes: 8 additions & 19 deletions pdf/pdfium/pdfium_engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -671,18 +671,6 @@ void ShutdownSDK() {
TearDownV8();
}

PDFiumEngine::TouchTimer::TouchTimer(PDFiumEngine* engine,
int id,
const pp::TouchInputEvent& event)
: Timer(kTouchLongPressTimeout), engine_(engine), id_(id), event_(event) {}

PDFiumEngine::TouchTimer::~TouchTimer() = default;

void PDFiumEngine::TouchTimer::OnTimer() {
engine_->HandleLongPress(event_);
engine_->KillTouchTimer(id_);
}

std::unique_ptr<PDFEngine> PDFEngine::Create(PDFEngine::Client* client,
bool enable_javascript) {
return std::make_unique<PDFiumEngine>(client, enable_javascript);
Expand Down Expand Up @@ -1100,20 +1088,20 @@ bool PDFiumEngine::HandleEvent(const pp::InputEvent& event) {
rv = OnChar(pp::KeyboardInputEvent(event));
break;
case PP_INPUTEVENT_TYPE_TOUCHSTART: {
KillTouchTimer(last_touch_timer_id_);
KillTouchTimer();

pp::TouchInputEvent touch_event(event);
if (touch_event.GetTouchCount(PP_TOUCHLIST_TYPE_TARGETTOUCHES) == 1)
ScheduleTouchTimer(touch_event);
break;
}
case PP_INPUTEVENT_TYPE_TOUCHEND:
KillTouchTimer(last_touch_timer_id_);
KillTouchTimer();
break;
case PP_INPUTEVENT_TYPE_TOUCHMOVE:
// TODO(dsinclair): This should allow a little bit of movement (up to the
// touch radii) to account for finger jiggle.
KillTouchTimer(last_touch_timer_id_);
KillTouchTimer();
break;
default:
break;
Expand Down Expand Up @@ -3526,12 +3514,13 @@ bool PDFiumEngine::IsPointInEditableFormTextArea(FPDF_PAGE page,
}

void PDFiumEngine::ScheduleTouchTimer(const pp::TouchInputEvent& evt) {
const int timer_id = ++last_touch_timer_id_;
touch_timers_[timer_id] = std::make_unique<TouchTimer>(this, timer_id, evt);
touch_timer_.Start(FROM_HERE, kTouchLongPressTimeout,
base::BindRepeating(&PDFiumEngine::HandleLongPress,
base::Unretained(this), evt));
}

void PDFiumEngine::KillTouchTimer(int timer_id) {
touch_timers_.erase(timer_id);
void PDFiumEngine::KillTouchTimer() {
touch_timer_.Stop();
}

bool PDFiumEngine::PageIndexInBounds(int index) const {
Expand Down
23 changes: 4 additions & 19 deletions pdf/pdfium/pdfium_engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
#include "base/macros.h"
#include "base/optional.h"
#include "base/time/time.h"
#include "base/timer/timer.h"
#include "pdf/document_loader.h"
#include "pdf/pdf_engine.h"
#include "pdf/pdfium/pdfium_form_filler.h"
#include "pdf/pdfium/pdfium_page.h"
#include "pdf/pdfium/pdfium_print.h"
#include "pdf/pdfium/pdfium_range.h"
#include "pdf/timer.h"
#include "ppapi/cpp/completion_callback.h"
#include "ppapi/cpp/dev/buffer_dev.h"
#include "ppapi/cpp/image_data.h"
Expand Down Expand Up @@ -146,20 +146,6 @@ class PDFiumEngine : public PDFEngine,
FPDF_FORMHANDLE form() const { return form_.get(); }

private:
class TouchTimer : public Timer {
public:
TouchTimer(PDFiumEngine* engine, int id, const pp::TouchInputEvent& event);
~TouchTimer() override;

// Timer overrides:
void OnTimer() override;

private:
PDFiumEngine* engine_;
const int id_;
const pp::TouchInputEvent event_;
};

// This helper class is used to detect the difference in selection between
// construction and destruction. At destruction, it invalidates all the
// parts that are newly selected, along with all the parts that used to be
Expand Down Expand Up @@ -486,7 +472,7 @@ class PDFiumEngine : public PDFEngine,
float GetToolbarHeightInScreenCoords();

void ScheduleTouchTimer(const pp::TouchInputEvent& event);
void KillTouchTimer(int timer_id);
void KillTouchTimer();
void HandleLongPress(const pp::TouchInputEvent& event);

// Returns a VarDictionary (representing a bookmark), which in turn contains
Expand Down Expand Up @@ -619,9 +605,8 @@ class PDFiumEngine : public PDFEngine,

pp::Size default_page_size_;

// Used to manage timers for touch long press.
std::map<int, std::unique_ptr<TouchTimer>> touch_timers_;
int last_touch_timer_id_ = 0;
// Timer for touch long press detection.
base::OneShotTimer touch_timer_;

// Holds the zero-based page index of the last page that the mouse clicked on.
int last_page_mouse_down_ = -1;
Expand Down
23 changes: 3 additions & 20 deletions pdf/pdfium/pdfium_form_filler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "pdf/pdfium/pdfium_engine.h"
#include "pdf/timer.h"

namespace chrome_pdf {

Expand All @@ -21,23 +20,6 @@ std::string WideStringToString(FPDF_WIDESTRING wide_string) {
return base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(wide_string));
}

class FormFillTimer : public Timer {
public:
FormFillTimer(base::TimeDelta delay, int id, TimerCallback timer_callback)
: Timer(delay), id_(id), timer_callback_(timer_callback) {}

~FormFillTimer() override = default;

// Timer overrides:
void OnTimer() override { timer_callback_(id_); }

private:
const int id_;
TimerCallback timer_callback_;

DISALLOW_COPY_AND_ASSIGN(FormFillTimer);
};

} // namespace

PDFiumFormFiller::PDFiumFormFiller(PDFiumEngine* engine, bool enable_javascript)
Expand Down Expand Up @@ -644,8 +626,9 @@ PDFiumEngine* PDFiumFormFiller::GetEngine(IPDF_JSPLATFORM* platform) {
int PDFiumFormFiller::SetTimer(const base::TimeDelta& delay,
TimerCallback timer_func) {
const int timer_id = ++last_timer_id_;
timers_[timer_id] =
std::make_unique<FormFillTimer>(delay, timer_id, timer_func);
auto timer = std::make_unique<base::RepeatingTimer>();
timer->Start(FROM_HERE, delay, base::BindRepeating(timer_func, timer_id));
timers_[timer_id] = std::move(timer);
return timer_id;
}

Expand Down
5 changes: 2 additions & 3 deletions pdf/pdfium/pdfium_form_filler.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@

#include "base/macros.h"
#include "base/time/time.h"
#include "base/timer/timer.h"
#include "third_party/pdfium/public/fpdf_formfill.h"

namespace chrome_pdf {

class PDFiumEngine;
class Timer;

class PDFiumFormFiller : public FPDF_FORMFILLINFO, public IPDF_JSPLATFORM {
public:
Expand Down Expand Up @@ -176,8 +176,7 @@ class PDFiumFormFiller : public FPDF_FORMFILLINFO, public IPDF_JSPLATFORM {

PDFiumEngine* const engine_;

std::map<int, std::unique_ptr<Timer>> timers_;

std::map<int, std::unique_ptr<base::RepeatingTimer>> timers_;
int last_timer_id_ = 0;

DISALLOW_COPY_AND_ASSIGN(PDFiumFormFiller);
Expand Down
30 changes: 0 additions & 30 deletions pdf/timer.cc

This file was deleted.

36 changes: 0 additions & 36 deletions pdf/timer.h

This file was deleted.

22 changes: 5 additions & 17 deletions pdf/url_loader_wrapper_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "net/http/http_util.h"
#include "pdf/timer.h"
#include "ppapi/c/pp_errors.h"
#include "ppapi/cpp/logging.h"
#include "ppapi/cpp/url_request_info.h"
Expand Down Expand Up @@ -97,19 +96,6 @@ bool IsDoubleEndLineAtEnd(const char* buffer, int size) {

} // namespace

class URLLoaderWrapperImpl::ReadStarter : public Timer {
public:
explicit ReadStarter(URLLoaderWrapperImpl* owner)
: Timer(kReadDelayMs), owner_(owner) {}
~ReadStarter() override = default;

// Timer overrides:
void OnTimer() override { owner_->ReadResponseBodyImpl(); }

private:
URLLoaderWrapperImpl* owner_;
};

URLLoaderWrapperImpl::URLLoaderWrapperImpl(pp::Instance* plugin_instance,
const pp::URLLoader& url_loader)
: plugin_instance_(plugin_instance),
Expand Down Expand Up @@ -171,7 +157,7 @@ bool URLLoaderWrapperImpl::GetDownloadProgress(

void URLLoaderWrapperImpl::Close() {
url_loader_.Close();
read_starter_.reset();
read_starter_.Stop();
}

void URLLoaderWrapperImpl::OpenRange(const std::string& url,
Expand All @@ -195,11 +181,13 @@ void URLLoaderWrapperImpl::ReadResponseBody(char* buffer,
did_read_callback_ = cc;
buffer_ = buffer;
buffer_size_ = buffer_size;
read_starter_ = std::make_unique<ReadStarter>(this);
read_starter_.Start(
FROM_HERE, kReadDelayMs,
base::BindRepeating(&URLLoaderWrapperImpl::ReadResponseBodyImpl,
base::Unretained(this)));
}

void URLLoaderWrapperImpl::ReadResponseBodyImpl() {
read_starter_.reset();
pp::CompletionCallback callback =
callback_factory_.NewCallback(&URLLoaderWrapperImpl::DidRead);
int rv = url_loader_.ReadResponseBody(buffer_, buffer_size_, callback);
Expand Down
5 changes: 2 additions & 3 deletions pdf/url_loader_wrapper_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <string>

#include "base/macros.h"
#include "base/timer/timer.h"
#include "pdf/url_loader_wrapper.h"
#include "ppapi/cpp/url_loader.h"
#include "ppapi/utility/completion_callback_factory.h"
Expand Down Expand Up @@ -50,8 +51,6 @@ class URLLoaderWrapperImpl : public URLLoaderWrapper {
void SetResponseHeaders(const std::string& response_headers);

private:
class ReadStarter;

void SetHeadersFromLoader();
void ParseHeaders();
void DidOpen(int32_t result);
Expand Down Expand Up @@ -79,7 +78,7 @@ class URLLoaderWrapperImpl : public URLLoaderWrapper {
pp::CompletionCallback did_read_callback_;
pp::CompletionCallbackFactory<URLLoaderWrapperImpl> callback_factory_;

std::unique_ptr<ReadStarter> read_starter_;
base::OneShotTimer read_starter_;

DISALLOW_COPY_AND_ASSIGN(URLLoaderWrapperImpl);
};
Expand Down

0 comments on commit 54e088f

Please sign in to comment.