Fix breakages in https://codereview.chromium.org/1155713003/
[chromium-blink-merge.git] / ios / web / net / request_tracker_factory_impl.mm
blob8973d3c3a77fc6d0ed2f5743c9082fac4bef2e93
1 // Copyright 2014 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 "ios/web/net/request_tracker_factory_impl.h"
7 #include "base/logging.h"
8 #include "base/memory/weak_ptr.h"
9 #include "base/strings/sys_string_conversions.h"
10 #include "ios/web/net/request_group_util.h"
11 #include "ios/web/net/request_tracker_impl.h"
13 namespace web {
15 RequestTrackerFactoryImpl::RequestTrackerFactoryImpl(
16     const std::string& application_scheme) {
17   if (!application_scheme.empty()) {
18     application_scheme_.reset(
19         [base::SysUTF8ToNSString(application_scheme) copy]);
20     DCHECK(application_scheme_);
21   }
24 RequestTrackerFactoryImpl::~RequestTrackerFactoryImpl() {
27 bool RequestTrackerFactoryImpl::GetRequestTracker(
28     NSURLRequest* request,
29     base::WeakPtr<net::RequestTracker>* tracker) {
30   DCHECK(tracker);
31   DCHECK(!tracker->get());
32   NSString* request_group_id =
33       web::ExtractRequestGroupIDFromRequest(request, application_scheme_);
34   if (!request_group_id) {
35     // There was no request_group_id, so the request was from something like a
36     // data: or file: URL.
37     return true;
38   }
39   RequestTrackerImpl* tracker_impl =
40       RequestTrackerImpl::GetTrackerForRequestGroupID(request_group_id);
41   if (tracker_impl)
42     *tracker = tracker_impl->GetWeakPtr();
43   // If there is a request group ID, but no associated tracker, return false.
44   // This usually happens when the tab has been closed, but can maybe also
45   // happen in other cases (see http://crbug.com/228397).
46   return tracker->get() != nullptr;
49 }  // namespace web