Skip to content

Commit

Permalink
Migrate //android_webview to OnceCallback
Browse files Browse the repository at this point in the history
This updates //android_webview to use base::OnceCallback instead of
legacy base::Callback. No intended functional change is included.

Bug: 714018
Change-Id: I4897aca2dcac09e0c67675416e6d9d20f8ed017b
Reviewed-on: https://chromium-review.googlesource.com/961750
Reviewed-by: Bo <boliu@chromium.org>
Reviewed-by: Tao Bai <michaelbai@chromium.org>
Commit-Queue: Taiju Tsuiki <tzik@chromium.org>
Cr-Commit-Position: refs/heads/master@{#545354}
  • Loading branch information
tzik authored and Commit Bot committed Mar 23, 2018
1 parent 290d821 commit b57fcc4
Show file tree
Hide file tree
Showing 54 changed files with 409 additions and 377 deletions.
7 changes: 4 additions & 3 deletions android_webview/browser/aw_browser_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ void AwBrowserContext::PreMainMessageLoopRun(net::NetLog* net_log) {
new web_restrictions::WebRestrictionsClient());
pref_change_registrar_.Add(
prefs::kWebRestrictionsAuthority,
base::Bind(&AwBrowserContext::OnWebRestrictionsAuthorityChanged,
base::Unretained(this)));
base::BindRepeating(&AwBrowserContext::OnWebRestrictionsAuthorityChanged,
base::Unretained(this)));
web_restriction_provider_->SetAuthority(
user_pref_service_->GetString(prefs::kWebRestrictionsAuthority));

Expand Down Expand Up @@ -237,7 +237,8 @@ void AwBrowserContext::InitUserPrefService() {
browser_policy_connector_->GetPolicyService(),
browser_policy_connector_->GetHandlerList(),
policy::POLICY_LEVEL_MANDATORY));
pref_service_factory.set_read_error_callback(base::Bind(&HandleReadError));
pref_service_factory.set_read_error_callback(
base::BindRepeating(&HandleReadError));
user_pref_service_ = pref_service_factory.Create(pref_registry);
pref_change_registrar_.Init(user_pref_service_.get());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,20 @@ class AwBrowserPermissionRequestDelegate {

virtual void RequestProtectedMediaIdentifierPermission(
const GURL& origin,
const base::Callback<void(bool)>& callback) = 0;
base::OnceCallback<void(bool)> callback) = 0;

virtual void CancelProtectedMediaIdentifierPermissionRequests(
const GURL& origin) = 0;

virtual void RequestGeolocationPermission(
const GURL& origin,
const base::Callback<void(bool)>& callback) = 0;
base::OnceCallback<void(bool)> callback) = 0;

virtual void CancelGeolocationPermissionRequests(const GURL& origin) = 0;

virtual void RequestMIDISysexPermission(
const GURL& origin,
const base::Callback<void(bool)>& callback) = 0;
base::OnceCallback<void(bool)> callback) = 0;

virtual void CancelMIDISysexPermissionRequests(const GURL& origin) = 0;

Expand Down
6 changes: 3 additions & 3 deletions android_webview/browser/aw_browser_policy_connector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ std::unique_ptr<policy::ConfigurationPolicyHandlerList> BuildHandlerList(
const policy::Schema& chrome_schema) {
std::unique_ptr<policy::ConfigurationPolicyHandlerList> handlers(
new policy::ConfigurationPolicyHandlerList(
base::Bind(&PopulatePolicyHandlerParameters),
base::Bind(&GetChromePolicyDetails)));
base::BindRepeating(&PopulatePolicyHandlerParameters),
base::BindRepeating(&GetChromePolicyDetails)));

// URL Filtering
handlers->AddHandler(std::make_unique<policy::SimplePolicyHandler>(
Expand All @@ -62,7 +62,7 @@ std::unique_ptr<policy::ConfigurationPolicyHandlerList> BuildHandlerList(
} // namespace

AwBrowserPolicyConnector::AwBrowserPolicyConnector()
: BrowserPolicyConnectorBase(base::Bind(&BuildHandlerList)) {}
: BrowserPolicyConnectorBase(base::BindRepeating(&BuildHandlerList)) {}

AwBrowserPolicyConnector::~AwBrowserPolicyConnector() = default;

Expand Down
12 changes: 6 additions & 6 deletions android_webview/browser/aw_browser_terminator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@ void AwBrowserTerminator::OnChildExitAsync(
crashed = true;
}

BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
base::Bind(&OnRenderProcessGoneDetail, process_host_id, pid, crashed));
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
base::BindOnce(&OnRenderProcessGoneDetail,
process_host_id, pid, crashed));
}

