Index: chrome/browser/safe_browsing/two_phase_uploader.cc |
diff --git a/chrome/browser/safe_browsing/two_phase_uploader.cc b/chrome/browser/safe_browsing/two_phase_uploader.cc |
index 07fd70a4ee80cf56aaa1087634a8b4b146c7b195..d5652ff8d6e73ebfbcf1e69e05bb487ca01bcfcc 100644 |
--- a/chrome/browser/safe_browsing/two_phase_uploader.cc |
+++ b/chrome/browser/safe_browsing/two_phase_uploader.cc |
@@ -11,9 +11,9 @@ |
#include "base/bind.h" |
#include "base/macros.h" |
#include "base/memory/ptr_util.h" |
+#include "base/sequence_checker.h" |
#include "base/task_runner.h" |
#include "components/data_use_measurement/core/data_use_user_data.h" |
-#include "content/public/browser/browser_thread.h" |
#include "net/base/net_errors.h" |
#include "net/http/http_response_headers.h" |
#include "net/url_request/url_fetcher.h" |
@@ -42,7 +42,7 @@ class TwoPhaseUploaderImpl : public net::URLFetcherDelegate, |
const ProgressCallback& progress_callback, |
const FinishCallback& finish_callback, |
const net::NetworkTrafficAnnotationTag& traffic_annotation); |
- ~TwoPhaseUploaderImpl() override; |
+ ~TwoPhaseUploaderImpl() override = default; |
// Begins the upload process. |
void Start() override; |
@@ -71,6 +71,10 @@ class TwoPhaseUploaderImpl : public net::URLFetcherDelegate, |
std::unique_ptr<net::URLFetcher> url_fetcher_; |
+ // Ensure access to the state_ variable is sequenced, and that callbacks are |
+ // invoked on the same sequence as Start. |
+ base::SequenceChecker sequence_checker_; |
+ |
DISALLOW_COPY_AND_ASSIGN(TwoPhaseUploaderImpl); |
}; |
@@ -92,22 +96,22 @@ TwoPhaseUploaderImpl::TwoPhaseUploaderImpl( |
progress_callback_(progress_callback), |
finish_callback_(finish_callback), |
traffic_annotation_(traffic_annotation) { |
- DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
-} |
- |
-TwoPhaseUploaderImpl::~TwoPhaseUploaderImpl() { |
- DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
+ // The callbacks must be invoked on the same sequence as Start, but that |
+ // doesn't need to be the same sequence the TwoPhaseUploaderImpl was |
+ // constructed on. |
+ sequence_checker_.DetachFromSequence(); |
} |
void TwoPhaseUploaderImpl::Start() { |
- DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
+ // Bind the sequence checker to the current sequence. |
+ DCHECK(sequence_checker_.CalledOnValidSequence()); |
DCHECK_EQ(STATE_NONE, state_); |
UploadMetadata(); |
} |
void TwoPhaseUploaderImpl::OnURLFetchComplete(const net::URLFetcher* source) { |
- DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
+ DCHECK(sequence_checker_.CalledOnValidSequence()); |
net::URLRequestStatus status = source->GetStatus(); |
int response_code = source->GetResponseCode(); |
@@ -163,7 +167,7 @@ void TwoPhaseUploaderImpl::OnURLFetchUploadProgress( |
const net::URLFetcher* source, |
int64_t current, |
int64_t total) { |
- DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
+ DCHECK(sequence_checker_.CalledOnValidSequence()); |
DVLOG(3) << __func__ << " " << source->GetURL().spec() << " " << current |
<< "/" << total; |
if (state_ == UPLOAD_FILE && !progress_callback_.is_null()) |
@@ -171,7 +175,7 @@ void TwoPhaseUploaderImpl::OnURLFetchUploadProgress( |
} |
void TwoPhaseUploaderImpl::UploadMetadata() { |
- DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
+ DCHECK(sequence_checker_.CalledOnValidSequence()); |
state_ = UPLOAD_METADATA; |
url_fetcher_ = net::URLFetcher::Create(base_url_, net::URLFetcher::POST, this, |
traffic_annotation_); |
@@ -185,7 +189,7 @@ void TwoPhaseUploaderImpl::UploadMetadata() { |
} |
void TwoPhaseUploaderImpl::UploadFile() { |
- DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
+ DCHECK(sequence_checker_.CalledOnValidSequence()); |
state_ = UPLOAD_FILE; |
url_fetcher_ = net::URLFetcher::Create(upload_url_, net::URLFetcher::PUT, |
@@ -202,7 +206,7 @@ void TwoPhaseUploaderImpl::UploadFile() { |
void TwoPhaseUploaderImpl::Finish(int net_error, |
int response_code, |
const std::string& response) { |
- DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
+ DCHECK(sequence_checker_.CalledOnValidSequence()); |
finish_callback_.Run(state_, net_error, response_code, response); |
} |