Give names to all utility processes.
[chromium-blink-merge.git] / chrome / browser / download / download_resource_throttle.cc
blobe613ae964caeb88f60390cd141201cd0833ba984
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/download/download_resource_throttle.h"
7 #include "base/bind.h"
8 #include "base/profiler/scoped_tracker.h"
9 #include "chrome/browser/download/download_stats.h"
10 #include "content/public/browser/resource_controller.h"
12 DownloadResourceThrottle::DownloadResourceThrottle(
13 DownloadRequestLimiter* limiter,
14 int render_process_id,
15 int render_view_id,
16 const GURL& url,
17 const std::string& request_method)
18 : querying_limiter_(true),
19 request_allowed_(false),
20 request_deferred_(false) {
21 limiter->CanDownloadOnIOThread(
22 render_process_id,
23 render_view_id,
24 url,
25 request_method,
26 base::Bind(&DownloadResourceThrottle::ContinueDownload,
27 AsWeakPtr()));
30 DownloadResourceThrottle::~DownloadResourceThrottle() {
33 void DownloadResourceThrottle::WillStartRequest(bool* defer) {
34 WillDownload(defer);
37 void DownloadResourceThrottle::WillRedirectRequest(
38 const net::RedirectInfo& redirect_info,
39 bool* defer) {
40 WillDownload(defer);
43 void DownloadResourceThrottle::WillProcessResponse(bool* defer) {
44 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed.
45 tracked_objects::ScopedTracker tracking_profile(
46 FROM_HERE_WITH_EXPLICIT_FUNCTION(
47 "422516 DownloadResourceThrottle::WillProcessResponse"));
49 WillDownload(defer);
52 const char* DownloadResourceThrottle::GetNameForLogging() const {
53 return "DownloadResourceThrottle";
56 void DownloadResourceThrottle::WillDownload(bool* defer) {
57 DCHECK(!request_deferred_);
59 // Defer the download until we have the DownloadRequestLimiter result.
60 if (querying_limiter_) {
61 request_deferred_ = true;
62 *defer = true;
63 return;
66 if (!request_allowed_)
67 controller()->Cancel();
70 void DownloadResourceThrottle::ContinueDownload(bool allow) {
71 querying_limiter_ = false;
72 request_allowed_ = allow;
74 if (allow) {
75 // Presumes all downloads initiated by navigation use this throttle and
76 // nothing else does.
77 RecordDownloadSource(DOWNLOAD_INITIATED_BY_NAVIGATION);
78 } else {
79 RecordDownloadCount(CHROME_DOWNLOAD_COUNT_BLOCKED_BY_THROTTLING);
82 if (request_deferred_) {
83 request_deferred_ = false;
84 if (allow) {
85 controller()->Resume();
86 } else {
87 controller()->Cancel();