void AwBrowserTerminator::OnChildExit(
Expand Down Expand Up @@ -191,9 +191,9 @@ void AwBrowserTerminator::OnChildExit(
FROM_HERE,
{base::MayBlock(), base::TaskPriority::USER_VISIBLE,
base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN},
base::Bind(&AwBrowserTerminator::OnChildExitAsync, process_host_id, pid,
process_type, termination_status, app_state, crash_dump_dir_,
base::Passed(std::move(pipe))));
base::BindOnce(&AwBrowserTerminator::OnChildExitAsync, process_host_id,
pid, process_type, termination_status, app_state,
crash_dump_dir_, std::move(pipe)));
}

} // namespace android_webview
11 changes: 6 additions & 5 deletions android_webview/browser/aw_content_browser_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,14 @@ AwBrowserContext* AwContentBrowserClient::GetAwBrowserContext() {
}

AwContentBrowserClient::AwContentBrowserClient() : net_log_(new net::NetLog()) {
frame_interfaces_.AddInterface(
base::Bind(&autofill::ContentAutofillDriverFactory::BindAutofillDriver));
frame_interfaces_.AddInterface(base::BindRepeating(
&autofill::ContentAutofillDriverFactory::BindAutofillDriver));
// Although WebView does not support password manager feature, renderer code
// could still request this interface, so we register a dummy binder which
// just drops the incoming request, to avoid the 'Failed to locate a binder
// for interface' error log..
frame_interfaces_.AddInterface(base::Bind(&DummyBindPasswordManagerDriver));
frame_interfaces_.AddInterface(
base::BindRepeating(&DummyBindPasswordManagerDriver));
sniff_file_urls_ = AwSettings::GetAllowSniffingFileUrls();
}

Expand Down Expand Up @@ -569,10 +570,10 @@ void AwContentBrowserClient::ExposeInterfacesToRenderer(
content::ResourceContext* resource_context =
render_process_host->GetBrowserContext()->GetResourceContext();
registry->AddInterface(
base::Bind(
base::BindRepeating(
&safe_browsing::MojoSafeBrowsingImpl::MaybeCreate,
render_process_host->GetID(), resource_context,
base::Bind(
base::BindRepeating(
&AwContentBrowserClient::GetSafeBrowsingUrlCheckerDelegate,
base::Unretained(this))),
BrowserThread::GetTaskRunnerForThread(BrowserThread::IO));
Expand Down
27 changes: 14 additions & 13 deletions android_webview/browser/aw_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ void AwContents::DocumentHasImages(JNIEnv* env,
ScopedJavaGlobalRef<jobject> j_message;
j_message.Reset(env, message);
render_view_host_ext_->DocumentHasImages(
base::Bind(&DocumentHasImagesCallback, j_message));
base::BindOnce(&DocumentHasImagesCallback, j_message));
}

namespace {
Expand Down Expand Up @@ -573,19 +573,20 @@ void ShowGeolocationPromptHelper(const JavaObjectWeakGlobalRef& java_ref,
if (java_ref.get(env).obj()) {
content::BrowserThread::PostTask(
content::BrowserThread::UI, FROM_HERE,
base::Bind(&ShowGeolocationPromptHelperTask, java_ref, origin));
base::BindOnce(&ShowGeolocationPromptHelperTask, java_ref, origin));
}
}

} // anonymous namespace

void AwContents::ShowGeolocationPrompt(const GURL& requesting_frame,
base::Callback<void(bool)> callback) {
void AwContents::ShowGeolocationPrompt(
const GURL& requesting_frame,
base::OnceCallback<void(bool)> callback) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);

GURL origin = requesting_frame.GetOrigin();
bool show_prompt = pending_geolocation_prompts_.empty();
pending_geolocation_prompts_.push_back(OriginCallback(origin, callback));
pending_geolocation_prompts_.emplace_back(origin, std::move(callback));
if (show_prompt) {
ShowGeolocationPromptHelper(java_ref_, origin);
}
Expand All @@ -604,7 +605,7 @@ void AwContents::InvokeGeolocationCallback(
GURL callback_origin(base::android::ConvertJavaStringToUTF16(env, origin));
if (callback_origin.GetOrigin() ==
pending_geolocation_prompts_.front().first) {
pending_geolocation_prompts_.front().second.Run(value);
std::move(pending_geolocation_prompts_.front().second).Run(value);
pending_geolocation_prompts_.pop_front();
if (!pending_geolocation_prompts_.empty()) {
ShowGeolocationPromptHelper(java_ref_,
Expand Down Expand Up @@ -680,10 +681,10 @@ void AwContents::PreauthorizePermission(JNIEnv* env,

void AwContents::RequestProtectedMediaIdentifierPermission(
const GURL& origin,
const base::Callback<void(bool)>& callback) {
base::OnceCallback<void(bool)> callback) {
permission_request_handler_->SendRequest(
std::unique_ptr<AwPermissionRequestDelegate>(new SimplePermissionRequest(
origin, AwPermissionRequest::ProtectedMediaId, callback)));
origin, AwPermissionRequest::ProtectedMediaId, std::move(callback))));
}

void AwContents::CancelProtectedMediaIdentifierPermissionRequests(
Expand All @@ -694,19 +695,19 @@ void AwContents::CancelProtectedMediaIdentifierPermissionRequests(

void AwContents::RequestGeolocationPermission(
const GURL& origin,
const base::Callback<void(bool)>& callback) {
base::OnceCallback<void(bool)> callback) {
JNIEnv* env = AttachCurrentThread();
ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
if (obj.is_null())
return;

if (Java_AwContents_useLegacyGeolocationPermissionAPI(env, obj)) {
ShowGeolocationPrompt(origin, callback);
ShowGeolocationPrompt(origin, std::move(callback));
return;
}
permission_request_handler_->SendRequest(
std::unique_ptr<AwPermissionRequestDelegate>(new SimplePermissionRequest(
origin, AwPermissionRequest::Geolocation, callback)));
origin, AwPermissionRequest::Geolocation, std::move(callback))));
}

void AwContents::CancelGeolocationPermissionRequests(const GURL& origin) {
Expand All @@ -725,10 +726,10 @@ void AwContents::CancelGeolocationPermissionRequests(const GURL& origin) {

void AwContents::RequestMIDISysexPermission(
const GURL& origin,
const base::Callback<void(bool)>& callback) {
base::OnceCallback<void(bool)> callback) {
permission_request_handler_->SendRequest(
std::unique_ptr<AwPermissionRequestDelegate>(new SimplePermissionRequest(
origin, AwPermissionRequest::MIDISysex, callback)));
origin, AwPermissionRequest::MIDISysex, std::move(callback))));
}

void AwContents::CancelMIDISysexPermissionRequests(const GURL& origin) {
Expand Down
11 changes: 6 additions & 5 deletions android_webview/browser/aw_contents.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,16 +237,16 @@ class AwContents : public FindHelper::Listener,
// AwBrowserPermissionRequestDelegate implementation.
void RequestProtectedMediaIdentifierPermission(
const GURL& origin,
const base::Callback<void(bool)>& callback) override;
base::OnceCallback<void(bool)> callback) override;
void CancelProtectedMediaIdentifierPermissionRequests(
const GURL& origin) override;
void RequestGeolocationPermission(
const GURL& origin,
const base::Callback<void(bool)>& callback) override;
base::OnceCallback<void(bool)> callback) override;
void CancelGeolocationPermissionRequests(const GURL& origin) override;
void RequestMIDISysexPermission(
const GURL& origin,
const base::Callback<void(bool)>& callback) override;
base::OnceCallback<void(bool)> callback) override;
void CancelMIDISysexPermissionRequests(const GURL& origin) override;

