forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrequest_tracker_factory_impl.mm
52 lines (44 loc) · 1.69 KB
/
request_tracker_factory_impl.mm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "ios/web/net/request_tracker_factory_impl.h"
#include "base/logging.h"
#include "base/memory/weak_ptr.h"
#include "base/strings/sys_string_conversions.h"
#import "ios/web/net/request_group_util.h"
#import "ios/web/net/request_tracker_impl.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace web {
RequestTrackerFactoryImpl::RequestTrackerFactoryImpl(
const std::string& application_scheme) {
if (!application_scheme.empty()) {
application_scheme_ = [base::SysUTF8ToNSString(application_scheme) copy];
DCHECK(application_scheme_);
}
}
RequestTrackerFactoryImpl::~RequestTrackerFactoryImpl() {
}
bool RequestTrackerFactoryImpl::GetRequestTracker(
NSURLRequest* request,
base::WeakPtr<net::RequestTracker>* tracker) {
DCHECK(tracker);
DCHECK(!tracker->get());
NSString* request_group_id =
web::ExtractRequestGroupIDFromRequest(request, application_scheme_);
if (!request_group_id) {
// There was no request_group_id, so the request was from something like a
// data: or file: URL.
return true;
}
RequestTrackerImpl* tracker_impl =
RequestTrackerImpl::GetTrackerForRequestGroupID(request_group_id);
if (tracker_impl)
*tracker = tracker_impl->GetWeakPtr();
// If there is a request group ID, but no associated tracker, return false.
// This usually happens when the tab has been closed, but can maybe also
// happen in other cases (see http://crbug.com/228397).
return tracker->get() != nullptr;
}
} // namespace web