derefence weak ptr only on the same sequence runner it was created in
This commit is contained in:
parent
fedf1d889b
commit
a518c5c3c4
3 changed files with 43 additions and 50 deletions
|
@ -21,6 +21,32 @@
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
// Generate default file path to save the download.
|
||||||
|
void CreateDownloadPath(
|
||||||
|
const GURL& url,
|
||||||
|
const std::string& content_disposition,
|
||||||
|
const std::string& suggested_filename,
|
||||||
|
const std::string& mime_type,
|
||||||
|
const base::FilePath& default_download_path,
|
||||||
|
const AtomDownloadManagerDelegate::CreateDownloadPathCallback& callback) {
|
||||||
|
DCHECK_CURRENTLY_ON(content::BrowserThread::FILE);
|
||||||
|
|
||||||
|
auto generated_name =
|
||||||
|
net::GenerateFileName(url, content_disposition, std::string(),
|
||||||
|
suggested_filename, mime_type, "download");
|
||||||
|
|
||||||
|
if (!base::PathExists(default_download_path))
|
||||||
|
base::CreateDirectory(default_download_path);
|
||||||
|
|
||||||
|
base::FilePath path(default_download_path.Append(generated_name));
|
||||||
|
content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
|
||||||
|
base::Bind(callback, path));
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
AtomDownloadManagerDelegate::AtomDownloadManagerDelegate(
|
AtomDownloadManagerDelegate::AtomDownloadManagerDelegate(
|
||||||
content::DownloadManager* manager)
|
content::DownloadManager* manager)
|
||||||
: download_manager_(manager),
|
: download_manager_(manager),
|
||||||
|
@ -46,30 +72,6 @@ void AtomDownloadManagerDelegate::GetItemSavePath(content::DownloadItem* item,
|
||||||
*path = download->GetSavePath();
|
*path = download->GetSavePath();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AtomDownloadManagerDelegate::CreateDownloadPath(
|
|
||||||
const GURL& url,
|
|
||||||
const std::string& content_disposition,
|
|
||||||
const std::string& suggested_filename,
|
|
||||||
const std::string& mime_type,
|
|
||||||
const base::FilePath& default_download_path,
|
|
||||||
const CreateDownloadPathCallback& callback) {
|
|
||||||
DCHECK_CURRENTLY_ON(content::BrowserThread::FILE);
|
|
||||||
|
|
||||||
auto generated_name = net::GenerateFileName(url,
|
|
||||||
content_disposition,
|
|
||||||
std::string(),
|
|
||||||
suggested_filename,
|
|
||||||
mime_type,
|
|
||||||
"download");
|
|
||||||
|
|
||||||
if (!base::PathExists(default_download_path))
|
|
||||||
base::CreateDirectory(default_download_path);
|
|
||||||
|
|
||||||
base::FilePath path(default_download_path.Append(generated_name));
|
|
||||||
content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
|
|
||||||
base::Bind(callback, path));
|
|
||||||
}
|
|
||||||
|
|
||||||
void AtomDownloadManagerDelegate::OnDownloadPathGenerated(
|
void AtomDownloadManagerDelegate::OnDownloadPathGenerated(
|
||||||
uint32_t download_id,
|
uint32_t download_id,
|
||||||
const content::DownloadTargetCallback& callback,
|
const content::DownloadTargetCallback& callback,
|
||||||
|
@ -164,14 +166,10 @@ bool AtomDownloadManagerDelegate::DetermineDownloadTarget(
|
||||||
|
|
||||||
content::BrowserThread::PostTask(
|
content::BrowserThread::PostTask(
|
||||||
content::BrowserThread::FILE, FROM_HERE,
|
content::BrowserThread::FILE, FROM_HERE,
|
||||||
base::Bind(&AtomDownloadManagerDelegate::CreateDownloadPath,
|
base::Bind(&CreateDownloadPath, download->GetURL(),
|
||||||
weak_ptr_factory_.GetWeakPtr(),
|
|
||||||
download->GetURL(),
|
|
||||||
download->GetContentDisposition(),
|
download->GetContentDisposition(),
|
||||||
download->GetSuggestedFilename(),
|
download->GetSuggestedFilename(), download->GetMimeType(),
|
||||||
download->GetMimeType(),
|
default_download_path, download_path_callback));
|
||||||
default_download_path,
|
|
||||||
download_path_callback));
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,13 +24,6 @@ class AtomDownloadManagerDelegate : public content::DownloadManagerDelegate {
|
||||||
explicit AtomDownloadManagerDelegate(content::DownloadManager* manager);
|
explicit AtomDownloadManagerDelegate(content::DownloadManager* manager);
|
||||||
virtual ~AtomDownloadManagerDelegate();
|
virtual ~AtomDownloadManagerDelegate();
|
||||||
|
|
||||||
// Generate default file path to save the download.
|
|
||||||
void CreateDownloadPath(const GURL& url,
|
|
||||||
const std::string& suggested_filename,
|
|
||||||
const std::string& content_disposition,
|
|
||||||
const std::string& mime_type,
|
|
||||||
const base::FilePath& path,
|
|
||||||
const CreateDownloadPathCallback& callback);
|
|
||||||
void OnDownloadPathGenerated(uint32_t download_id,
|
void OnDownloadPathGenerated(uint32_t download_id,
|
||||||
const content::DownloadTargetCallback& callback,
|
const content::DownloadTargetCallback& callback,
|
||||||
const base::FilePath& default_path);
|
const base::FilePath& default_path);
|
||||||
|
|
|
@ -94,25 +94,27 @@ class CertVerifierRequest : public AtomCertVerifier::Request {
|
||||||
request->default_result = net::ErrorToString(error);
|
request->default_result = net::ErrorToString(error);
|
||||||
request->error_code = error;
|
request->error_code = error;
|
||||||
request->certificate = params_.certificate();
|
request->certificate = params_.certificate();
|
||||||
|
auto response_callback = base::Bind(&CertVerifierRequest::OnResponseInUI,
|
||||||
|
weak_ptr_factory_.GetWeakPtr());
|
||||||
BrowserThread::PostTask(
|
BrowserThread::PostTask(
|
||||||
BrowserThread::UI, FROM_HERE,
|
BrowserThread::UI, FROM_HERE,
|
||||||
base::Bind(&CertVerifierRequest::OnVerifyRequestInUI,
|
base::Bind(&CertVerifierRequest::OnVerifyRequestInUI,
|
||||||
weak_ptr_factory_.GetWeakPtr(),
|
cert_verifier_->verify_proc(), base::Passed(&request),
|
||||||
cert_verifier_->verify_proc(),
|
response_callback));
|
||||||
base::Passed(&request)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnVerifyRequestInUI(const AtomCertVerifier::VerifyProc& verify_proc,
|
static void OnVerifyRequestInUI(
|
||||||
std::unique_ptr<VerifyRequestParams> request) {
|
const AtomCertVerifier::VerifyProc& verify_proc,
|
||||||
verify_proc.Run(*(request.get()),
|
std::unique_ptr<VerifyRequestParams> request,
|
||||||
base::Bind(&CertVerifierRequest::OnResponseInUI,
|
const base::Callback<void(int)>& response_callback) {
|
||||||
weak_ptr_factory_.GetWeakPtr()));
|
verify_proc.Run(*(request.get()), response_callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnResponseInUI(int result) {
|
static void OnResponseInUI(base::WeakPtr<CertVerifierRequest> self,
|
||||||
BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
|
int result) {
|
||||||
base::Bind(&CertVerifierRequest::NotifyResponseInIO,
|
BrowserThread::PostTask(
|
||||||
weak_ptr_factory_.GetWeakPtr(), result));
|
BrowserThread::IO, FROM_HERE,
|
||||||
|
base::Bind(&CertVerifierRequest::NotifyResponseInIO, self, result));
|
||||||
}
|
}
|
||||||
|
|
||||||
void NotifyResponseInIO(int result) {
|
void NotifyResponseInIO(int result) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue