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 @@
#include "base/callback.h"
#include "base/feature_list.h"
#include "base/logging.h"
#include "base/memory/weak_ptr.h"
#include "base/metrics/histogram_functions.h"
#include "base/notreached.h"
#include "base/numerics/ranges.h"
......@@ -460,7 +461,6 @@ OutOfProcessInstance::OutOfProcessInstance(PP_Instance instance)
pp::Find_Private(this),
pp::Printing_Dev(this),
paint_manager_(this) {
callback_factory_.Initialize(this);
pp::Module::Get()->AddPluginInterface(kPPPPdfInterface, &ppp_private);
AddPerInstanceObject(kPPPPdfInterface, this);
......@@ -776,10 +776,12 @@ void OutOfProcessInstance::LoadAccessibility() {
SendAccessibilityViewportInfo();
// Schedule loading the first page.
pp::CompletionCallback callback = callback_factory_.NewCallback(
&OutOfProcessInstance::SendNextAccessibilityPage);
pp::Module::Get()->core()->CallOnMainThread(kAccessibilityPageDelayMs,
callback, 0);
pp::Module::Get()->core()->CallOnMainThread(
kAccessibilityPageDelayMs,
PPCompletionCallbackFromResultCallback(
base::BindOnce(&OutOfProcessInstance::SendNextAccessibilityPage,
weak_factory_.GetWeakPtr())),
0);
}
void OutOfProcessInstance::SendNextAccessibilityPage(int32_t page_index) {
......@@ -797,10 +799,12 @@ void OutOfProcessInstance::SendNextAccessibilityPage(int32_t page_index) {
chars, page_objects);
// Schedule loading the next page.
pp::CompletionCallback callback = callback_factory_.NewCallback(
&OutOfProcessInstance::SendNextAccessibilityPage);
pp::Module::Get()->core()->CallOnMainThread(kAccessibilityPageDelayMs,
callback, page_index + 1);
pp::Module::Get()->core()->CallOnMainThread(
kAccessibilityPageDelayMs,
PPCompletionCallbackFromResultCallback(
base::BindOnce(&OutOfProcessInstance::SendNextAccessibilityPage,
weak_factory_.GetWeakPtr())),
page_index + 1);
}
void OutOfProcessInstance::SendAccessibilityViewportInfo() {
......@@ -1058,9 +1062,10 @@ void OutOfProcessInstance::OnPaint(const std::vector<gfx::Rect>& paint_rects,
engine()->PostPaint();
if (!deferred_invalidates_.empty()) {
pp::CompletionCallback callback = callback_factory_.NewCallback(
&OutOfProcessInstance::InvalidateAfterPaintDone);
pp::Module::Get()->core()->CallOnMainThread(0, callback);
pp::Module::Get()->core()->CallOnMainThread(
0, PPCompletionCallbackFromResultCallback(
base::BindOnce(&OutOfProcessInstance::InvalidateAfterPaintDone,
weak_factory_.GetWeakPtr())));
}
}
......@@ -1274,10 +1279,12 @@ void OutOfProcessInstance::NotifyNumberOfFindResultsChanged(int total,
NumberOfFindResultsChanged(total, final_result);
SetTickmarks(tickmarks_);
recently_sent_find_update_ = true;
pp::CompletionCallback callback = callback_factory_.NewCallback(
&OutOfProcessInstance::ResetRecentlySentFindUpdate);
pp::Module::Get()->core()->CallOnMainThread(kFindResultCooldownMs, callback,
0);
pp::Module::Get()->core()->CallOnMainThread(
kFindResultCooldownMs,
PPCompletionCallbackFromResultCallback(
base::BindOnce(&OutOfProcessInstance::ResetRecentlySentFindUpdate,
weak_factory_.GetWeakPtr())),
0);
}
void OutOfProcessInstance::NotifySelectedFindResultChanged(
......@@ -1413,9 +1420,9 @@ void OutOfProcessInstance::Print() {
return;
}
pp::CompletionCallback callback =
callback_factory_.NewCallback(&OutOfProcessInstance::OnPrint);
pp::Module::Get()->core()->CallOnMainThread(0, callback);
pp::Module::Get()->core()->CallOnMainThread(
0, PPCompletionCallbackFromResultCallback(base::BindOnce(
&OutOfProcessInstance::OnPrint, weak_factory_.GetWeakPtr())));
}
void OutOfProcessInstance::SubmitForm(const std::string& url,
......@@ -1426,9 +1433,10 @@ void OutOfProcessInstance::SubmitForm(const std::string& url,
request.SetMethod("POST");
request.AppendDataToBody(reinterpret_cast<const char*>(data), length);
pp::CompletionCallback callback =
callback_factory_.NewCallback(&OutOfProcessInstance::FormDidOpen);
form_loader_ = CreateURLLoaderInternal();
pp::CompletionCallback callback =
PPCompletionCallbackFromResultCallback(base::BindOnce(
&OutOfProcessInstance::FormDidOpen, weak_factory_.GetWeakPtr()));
int rv = form_loader_.Open(request, callback);
if (rv != PP_OK_COMPLETIONPENDING)
callback.Run(rv);
......@@ -2020,9 +2028,10 @@ void OutOfProcessInstance::LoadUrl(const std::string& url,
pp::URLLoader* loader =
is_print_preview ? &embed_preview_loader_ : &embed_loader_;
*loader = CreateURLLoaderInternal();
pp::CompletionCallback callback = callback_factory_.NewCallback(
is_print_preview ? &OutOfProcessInstance::DidOpenPreview
: &OutOfProcessInstance::DidOpen);
pp::CompletionCallback callback = PPCompletionCallbackFromResultCallback(
base::BindOnce(is_print_preview ? &OutOfProcessInstance::DidOpenPreview
: &OutOfProcessInstance::DidOpen,
weak_factory_.GetWeakPtr()));
int rv = loader->Open(request, callback);
if (rv != PP_OK_COMPLETIONPENDING)
callback.Run(rv);
......
......@@ -16,6 +16,7 @@
#include "base/callback.h"
#include "base/containers/queue.h"
#include "base/memory/weak_ptr.h"
#include "pdf/paint_manager.h"
#include "pdf/pdf_view_plugin_base.h"
#include "pdf/preview_mode_client.h"
......@@ -25,7 +26,6 @@
#include "ppapi/cpp/instance.h"
#include "ppapi/cpp/private/find_private.h"
#include "ppapi/cpp/url_loader.h"
#include "ppapi/utility/completion_callback_factory.h"
#include "third_party/skia/include/core/SkBitmap.h"
namespace gfx {
......@@ -423,8 +423,6 @@ class OutOfProcessInstance : public PdfViewPluginBase,
// Used for submitting forms.
pp::URLLoader form_loader_;
pp::CompletionCallbackFactory<OutOfProcessInstance> callback_factory_;
// The callback for receiving the password from the page.
base::OnceCallback<void(const std::string&)> password_callback_;
......@@ -504,6 +502,8 @@ class OutOfProcessInstance : public PdfViewPluginBase,
ACCESSIBILITY_STATE_PENDING, // Enabled but waiting for doc to load.
ACCESSIBILITY_STATE_LOADED
} accessibility_state_ = ACCESSIBILITY_STATE_OFF;
base::WeakPtrFactory<OutOfProcessInstance> weak_factory_{this};
};
} // namespace chrome_pdf
......
......@@ -445,8 +445,6 @@ PDFiumEngine::PDFiumEngine(PDFEngine::Client* client, bool enable_javascript)
if (enable_javascript)
DCHECK(IsV8Initialized());
find_factory_.Initialize(this);
IFSDK_PAUSE::version = 1;
IFSDK_PAUSE::user = nullptr;
IFSDK_PAUSE::NeedToPauseNow = Pause_NeedToPauseNow;
......@@ -1709,10 +1707,11 @@ void PDFiumEngine::StartFind(const std::string& text, bool case_sensitive) {
if (doc_loader_set_for_testing_) {
ContinueFind(case_sensitive ? 1 : 0);
} else {
pp::CompletionCallback callback =
find_factory_.NewCallback(&PDFiumEngine::ContinueFind);
pp::Module::Get()->core()->CallOnMainThread(0, callback,
case_sensitive ? 1 : 0);
pp::Module::Get()->core()->CallOnMainThread(
0,
PPCompletionCallbackFromResultCallback(base::BindOnce(
&PDFiumEngine::ContinueFind, find_weak_factory_.GetWeakPtr())),
case_sensitive ? 1 : 0);
}
}
......@@ -1977,7 +1976,7 @@ void PDFiumEngine::StopFind() {
current_find_text_.clear();
UpdateTickMarks();
find_factory_.CancelAll();
find_weak_factory_.InvalidateWeakPtrs();
}
std::vector<pp::Rect> PDFiumEngine::GetAllScreenRectsUnion(
......
......@@ -27,13 +27,11 @@
#include "pdf/pdfium/pdfium_print.h"
#include "pdf/pdfium/pdfium_range.h"
#include "ppapi/c/private/ppp_pdf.h"
#include "ppapi/cpp/completion_callback.h"
#include "ppapi/cpp/dev/buffer_dev.h"
#include "ppapi/cpp/input_event.h"
#include "ppapi/cpp/point.h"
#include "ppapi/cpp/rect.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/fpdf_formfill.h"
#include "third_party/pdfium/public/fpdf_progressive.h"
......@@ -652,7 +650,6 @@ class PDFiumEngine : public PDFEngine,
bool doc_loader_set_for_testing_ = false;
std::string url_;
std::string headers_;
pp::CompletionCallbackFactory<PDFiumEngine> find_factory_;
// Set to true if the user is being prompted for their password. Will be set
// to false after the user finishes getting their password.
......@@ -835,6 +832,11 @@ class PDFiumEngine : public PDFEngine,
PDFiumPrint print_;
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
......
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