// Find-in-page API and related methods.
Expand Down Expand Up @@ -366,7 +366,8 @@ class AwContents : public FindHelper::Listener,
void InitAutofillIfNecessary(bool autocomplete_enabled);

// Geolocation API support
void ShowGeolocationPrompt(const GURL& origin, base::Callback<void(bool)>);
void ShowGeolocationPrompt(const GURL& origin,
base::OnceCallback<void(bool)>);
void HideGeolocationPrompt(const GURL& origin);

void SetDipScaleInternal(float dip_scale);
Expand All @@ -390,7 +391,7 @@ class AwContents : public FindHelper::Listener,
// GURL is supplied by the content layer as requesting frame.
// Callback is supplied by the content layer, and is invoked with the result
// from the permission prompt.
typedef std::pair<const GURL, base::Callback<void(bool)>> OriginCallback;
typedef std::pair<const GURL, base::OnceCallback<void(bool)>> OriginCallback;
// The first element in the list is always the currently pending request.
std::list<OriginCallback> pending_geolocation_prompts_;

Expand Down
24 changes: 12 additions & 12 deletions android_webview/browser/aw_contents_client_bridge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,11 @@ AwContentsClientBridge::~AwContentsClientBridge() {
}
}

void AwContentsClientBridge::AllowCertificateError(
int cert_error,
net::X509Certificate* cert,
const GURL& request_url,
const base::Callback<void(content::CertificateRequestResultType)>& callback,
bool* cancel_request) {
void AwContentsClientBridge::AllowCertificateError(int cert_error,
net::X509Certificate* cert,
const GURL& request_url,
CertErrorCallback callback,
bool* cancel_request) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
JNIEnv* env = AttachCurrentThread();

Expand All @@ -148,7 +147,7 @@ void AwContentsClientBridge::AllowCertificateError(
// We need to add the callback before making the call to java side,
// as it may do a synchronous callback prior to returning.
int request_id = pending_cert_error_callbacks_.Add(
std::make_unique<CertErrorCallback>(callback));
std::make_unique<CertErrorCallback>(std::move(callback)));
*cancel_request = !Java_AwContentsClientBridge_allowCertificateError(
env, obj, cert_error, jcert, jurl, request_id);
// if the request is cancelled, then cancel the stored callback
Expand All @@ -167,8 +166,9 @@ void AwContentsClientBridge::ProceedSslError(JNIEnv* env,
LOG(WARNING) << "Ignoring unexpected ssl error proceed callback";
return;
}
callback->Run(proceed ? content::CERTIFICATE_REQUEST_RESULT_TYPE_CONTINUE
: content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL);
std::move(*callback).Run(
proceed ? content::CERTIFICATE_REQUEST_RESULT_TYPE_CONTINUE
: content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL);
pending_cert_error_callbacks_.Remove(id);
}

Expand Down Expand Up @@ -453,9 +453,9 @@ void AwContentsClientBridge::OnReceivedError(
void AwContentsClientBridge::OnSafeBrowsingHit(
const AwWebResourceRequest& request,
const safe_browsing::SBThreatType& threat_type,
const SafeBrowsingActionCallback& callback) {
SafeBrowsingActionCallback callback) {
int request_id = safe_browsing_callbacks_.Add(
std::make_unique<SafeBrowsingActionCallback>(callback));
std::make_unique<SafeBrowsingActionCallback>(std::move(callback)));

DCHECK_CURRENTLY_ON(BrowserThread::UI);
JNIEnv* env = AttachCurrentThread();
Expand Down Expand Up @@ -551,7 +551,7 @@ void AwContentsClientBridge::TakeSafeBrowsingAction(JNIEnv*,
LOG(WARNING) << "Unexpected TakeSafeBrowsingAction. " << request_id;
return;
}
callback->Run(
std::move(*callback).Run(
static_cast<AwUrlCheckerDelegateImpl::SafeBrowsingAction>(action),
reporting);
safe_browsing_callbacks_.Remove(request_id);
Expand Down
31 changes: 14 additions & 17 deletions android_webview/browser/aw_contents_client_bridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ namespace android_webview {
// any references.
class AwContentsClientBridge {
public:
using CertErrorCallback =
base::OnceCallback<void(content::CertificateRequestResultType)>;
using SafeBrowsingActionCallback =
base::OnceCallback<void(AwUrlCheckerDelegateImpl::SafeBrowsingAction,
bool)>;

// Adds the handler to the UserData registry.
static void Associate(content::WebContents* web_contents,
AwContentsClientBridge* handler);
Expand All @@ -58,13 +64,11 @@ class AwContentsClientBridge {
~AwContentsClientBridge();

// AwContentsClientBridge implementation
void AllowCertificateError(
int cert_error,
net::X509Certificate* cert,
const GURL& request_url,
const base::Callback<void(content::CertificateRequestResultType)>&
callback,
bool* cancel_request);
void AllowCertificateError(int cert_error,
net::X509Certificate* cert,
const GURL& request_url,
CertErrorCallback callback,
bool* cancel_request);
void SelectClientCertificate(
net::SSLCertRequestInfo* cert_request_info,
std::unique_ptr<content::ClientCertificateDelegate> delegate);
Expand Down Expand Up @@ -100,11 +104,9 @@ class AwContentsClientBridge {
int error_code,
bool safebrowsing_hit);

void OnSafeBrowsingHit(
const AwWebResourceRequest& request,
const safe_browsing::SBThreatType& threat_type,
const base::Callback<void(AwUrlCheckerDelegateImpl::SafeBrowsingAction,
bool)>& callback);
void OnSafeBrowsingHit(const AwWebResourceRequest& request,
const safe_browsing::SBThreatType& threat_type,
SafeBrowsingActionCallback callback);

// Called when a response from the server is received with status code >= 400.
void OnReceivedHttpError(
Expand Down Expand Up @@ -137,11 +139,6 @@ class AwContentsClientBridge {
private:
JavaObjectWeakGlobalRef java_ref_;

typedef const base::Callback<void(content::CertificateRequestResultType)>
CertErrorCallback;
typedef const base::Callback<
void(AwUrlCheckerDelegateImpl::SafeBrowsingAction, bool)>
SafeBrowsingActionCallback;
base::IDMap<std::unique_ptr<CertErrorCallback>> pending_cert_error_callbacks_;
base::IDMap<std::unique_ptr<SafeBrowsingActionCallback>>
safe_browsing_callbacks_;
Expand Down
Loading

0 comments on commit b57fcc4

Please sign in to comment.