[Cronet] Add const and thread annotations to native UrlRequest.

Change-Id: Ia56988f41bf11d74be67f0e7876b22c48a6c34d0
Reviewed-on: https://chromium-review.googlesource.com/c/1423619
Reviewed-by: Paul Jensen <pauljensen@chromium.org>
Reviewed-by: Misha Efimov <mef@chromium.org>
Commit-Queue: Caleb Raitto <caraitto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#625350}
diff --git a/components/cronet/native/url_request.cc b/components/cronet/native/url_request.cc
index 98c645f..1688f23 100644
--- a/components/cronet/native/url_request.cc
+++ b/components/cronet/native/url_request.cc
@@ -434,7 +434,7 @@
   return IsDoneLocked();
 }
 
-bool Cronet_UrlRequestImpl::IsDoneLocked() {
+bool Cronet_UrlRequestImpl::IsDoneLocked() const {
   lock_.AssertAcquired();
   return started_ && request_ == nullptr;
 }
diff --git a/components/cronet/native/url_request.h b/components/cronet/native/url_request.h
index e3936b1..08ba896 100644
--- a/components/cronet/native/url_request.h
+++ b/components/cronet/native/url_request.h
@@ -12,6 +12,7 @@
 #include "base/macros.h"
 #include "base/synchronization/lock.h"
 #include "base/synchronization/waitable_event.h"
+#include "base/thread_annotations.h"
 #include "components/cronet/cronet_url_request.h"
 #include "components/cronet/cronet_url_request_context.h"
 #include "components/cronet/native/generated/cronet.idl_impl_interface.h"
@@ -53,7 +54,7 @@
 
   // Return |true| if request has started and is now done.
   // Must be called under |lock_| held.
-  bool IsDoneLocked();
+  bool IsDoneLocked() const SHARED_LOCKS_REQUIRED(lock_);
 
   // Helper method to set final status of CronetUrlRequest and clean up the
   // native request adapter. Returns true if request is already done, false
@@ -65,7 +66,8 @@
   // native request adapter. Returns true if request is already done, false
   // request is not done and is destroyed. Must be called under |lock_| held.
   bool DestroyRequestUnlessDoneLocked(
-      Cronet_RequestFinishedInfo_FINISHED_REASON finished_reason);
+      Cronet_RequestFinishedInfo_FINISHED_REASON finished_reason)
+      EXCLUSIVE_LOCKS_REQUIRED(lock_);
 
   // Helper method to post |task| to the |executor_|.
   void PostTaskToExecutor(base::OnceClosure task);
@@ -90,14 +92,15 @@
   base::Lock lock_;
   // NetworkTask object lives on the network thread. Owned by |request_|.
   // Outlives this.
-  NetworkTasks* network_tasks_ = nullptr;
+  NetworkTasks* network_tasks_ GUARDED_BY(lock_) = nullptr;
   // Cronet URLRequest used for this operation.
-  CronetURLRequest* request_ = nullptr;
-  bool started_ = false;
-  bool waiting_on_redirect_ = false;
-  bool waiting_on_read_ = false;
+  CronetURLRequest* request_ GUARDED_BY(lock_) = nullptr;
+  bool started_ GUARDED_BY(lock_) = false;
+  bool waiting_on_redirect_ GUARDED_BY(lock_) = false;
+  bool waiting_on_read_ GUARDED_BY(lock_) = false;
   // Set of status_listeners_ that have not yet been called back.
-  std::unordered_multiset<Cronet_UrlRequestStatusListenerPtr> status_listeners_;
+  std::unordered_multiset<Cronet_UrlRequestStatusListenerPtr> status_listeners_
+      GUARDED_BY(lock_);
 
   // Response info updated by callback with number of bytes received. May be
   // nullptr, if no response has been received.