Evict resources from resource pool after timeout
[chromium-blink-merge.git] / net / url_request / url_request_job_manager.h
blob7729abbbe2b710031367cd0f8fbc588b111ce2e1
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 #ifndef NET_URL_REQUEST_URL_REQUEST_JOB_MANAGER_H_
6 #define NET_URL_REQUEST_URL_REQUEST_JOB_MANAGER_H_
8 #include <string>
10 #include "base/threading/thread_checker.h"
11 #include "net/base/net_export.h"
12 #include "net/url_request/url_request.h"
14 template <typename T> struct DefaultSingletonTraits;
16 namespace net {
18 // This class is responsible for managing the set of protocol factories and
19 // request interceptors that determine how an URLRequestJob gets created to
20 // handle an URLRequest.
22 // MULTI-THREADING NOTICE:
23 // URLRequest is designed to have all consumers on a single thread, and
24 // so no attempt is made to support Interceptor instances being
25 // registered/unregistered or in any way poked on multiple threads.
26 class NET_EXPORT URLRequestJobManager {
27 public:
28 // Returns the singleton instance.
29 static URLRequestJobManager* GetInstance();
31 // Instantiate an URLRequestJob implementation based on the registered
32 // interceptors and protocol factories. This will always succeed in
33 // returning a job unless we are--in the extreme case--out of memory.
34 URLRequestJob* CreateJob(URLRequest* request,
35 NetworkDelegate* network_delegate) const;
37 // Allows interceptors to hijack the request after examining the new location
38 // of a redirect. Returns NULL if no interceptor intervenes.
39 URLRequestJob* MaybeInterceptRedirect(URLRequest* request,
40 NetworkDelegate* network_delegate,
41 const GURL& location) const;
43 // Allows interceptors to hijack the request after examining the response
44 // status and headers. This is also called when there is no server response
45 // at all to allow interception of failed requests due to network errors.
46 // Returns NULL if no interceptor intervenes.
47 URLRequestJob* MaybeInterceptResponse(
48 URLRequest* request, NetworkDelegate* network_delegate) const;
50 // Returns true if the manager has a built-in handler for |scheme|.
51 static bool SupportsScheme(const std::string& scheme);
53 private:
54 friend struct DefaultSingletonTraits<URLRequestJobManager>;
56 URLRequestJobManager();
57 ~URLRequestJobManager();
59 // The first guy to call this function sets the allowed thread. This way we
60 // avoid needing to define that thread externally. Since we expect all
61 // callers to be on the same thread, we don't worry about threads racing to
62 // set the allowed thread.
63 bool IsAllowedThread() const {
64 #if 0
65 return thread_checker_.CalledOnValidThread();
68 // We use this to assert that CreateJob and the registration functions all
69 // run on the same thread.
70 base::ThreadChecker thread_checker_;
71 #else
72 // The previous version of this check used GetCurrentThread on Windows to
73 // get thread handles to compare. Unfortunately, GetCurrentThread returns
74 // a constant pseudo-handle (0xFFFFFFFE), and therefore IsAllowedThread
75 // always returned true. The above code that's turned off is the correct
76 // code, but causes the tree to turn red because some caller isn't
77 // respecting our thread requirements. We're turning off the check for now;
78 // bug http://b/issue?id=1338969 has been filed to fix things and turn the
79 // check back on.
80 return true;
82 #endif
84 DISALLOW_COPY_AND_ASSIGN(URLRequestJobManager);
87 } // namespace net
89 #endif // NET_URL_REQUEST_URL_REQUEST_JOB_MANAGER_H_