Refactoring DownloadManager::DownloadURL to add proper annotation.

Refactoring DownloadManager::DownloadURL to add proper network traffic
annotation. All changed files have received a NO_TRAFFIC_ANNOTATION_YET
tag instead of proper annotation and will be annotated in next CLs.

BUG=656607
CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.linux:linux_site_isolation

Review-Url: https://codereview.chromium.org/2860593003
Cr-Commit-Position: refs/heads/master@{#476312}
diff --git a/content/browser/background_fetch/background_fetch_context.cc b/content/browser/background_fetch/background_fetch_context.cc
index c4496e14..ab3b8c3 100644
--- a/content/browser/background_fetch/background_fetch_context.cc
+++ b/content/browser/background_fetch/background_fetch_context.cc
@@ -13,6 +13,7 @@
 #include "content/browser/storage_partition_impl.h"
 #include "content/public/browser/blob_handle.h"
 #include "content/public/browser/browser_context.h"
+#include "net/traffic_annotation/network_traffic_annotation.h"
 #include "net/url_request/url_request_context_getter.h"
 #include "url/origin.h"
 
@@ -158,7 +159,7 @@
   if (request_context_getter_) {
     // Start fetching the |initial_requests| immediately. At some point in the
     // future we may want a more elaborate scheduling mechanism here.
-    controller->Start(std::move(initial_requests));
+    controller->Start(std::move(initial_requests), NO_TRAFFIC_ANNOTATION_YET);
   }
 
   active_fetches_.insert(
diff --git a/content/browser/background_fetch/background_fetch_job_controller.cc b/content/browser/background_fetch/background_fetch_job_controller.cc
index 3f9ae19..950e43120 100644
--- a/content/browser/background_fetch/background_fetch_job_controller.cc
+++ b/content/browser/background_fetch/background_fetch_job_controller.cc
@@ -59,7 +59,9 @@
   base::WeakPtr<Core> GetWeakPtr() { return weak_ptr_factory_.GetWeakPtr(); }
 
   // Starts fetching the |request| with the download manager.
-  void StartRequest(scoped_refptr<BackgroundFetchRequestInfo> request) {
+  void StartRequest(
+      scoped_refptr<BackgroundFetchRequestInfo> request,
+      const net::NetworkTrafficAnnotationTag& traffic_annotation) {
     DCHECK_CURRENTLY_ON(BrowserThread::UI);
     DCHECK(request_context_);
     DCHECK(request);
@@ -108,7 +110,8 @@
                                                  weak_ptr_factory_.GetWeakPtr(),
                                                  std::move(request)));
 
-    download_manager->DownloadUrl(std::move(download_parameters));
+    download_manager->DownloadUrl(std::move(download_parameters),
+                                  traffic_annotation);
   }
 
   // DownloadItem::Observer overrides:
@@ -236,7 +239,8 @@
 BackgroundFetchJobController::~BackgroundFetchJobController() = default;
 
 void BackgroundFetchJobController::Start(
-    std::vector<scoped_refptr<BackgroundFetchRequestInfo>> initial_requests) {
+    std::vector<scoped_refptr<BackgroundFetchRequestInfo>> initial_requests,
+    const net::NetworkTrafficAnnotationTag& traffic_annotation) {
   DCHECK_CURRENTLY_ON(BrowserThread::IO);
   DCHECK_LE(initial_requests.size(), kMaximumBackgroundFetchParallelRequests);
   DCHECK_EQ(state_, State::INITIALIZED);
@@ -244,16 +248,17 @@
   state_ = State::FETCHING;
 
   for (const auto& request : initial_requests)
-    StartRequest(request);
+    StartRequest(request, traffic_annotation);
 }
 
 void BackgroundFetchJobController::StartRequest(
-    scoped_refptr<BackgroundFetchRequestInfo> request) {
+    scoped_refptr<BackgroundFetchRequestInfo> request,
+    const net::NetworkTrafficAnnotationTag& traffic_annotation) {
   DCHECK_CURRENTLY_ON(BrowserThread::IO);
   DCHECK_EQ(state_, State::FETCHING);
-  BrowserThread::PostTask(
-      BrowserThread::UI, FROM_HERE,
-      base::Bind(&Core::StartRequest, ui_core_ptr_, std::move(request)));
+  BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
+                          base::Bind(&Core::StartRequest, ui_core_ptr_,
+                                     std::move(request), traffic_annotation));
 }
 
 void BackgroundFetchJobController::DidStartRequest(
@@ -285,7 +290,7 @@
 
   // If a |request| has been given, start downloading the file and bail.
   if (request) {
-    StartRequest(std::move(request));
+    StartRequest(std::move(request), NO_TRAFFIC_ANNOTATION_YET);
     return;
   }
 
diff --git a/content/browser/background_fetch/background_fetch_job_controller.h b/content/browser/background_fetch/background_fetch_job_controller.h
index 4c33c76..a6e598c 100644
--- a/content/browser/background_fetch/background_fetch_job_controller.h
+++ b/content/browser/background_fetch/background_fetch_job_controller.h
@@ -17,6 +17,7 @@
 #include "content/common/background_fetch/background_fetch_types.h"
 #include "content/common/content_export.h"
 #include "content/public/browser/browser_thread.h"
+#include "net/traffic_annotation/network_traffic_annotation.h"
 
 namespace net {
 class URLRequestContextGetter;
@@ -49,7 +50,8 @@
   // Starts fetching the |initial_fetches|. The controller will continue to
   // fetch new content until all requests have been handled.
   void Start(
-      std::vector<scoped_refptr<BackgroundFetchRequestInfo>> initial_requests);
+      std::vector<scoped_refptr<BackgroundFetchRequestInfo>> initial_requests,
+      const net::NetworkTrafficAnnotationTag& traffic_annotation);
 
   // Updates the representation of this Background Fetch in the user interface
   // to match the given |title|.
@@ -73,7 +75,8 @@
   class Core;
 
   // Requests the download manager to start fetching |request|.
-  void StartRequest(scoped_refptr<BackgroundFetchRequestInfo> request);
+  void StartRequest(scoped_refptr<BackgroundFetchRequestInfo> request,
+                    const net::NetworkTrafficAnnotationTag& traffic_annotation);
 
   // Called when the given |request| has started fetching, after having been
   // assigned the |download_guid| by the download system.
diff --git a/content/browser/background_fetch/background_fetch_job_controller_unittest.cc b/content/browser/background_fetch/background_fetch_job_controller_unittest.cc
index d2678142..55853a3 100644
--- a/content/browser/background_fetch/background_fetch_job_controller_unittest.cc
+++ b/content/browser/background_fetch/background_fetch_job_controller_unittest.cc
@@ -20,6 +20,7 @@
 #include "content/public/browser/storage_partition.h"
 #include "content/public/test/fake_download_item.h"
 #include "content/public/test/mock_download_manager.h"
+#include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
 #include "net/url_request/url_request_context_getter.h"
 #include "testing/gmock/include/gmock/gmock.h"
 
@@ -148,7 +149,8 @@
   EXPECT_EQ(controller->state(),
             BackgroundFetchJobController::State::INITIALIZED);
 
-  controller->Start(initial_requests /* deliberate copy */);
+  controller->Start(initial_requests /* deliberate copy */,
+                    TRAFFIC_ANNOTATION_FOR_TESTS);
   EXPECT_EQ(controller->state(), BackgroundFetchJobController::State::FETCHING);
 
   // Mark the single download item as finished, completing the job.
@@ -192,7 +194,8 @@
     base::RunLoop run_loop;
     job_completed_closure_ = run_loop.QuitClosure();
 
-    controller->Start(initial_requests /* deliberate copy */);
+    controller->Start(initial_requests /* deliberate copy */,
+                      TRAFFIC_ANNOTATION_FOR_TESTS);
     EXPECT_EQ(controller->state(),
               BackgroundFetchJobController::State::FETCHING);
 
@@ -223,7 +226,8 @@
     base::RunLoop run_loop;
     job_completed_closure_ = run_loop.QuitClosure();
 
-    controller->Start(initial_requests /* deliberate copy */);
+    controller->Start(initial_requests /* deliberate copy */,
+                      TRAFFIC_ANNOTATION_FOR_TESTS);
     EXPECT_EQ(controller->state(),
               BackgroundFetchJobController::State::FETCHING);
 
diff --git a/content/browser/background_fetch/background_fetch_test_base.cc b/content/browser/background_fetch/background_fetch_test_base.cc
index 9314f19..f925c74 100644
--- a/content/browser/background_fetch/background_fetch_test_base.cc
+++ b/content/browser/background_fetch/background_fetch_test_base.cc
@@ -125,7 +125,9 @@
 
   // Called when the Background Fetch system starts a download, all information
   // for which is contained in the |params|.
-  void DownloadUrl(std::unique_ptr<DownloadUrlParameters> params) override {
+  void DownloadUrl(
+      std::unique_ptr<DownloadUrlParameters> params,
+      const net::NetworkTrafficAnnotationTag& traffic_annotation) override {
     auto iter = registered_responses_.find(params->url());
     if (iter == registered_responses_.end())
       return;
diff --git a/content/browser/download/download_browsertest.cc b/content/browser/download/download_browsertest.cc
index a5debca..b2a20a7 100644
--- a/content/browser/download/download_browsertest.cc
+++ b/content/browser/download/download_browsertest.cc
@@ -63,6 +63,7 @@
 #include "net/test/embedded_test_server/http_response.h"
 #include "net/test/url_request/url_request_mock_http_job.h"
 #include "net/test/url_request/url_request_slow_download_job.h"
+#include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
 #include "ppapi/features/features.h"
 #include "testing/gmock/include/gmock/gmock.h"
 #include "testing/gtest/include/gtest/gtest.h"
@@ -2347,7 +2348,8 @@
       DownloadUrlParameters::CreateForWebContentsMainFrame(
           shell()->web_contents(), origin_two.GetURL("/bar")));
   std::unique_ptr<DownloadTestObserver> observer(CreateWaiter(shell(), 1));
-  DownloadManagerForShell(shell())->DownloadUrl(std::move(download_parameters));
+  DownloadManagerForShell(shell())->DownloadUrl(std::move(download_parameters),
+                                                TRAFFIC_ANNOTATION_FOR_TESTS);
   observer->WaitForFinished();
 
   // Get the important info from other threads and check it.
diff --git a/content/browser/download/download_manager_impl.cc b/content/browser/download/download_manager_impl.cc
index ecd6d88..238508c 100644
--- a/content/browser/download/download_manager_impl.cc
+++ b/content/browser/download/download_manager_impl.cc
@@ -51,6 +51,7 @@
 #include "net/base/upload_bytes_element_reader.h"
 #include "net/log/net_log_source_type.h"
 #include "net/log/net_log_with_source.h"
+#include "net/traffic_annotation/network_traffic_annotation.h"
 #include "net/url_request/url_request_context.h"
 #include "storage/browser/blob/blob_url_request_job_factory.h"
 #include "url/origin.h"
@@ -66,7 +67,8 @@
   DCHECK_CURRENTLY_ON(BrowserThread::IO);
 
   std::unique_ptr<net::URLRequest> url_request =
-      DownloadRequestCore::CreateRequestOnIOThread(download_id, params.get());
+      DownloadRequestCore::CreateRequestOnIOThread(download_id, params.get(),
+                                                   NO_TRAFFIC_ANNOTATION_YET);
   std::unique_ptr<storage::BlobDataHandle> blob_data_handle =
       params->GetBlobDataHandle();
   if (blob_data_handle) {
@@ -606,7 +608,8 @@
 }
 
 void DownloadManagerImpl::DownloadUrl(
-    std::unique_ptr<DownloadUrlParameters> params) {
+    std::unique_ptr<DownloadUrlParameters> params,
+    const net::NetworkTrafficAnnotationTag& traffic_annotation) {
   if (params->post_id() >= 0) {
     // Check this here so that the traceback is more useful.
     DCHECK(params->prefer_cache());
diff --git a/content/browser/download/download_manager_impl.h b/content/browser/download/download_manager_impl.h
index e9b13f6..23e6ba7 100644
--- a/content/browser/download/download_manager_impl.h
+++ b/content/browser/download/download_manager_impl.h
@@ -27,6 +27,7 @@
 #include "content/public/browser/download_manager.h"
 #include "content/public/browser/download_manager_delegate.h"
 #include "content/public/browser/download_url_parameters.h"
+#include "net/traffic_annotation/network_traffic_annotation.h"
 
 namespace net {
 class NetLog;
@@ -79,7 +80,9 @@
       const base::Callback<bool(const GURL&)>& url_filter,
       base::Time remove_begin,
       base::Time remove_end) override;
-  void DownloadUrl(std::unique_ptr<DownloadUrlParameters> params) override;
+  void DownloadUrl(
+      std::unique_ptr<DownloadUrlParameters> params,
+      const net::NetworkTrafficAnnotationTag& traffic_annotation) override;
   void AddObserver(Observer* observer) override;
   void RemoveObserver(Observer* observer) override;
   content::DownloadItem* CreateDownloadItem(
diff --git a/content/browser/download/download_request_core.cc b/content/browser/download/download_request_core.cc
index fef2ca6..34783e6 100644
--- a/content/browser/download/download_request_core.cc
+++ b/content/browser/download/download_request_core.cc
@@ -115,7 +115,8 @@
 // static
 std::unique_ptr<net::URLRequest> DownloadRequestCore::CreateRequestOnIOThread(
     uint32_t download_id,
-    DownloadUrlParameters* params) {
+    DownloadUrlParameters* params,
+    const net::NetworkTrafficAnnotationTag& traffic_annotation) {
   DCHECK_CURRENTLY_ON(BrowserThread::IO);
   DCHECK(download_id == DownloadItem::kInvalidId ||
          !params->content_initiated())
@@ -128,7 +129,8 @@
   std::unique_ptr<net::URLRequest> request(
       params->url_request_context_getter()
           ->GetURLRequestContext()
-          ->CreateRequest(params->url(), net::DEFAULT_PRIORITY, nullptr));
+          ->CreateRequest(params->url(), net::DEFAULT_PRIORITY, nullptr,
+                          traffic_annotation));
   request->set_method(params->method());
 
   if (!params->post_body().empty()) {
diff --git a/content/browser/download/download_request_core.h b/content/browser/download/download_request_core.h
index fc2ccd2..e2a9f80 100644
--- a/content/browser/download/download_request_core.h
+++ b/content/browser/download/download_request_core.h
@@ -19,6 +19,7 @@
 #include "content/public/browser/download_save_info.h"
 #include "content/public/browser/download_url_parameters.h"
 #include "device/wake_lock/public/interfaces/wake_lock_service.mojom.h"
+#include "net/traffic_annotation/network_traffic_annotation.h"
 
 namespace net {
 class HttpResponseHeaders;
@@ -105,7 +106,8 @@
 
   static std::unique_ptr<net::URLRequest> CreateRequestOnIOThread(
       uint32_t download_id,
-      DownloadUrlParameters* params);
+      DownloadUrlParameters* params,
+      const net::NetworkTrafficAnnotationTag& traffic_annotation);
 
   // Size of the buffer used between the DownloadRequestCore and the
   // downstream receiver of its output.
diff --git a/content/browser/download/download_request_core_unittest.cc b/content/browser/download/download_request_core_unittest.cc
index f2eba00..2be6a58 100644
--- a/content/browser/download/download_request_core_unittest.cc
+++ b/content/browser/download/download_request_core_unittest.cc
@@ -12,6 +12,7 @@
 #include "content/public/browser/download_url_parameters.h"
 #include "content/public/test/test_browser_thread_bundle.h"
 #include "net/http/http_request_headers.h"
+#include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
 #include "net/url_request/url_request_test_util.h"
 #include "testing/gtest/include/gtest/gtest.h"
 
@@ -47,7 +48,7 @@
 
   void CreateRequestOnIOThread(DownloadUrlParameters* params) {
     url_request_ = DownloadRequestCore::CreateRequestOnIOThread(
-        DownloadItem::kInvalidId, params);
+        DownloadItem::kInvalidId, params, TRAFFIC_ANNOTATION_FOR_TESTS);
     DCHECK(url_request_.get());
   }
 
diff --git a/content/browser/download/download_worker.cc b/content/browser/download/download_worker.cc
index 5eff1cf..c1fea18 100644
--- a/content/browser/download/download_worker.cc
+++ b/content/browser/download/download_worker.cc
@@ -7,6 +7,7 @@
 #include "content/browser/download/download_create_info.h"
 #include "content/public/browser/download_interrupt_reasons.h"
 #include "content/public/browser/web_contents.h"
+#include "net/traffic_annotation/network_traffic_annotation.h"
 
 namespace content {
 namespace {
@@ -38,8 +39,8 @@
   // Build the URLRequest, BlobDataHandle is hold in original request for image
   // download.
   std::unique_ptr<net::URLRequest> url_request =
-      DownloadRequestCore::CreateRequestOnIOThread(DownloadItem::kInvalidId,
-                                                   params.get());
+      DownloadRequestCore::CreateRequestOnIOThread(
+          DownloadItem::kInvalidId, params.get(), NO_TRAFFIC_ANNOTATION_YET);
 
   return std::unique_ptr<UrlDownloader, BrowserThread::DeleteOnIOThread>(
       UrlDownloader::BeginDownload(delegate, std::move(url_request),
diff --git a/content/browser/download/drag_download_file.cc b/content/browser/download/drag_download_file.cc
index 40c76535..88b159e 100644
--- a/content/browser/download/drag_download_file.cc
+++ b/content/browser/download/drag_download_file.cc
@@ -20,6 +20,7 @@
 #include "content/public/browser/download_item.h"
 #include "content/public/browser/download_save_info.h"
 #include "content/public/browser/download_url_parameters.h"
+#include "net/traffic_annotation/network_traffic_annotation.h"
 
 namespace content {
 
@@ -77,7 +78,7 @@
     params->set_file_path(file_path);
     params->set_file(std::move(file));  // Nulls file.
     BrowserContext::GetDownloadManager(web_contents_->GetBrowserContext())
-        ->DownloadUrl(std::move(params));
+        ->DownloadUrl(std::move(params), NO_TRAFFIC_ANNOTATION_YET);
   }
 
   void Cancel() {
diff --git a/content/browser/frame_host/render_frame_message_filter.cc b/content/browser/frame_host/render_frame_message_filter.cc
index bbbb37d..42dde36 100644
--- a/content/browser/frame_host/render_frame_message_filter.cc
+++ b/content/browser/frame_host/render_frame_message_filter.cc
@@ -30,6 +30,7 @@
 #include "net/base/registry_controlled_domains/registry_controlled_domain.h"
 #include "net/cookies/cookie_options.h"
 #include "net/cookies/cookie_store.h"
+#include "net/traffic_annotation/network_traffic_annotation.h"
 #include "net/url_request/url_request_context.h"
 #include "net/url_request/url_request_context_getter.h"
 #include "ppapi/features/features.h"
@@ -89,7 +90,8 @@
   DownloadManager* download_manager =
       BrowserContext::GetDownloadManager(browser_context);
   RecordDownloadSource(INITIATED_BY_RENDERER);
-  download_manager->DownloadUrl(std::move(parameters));
+  download_manager->DownloadUrl(std::move(parameters),
+                                NO_TRAFFIC_ANNOTATION_YET);
 }
 
 // Common functionality for converting a sync renderer message to a callback
diff --git a/content/browser/indexed_db/indexed_db_internals_ui.cc b/content/browser/indexed_db/indexed_db_internals_ui.cc
index 8e304fa..4545865 100644
--- a/content/browser/indexed_db/indexed_db_internals_ui.cc
+++ b/content/browser/indexed_db/indexed_db_internals_ui.cc
@@ -23,6 +23,7 @@
 #include "content/public/browser/web_ui.h"
 #include "content/public/browser/web_ui_data_source.h"
 #include "content/public/common/url_constants.h"
+#include "net/traffic_annotation/network_traffic_annotation.h"
 #include "storage/common/database/database_identifier.h"
 #include "third_party/zlib/google/zip.h"
 #include "ui/base/text/bytes_formatting.h"
@@ -299,7 +300,7 @@
 
   BrowserContext* context = web_contents->GetBrowserContext();
   BrowserContext::GetDownloadManager(context)->DownloadUrl(
-      std::move(dl_params));
+      std::move(dl_params), NO_TRAFFIC_ANNOTATION_YET);
 }
 
 // The entire purpose of this class is to delete the temp file after
diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc
index ed882eff..626c4c8 100644
--- a/content/browser/web_contents/web_contents_impl.cc
+++ b/content/browser/web_contents/web_contents_impl.cc
@@ -127,6 +127,7 @@
 #include "net/base/url_util.h"
 #include "net/http/http_cache.h"
 #include "net/http/http_transaction_factory.h"
+#include "net/traffic_annotation/network_traffic_annotation.h"
 #include "net/url_request/url_request_context.h"
 #include "net/url_request/url_request_context_getter.h"
 #include "ppapi/features/features.h"
@@ -3209,7 +3210,7 @@
     }
   }
   BrowserContext::GetDownloadManager(GetBrowserContext())
-      ->DownloadUrl(std::move(params));
+      ->DownloadUrl(std::move(params), NO_TRAFFIC_ANNOTATION_YET);
 }
 
 void WebContentsImpl::GenerateMHTML(