+ // |done_callback| must only be called as long as |this| still exists.
+ // Thereforce, call back to |this|. This check of |this| must happen last and
+ // on the origin thread.
+ DoneCallback callback_to_this =
+ base::Bind(&CertificateImporterImpl::RunDoneCallback,
+ weak_factory_.GetWeakPtr(),
+ done_callback);
+
+ // |done_callback| must be called on the origin thread.
+ DoneCallback callback_on_origin_loop =
+ base::Bind(&CallBackOnOriginLoop,
+ base::ThreadTaskRunnerHandle::Get(),
+ callback_to_this);
+
+ // This is the actual function that imports the certificates.
+ base::Closure import_certs_callback =
+ base::Bind(&ParseAndStoreCertificates,
+ source,
+ callback_on_origin_loop,
+ base::Owned(certificates.DeepCopy()),
+ target_nssdb_);
+
+ // The NSSCertDatabase must be accessed on |io_task_runner_|
+ io_task_runner_->PostTask(FROM_HERE, import_certs_callback);
+}