Commit 3705c91e authored by Hui Yingst's avatar Hui Yingst Committed by Commit Bot

Remove pp::CompletionCallbackFactory in pdf/.

With PPCompletionCallbackFromResultCallback() wraps base::OnceCallback
as a pp::CompletionCallback, direct references to
pp::CompletionCallbackFactory in pdf/ now can be removed.

Bug: 1101169
Change-Id: If8249b1d995221f9f7fb765dee8509368c7a21bb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2347978
Commit-Queue: Hui Yingst <nigi@chromium.org>
Reviewed-by: default avatarK. Moon <kmoon@chromium.org>
Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#797915}
parent 04057c5a
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "base/callback.h" #include "base/callback.h"
#include "base/feature_list.h" #include "base/feature_list.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/memory/weak_ptr.h"
#include "base/metrics/histogram_functions.h" #include "base/metrics/histogram_functions.h"
#include "base/notreached.h" #include "base/notreached.h"
#include "base/numerics/ranges.h" #include "base/numerics/ranges.h"
...@@ -460,7 +461,6 @@ OutOfProcessInstance::OutOfProcessInstance(PP_Instance instance) ...@@ -460,7 +461,6 @@ OutOfProcessInstance::OutOfProcessInstance(PP_Instance instance)
pp::Find_Private(this), pp::Find_Private(this),
pp::Printing_Dev(this), pp::Printing_Dev(this),
paint_manager_(this) { paint_manager_(this) {
callback_factory_.Initialize(this);
pp::Module::Get()->AddPluginInterface(kPPPPdfInterface, &ppp_private); pp::Module::Get()->AddPluginInterface(kPPPPdfInterface, &ppp_private);
AddPerInstanceObject(kPPPPdfInterface, this); AddPerInstanceObject(kPPPPdfInterface, this);
...@@ -776,10 +776,12 @@ void OutOfProcessInstance::LoadAccessibility() { ...@@ -776,10 +776,12 @@ void OutOfProcessInstance::LoadAccessibility() {
SendAccessibilityViewportInfo(); SendAccessibilityViewportInfo();
// Schedule loading the first page. // Schedule loading the first page.
pp::CompletionCallback callback = callback_factory_.NewCallback( pp::Module::Get()->core()->CallOnMainThread(
&OutOfProcessInstance::SendNextAccessibilityPage); kAccessibilityPageDelayMs,
pp::Module::Get()->core()->CallOnMainThread(kAccessibilityPageDelayMs, PPCompletionCallbackFromResultCallback(
callback, 0); base::BindOnce(&OutOfProcessInstance::SendNextAccessibilityPage,
weak_factory_.GetWeakPtr())),
0);
} }
void OutOfProcessInstance::SendNextAccessibilityPage(int32_t page_index) { void OutOfProcessInstance::SendNextAccessibilityPage(int32_t page_index) {
...@@ -797,10 +799,12 @@ void OutOfProcessInstance::SendNextAccessibilityPage(int32_t page_index) { ...@@ -797,10 +799,12 @@ void OutOfProcessInstance::SendNextAccessibilityPage(int32_t page_index) {
chars, page_objects); chars, page_objects);
// Schedule loading the next page. // Schedule loading the next page.
pp::CompletionCallback callback = callback_factory_.NewCallback( pp::Module::Get()->core()->CallOnMainThread(
&OutOfProcessInstance::SendNextAccessibilityPage); kAccessibilityPageDelayMs,
pp::Module::Get()->core()->CallOnMainThread(kAccessibilityPageDelayMs, PPCompletionCallbackFromResultCallback(
callback, page_index + 1); base::BindOnce(&OutOfProcessInstance::SendNextAccessibilityPage,
weak_factory_.GetWeakPtr())),
page_index + 1);
} }
void OutOfProcessInstance::SendAccessibilityViewportInfo() { void OutOfProcessInstance::SendAccessibilityViewportInfo() {
...@@ -1058,9 +1062,10 @@ void OutOfProcessInstance::OnPaint(const std::vector<gfx::Rect>& paint_rects, ...@@ -1058,9 +1062,10 @@ void OutOfProcessInstance::OnPaint(const std::vector<gfx::Rect>& paint_rects,
engine()->PostPaint(); engine()->PostPaint();
if (!deferred_invalidates_.empty()) { if (!deferred_invalidates_.empty()) {
pp::CompletionCallback callback = callback_factory_.NewCallback( pp::Module::Get()->core()->CallOnMainThread(
&OutOfProcessInstance::InvalidateAfterPaintDone); 0, PPCompletionCallbackFromResultCallback(
pp::Module::Get()->core()->CallOnMainThread(0, callback); base::BindOnce(&OutOfProcessInstance::InvalidateAfterPaintDone,
weak_factory_.GetWeakPtr())));
} }
} }
...@@ -1274,10 +1279,12 @@ void OutOfProcessInstance::NotifyNumberOfFindResultsChanged(int total, ...@@ -1274,10 +1279,12 @@ void OutOfProcessInstance::NotifyNumberOfFindResultsChanged(int total,
NumberOfFindResultsChanged(total, final_result); NumberOfFindResultsChanged(total, final_result);
SetTickmarks(tickmarks_); SetTickmarks(tickmarks_);
recently_sent_find_update_ = true; recently_sent_find_update_ = true;
pp::CompletionCallback callback = callback_factory_.NewCallback( pp::Module::Get()->core()->CallOnMainThread(
&OutOfProcessInstance::ResetRecentlySentFindUpdate); kFindResultCooldownMs,
pp::Module::Get()->core()->CallOnMainThread(kFindResultCooldownMs, callback, PPCompletionCallbackFromResultCallback(
0); base::BindOnce(&OutOfProcessInstance::ResetRecentlySentFindUpdate,
weak_factory_.GetWeakPtr())),
0);
} }
void OutOfProcessInstance::NotifySelectedFindResultChanged( void OutOfProcessInstance::NotifySelectedFindResultChanged(
...@@ -1413,9 +1420,9 @@ void OutOfProcessInstance::Print() { ...@@ -1413,9 +1420,9 @@ void OutOfProcessInstance::Print() {
return; return;
} }
pp::CompletionCallback callback = pp::Module::Get()->core()->CallOnMainThread(
callback_factory_.NewCallback(&OutOfProcessInstance::OnPrint); 0, PPCompletionCallbackFromResultCallback(base::BindOnce(
pp::Module::Get()->core()->CallOnMainThread(0, callback); &OutOfProcessInstance::OnPrint, weak_factory_.GetWeakPtr())));
} }
void OutOfProcessInstance::SubmitForm(const std::string& url, void OutOfProcessInstance::SubmitForm(const std::string& url,
...@@ -1426,9 +1433,10 @@ void OutOfProcessInstance::SubmitForm(const std::string& url, ...@@ -1426,9 +1433,10 @@ void OutOfProcessInstance::SubmitForm(const std::string& url,
request.SetMethod("POST"); request.SetMethod("POST");
request.AppendDataToBody(reinterpret_cast<const char*>(data), length); request.AppendDataToBody(reinterpret_cast<const char*>(data), length);
pp::CompletionCallback callback =
callback_factory_.NewCallback(&OutOfProcessInstance::FormDidOpen);
form_loader_ = CreateURLLoaderInternal(); form_loader_ = CreateURLLoaderInternal();
pp::CompletionCallback callback =
PPCompletionCallbackFromResultCallback(base::BindOnce(
&OutOfProcessInstance::FormDidOpen, weak_factory_.GetWeakPtr()));
int rv = form_loader_.Open(request, callback); int rv = form_loader_.Open(request, callback);
if (rv != PP_OK_COMPLETIONPENDING) if (rv != PP_OK_COMPLETIONPENDING)
callback.Run(rv); callback.Run(rv);
...@@ -2020,9 +2028,10 @@ void OutOfProcessInstance::LoadUrl(const std::string& url, ...@@ -2020,9 +2028,10 @@ void OutOfProcessInstance::LoadUrl(const std::string& url,
pp::URLLoader* loader = pp::URLLoader* loader =
is_print_preview ? &embed_preview_loader_ : &embed_loader_; is_print_preview ? &embed_preview_loader_ : &embed_loader_;
*loader = CreateURLLoaderInternal(); *loader = CreateURLLoaderInternal();
pp::CompletionCallback callback = callback_factory_.NewCallback( pp::CompletionCallback callback = PPCompletionCallbackFromResultCallback(
is_print_preview ? &OutOfProcessInstance::DidOpenPreview base::BindOnce(is_print_preview ? &OutOfProcessInstance::DidOpenPreview
: &OutOfProcessInstance::DidOpen); : &OutOfProcessInstance::DidOpen,
weak_factory_.GetWeakPtr()));
int rv = loader->Open(request, callback); int rv = loader->Open(request, callback);
if (rv != PP_OK_COMPLETIONPENDING) if (rv != PP_OK_COMPLETIONPENDING)
callback.Run(rv); callback.Run(rv);
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "base/callback.h" #include "base/callback.h"
#include "base/containers/queue.h" #include "base/containers/queue.h"
#include "base/memory/weak_ptr.h"
#include "pdf/paint_manager.h" #include "pdf/paint_manager.h"
#include "pdf/pdf_view_plugin_base.h" #include "pdf/pdf_view_plugin_base.h"
#include "pdf/preview_mode_client.h" #include "pdf/preview_mode_client.h"
...@@ -25,7 +26,6 @@ ...@@ -25,7 +26,6 @@
#include "ppapi/cpp/instance.h" #include "ppapi/cpp/instance.h"
#include "ppapi/cpp/private/find_private.h" #include "ppapi/cpp/private/find_private.h"
#include "ppapi/cpp/url_loader.h" #include "ppapi/cpp/url_loader.h"
#include "ppapi/utility/completion_callback_factory.h"
#include "third_party/skia/include/core/SkBitmap.h" #include "third_party/skia/include/core/SkBitmap.h"
namespace gfx { namespace gfx {
...@@ -423,8 +423,6 @@ class OutOfProcessInstance : public PdfViewPluginBase, ...@@ -423,8 +423,6 @@ class OutOfProcessInstance : public PdfViewPluginBase,
// Used for submitting forms. // Used for submitting forms.
pp::URLLoader form_loader_; pp::URLLoader form_loader_;
pp::CompletionCallbackFactory<OutOfProcessInstance> callback_factory_;
// The callback for receiving the password from the page. // The callback for receiving the password from the page.
base::OnceCallback<void(const std::string&)> password_callback_; base::OnceCallback<void(const std::string&)> password_callback_;
...@@ -504,6 +502,8 @@ class OutOfProcessInstance : public PdfViewPluginBase, ...@@ -504,6 +502,8 @@ class OutOfProcessInstance : public PdfViewPluginBase,
ACCESSIBILITY_STATE_PENDING, // Enabled but waiting for doc to load. ACCESSIBILITY_STATE_PENDING, // Enabled but waiting for doc to load.
ACCESSIBILITY_STATE_LOADED ACCESSIBILITY_STATE_LOADED
} accessibility_state_ = ACCESSIBILITY_STATE_OFF; } accessibility_state_ = ACCESSIBILITY_STATE_OFF;
base::WeakPtrFactory<OutOfProcessInstance> weak_factory_{this};
}; };
} // namespace chrome_pdf } // namespace chrome_pdf
......
...@@ -445,8 +445,6 @@ PDFiumEngine::PDFiumEngine(PDFEngine::Client* client, bool enable_javascript) ...@@ -445,8 +445,6 @@ PDFiumEngine::PDFiumEngine(PDFEngine::Client* client, bool enable_javascript)
if (enable_javascript) if (enable_javascript)
DCHECK(IsV8Initialized()); DCHECK(IsV8Initialized());
find_factory_.Initialize(this);
IFSDK_PAUSE::version = 1; IFSDK_PAUSE::version = 1;
IFSDK_PAUSE::user = nullptr; IFSDK_PAUSE::user = nullptr;
IFSDK_PAUSE::NeedToPauseNow = Pause_NeedToPauseNow; IFSDK_PAUSE::NeedToPauseNow = Pause_NeedToPauseNow;
...@@ -1709,10 +1707,11 @@ void PDFiumEngine::StartFind(const std::string& text, bool case_sensitive) { ...@@ -1709,10 +1707,11 @@ void PDFiumEngine::StartFind(const std::string& text, bool case_sensitive) {
if (doc_loader_set_for_testing_) { if (doc_loader_set_for_testing_) {
ContinueFind(case_sensitive ? 1 : 0); ContinueFind(case_sensitive ? 1 : 0);
} else { } else {
pp::CompletionCallback callback = pp::Module::Get()->core()->CallOnMainThread(
find_factory_.NewCallback(&PDFiumEngine::ContinueFind); 0,
pp::Module::Get()->core()->CallOnMainThread(0, callback, PPCompletionCallbackFromResultCallback(base::BindOnce(
case_sensitive ? 1 : 0); &PDFiumEngine::ContinueFind, find_weak_factory_.GetWeakPtr())),
case_sensitive ? 1 : 0);
} }
} }
...@@ -1977,7 +1976,7 @@ void PDFiumEngine::StopFind() { ...@@ -1977,7 +1976,7 @@ void PDFiumEngine::StopFind() {
current_find_text_.clear(); current_find_text_.clear();
UpdateTickMarks(); UpdateTickMarks();
find_factory_.CancelAll(); find_weak_factory_.InvalidateWeakPtrs();
} }
std::vector<pp::Rect> PDFiumEngine::GetAllScreenRectsUnion( std::vector<pp::Rect> PDFiumEngine::GetAllScreenRectsUnion(
......
...@@ -27,13 +27,11 @@ ...@@ -27,13 +27,11 @@
#include "pdf/pdfium/pdfium_print.h" #include "pdf/pdfium/pdfium_print.h"
#include "pdf/pdfium/pdfium_range.h" #include "pdf/pdfium/pdfium_range.h"
#include "ppapi/c/private/ppp_pdf.h" #include "ppapi/c/private/ppp_pdf.h"
#include "ppapi/cpp/completion_callback.h"
#include "ppapi/cpp/dev/buffer_dev.h" #include "ppapi/cpp/dev/buffer_dev.h"
#include "ppapi/cpp/input_event.h" #include "ppapi/cpp/input_event.h"
#include "ppapi/cpp/point.h" #include "ppapi/cpp/point.h"
#include "ppapi/cpp/rect.h" #include "ppapi/cpp/rect.h"
#include "ppapi/cpp/var_array.h" #include "ppapi/cpp/var_array.h"
#include "ppapi/utility/completion_callback_factory.h"
#include "third_party/pdfium/public/cpp/fpdf_scopers.h" #include "third_party/pdfium/public/cpp/fpdf_scopers.h"
#include "third_party/pdfium/public/fpdf_formfill.h" #include "third_party/pdfium/public/fpdf_formfill.h"
#include "third_party/pdfium/public/fpdf_progressive.h" #include "third_party/pdfium/public/fpdf_progressive.h"
...@@ -652,7 +650,6 @@ class PDFiumEngine : public PDFEngine, ...@@ -652,7 +650,6 @@ class PDFiumEngine : public PDFEngine,
bool doc_loader_set_for_testing_ = false; bool doc_loader_set_for_testing_ = false;
std::string url_; std::string url_;
std::string headers_; std::string headers_;
pp::CompletionCallbackFactory<PDFiumEngine> find_factory_;
// Set to true if the user is being prompted for their password. Will be set // Set to true if the user is being prompted for their password. Will be set
// to false after the user finishes getting their password. // to false after the user finishes getting their password.
...@@ -835,6 +832,11 @@ class PDFiumEngine : public PDFEngine, ...@@ -835,6 +832,11 @@ class PDFiumEngine : public PDFEngine,
PDFiumPrint print_; PDFiumPrint print_;
base::WeakPtrFactory<PDFiumEngine> weak_factory_{this}; base::WeakPtrFactory<PDFiumEngine> weak_factory_{this};
// Weak pointers from this factory are used to bind the ContinueFind()
// function. This allows those weak pointers to be invalidated during
// StopFind(), and keeps the invalidation separated from |weak_factory_|.
base::WeakPtrFactory<PDFiumEngine> find_weak_factory_{this};
}; };
} // namespace chrome_pdf } // namespace chrome_pdf
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment