Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2821)

Unified Diff: chrome/browser/chromeos/policy/policy_cert_verifier.cc

Issue 24153012: Fix cyclic dependency between ProfilePolicyConnector and PrefService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed another bug for OTRProfile. Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/policy/policy_cert_verifier.cc
diff --git a/chrome/browser/chromeos/policy/policy_cert_verifier.cc b/chrome/browser/chromeos/policy/policy_cert_verifier.cc
index 307cdd01bad7994d548531f6a850171a8bd808d1..8f79bec1497fb2d527107270d949e63f0917c3ef 100644
--- a/chrome/browser/chromeos/policy/policy_cert_verifier.cc
+++ b/chrome/browser/chromeos/policy/policy_cert_verifier.cc
@@ -5,7 +5,6 @@
#include "chrome/browser/chromeos/policy/policy_cert_verifier.h"
#include "base/logging.h"
-#include "base/memory/ref_counted.h"
#include "chrome/browser/browser_process.h"
#include "content/public/browser/browser_thread.h"
#include "net/base/net_errors.h"
@@ -14,40 +13,18 @@
namespace policy {
-namespace {
-
-void MaybeSignalAnchorUse(int error,
- const base::Closure& anchor_used_callback,
- const net::CertVerifyResult& verify_result) {
- DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
- if (error != net::OK || !verify_result.is_issued_by_additional_trust_anchor ||
- anchor_used_callback.is_null()) {
- return;
- }
- anchor_used_callback.Run();
-}
-
-void CompleteAndSignalAnchorUse(
- const base::Closure& anchor_used_callback,
- const net::CompletionCallback& completion_callback,
- const net::CertVerifyResult* verify_result,
- int error) {
- DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
- MaybeSignalAnchorUse(error, anchor_used_callback, *verify_result);
- if (!completion_callback.is_null())
- completion_callback.Run(error);
-}
-
-} // namespace
-
PolicyCertVerifier::PolicyCertVerifier(
const base::Closure& anchor_used_callback)
- : anchor_used_callback_(anchor_used_callback) {
+ : anchor_used_callback_(anchor_used_callback),
+ weak_ptr_factory_(this),
+ weak_ptr_(weak_ptr_factory_.GetWeakPtr()) {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
}
PolicyCertVerifier::~PolicyCertVerifier() {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
+ DCHECK(!weak_ptr_factory_.HasWeakPtrs())
+ << "UnsetTrustAnchorUsedCallback must be called before d'tor. " << this;
}
void PolicyCertVerifier::InitializeOnIOThread() {
@@ -56,7 +33,7 @@ void PolicyCertVerifier::InitializeOnIOThread() {
net::CertVerifyProc::CreateDefault();
if (!verify_proc->SupportsAdditionalTrustAnchors()) {
LOG(WARNING)
- << "Additional trust anchors not supported in the current platform!";
+ << "Additional trust anchors not supported on the current platform!";
}
net::MultiThreadedCertVerifier* verifier =
new net::MultiThreadedCertVerifier(verify_proc.get());
@@ -64,6 +41,12 @@ void PolicyCertVerifier::InitializeOnIOThread() {
delegate_.reset(verifier);
}
+void PolicyCertVerifier::UnsetTrustAnchorUsedCallback() {
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
+ anchor_used_callback_.Reset();
+ weak_ptr_factory_.InvalidateWeakPtrs();
+}
+
void PolicyCertVerifier::SetTrustAnchors(
const net::CertificateList& trust_anchors) {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
@@ -82,13 +65,13 @@ int PolicyCertVerifier::Verify(
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
DCHECK(delegate_);
net::CompletionCallback wrapped_callback =
- base::Bind(&CompleteAndSignalAnchorUse,
- anchor_used_callback_,
+ base::Bind(&PolicyCertVerifier::CompleteAndSignalAnchorUse,
completion_callback,
- verify_result);
+ verify_result,
+ weak_ptr_);
int error = delegate_->Verify(cert, hostname, flags, crl_set, verify_result,
wrapped_callback, out_req, net_log);
- MaybeSignalAnchorUse(error, anchor_used_callback_, *verify_result);
+ MaybeSignalAnchorUse(error, *verify_result, weak_ptr_);
return error;
}
@@ -102,4 +85,37 @@ const net::CertificateList& PolicyCertVerifier::GetAdditionalTrustAnchors() {
return trust_anchors_;
}
+void PolicyCertVerifier::NotifyOnUI() {
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
+ if (!anchor_used_callback_.is_null())
+ anchor_used_callback_.Run();
+}
+
+// static
+void PolicyCertVerifier::MaybeSignalAnchorUse(
+ int error,
+ const net::CertVerifyResult& verify_result,
+ const base::WeakPtr<PolicyCertVerifier>& weak_ptr) {
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
+ if (error != net::OK || !verify_result.is_issued_by_additional_trust_anchor)
+ return;
+
+ content::BrowserThread::PostTask(
+ content::BrowserThread::UI,
+ FROM_HERE,
+ base::Bind(&PolicyCertVerifier::NotifyOnUI, weak_ptr));
+}
+
+// static
+void PolicyCertVerifier::CompleteAndSignalAnchorUse(
+ const net::CompletionCallback& completion_callback,
+ const net::CertVerifyResult* verify_result,
+ const base::WeakPtr<PolicyCertVerifier>& weak_ptr,
+ int error) {
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
+ MaybeSignalAnchorUse(error, *verify_result, weak_ptr);
+ if (!completion_callback.is_null())
+ completion_callback.Run(error);
+}
+
} // namespace policy

Powered by Google App Engine
This is Rietveld 408576698