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