OLD | NEW |
| (Empty) |
1 // Copyright 2016 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. | |
4 | |
5 #ifndef CHROME_BROWSER_ANDROID_OFFLINE_PAGES_OFFLINE_PAGE_REQUEST_HANDLER_H_ | |
6 #define CHROME_BROWSER_ANDROID_OFFLINE_PAGES_OFFLINE_PAGE_REQUEST_HANDLER_H_ | |
7 | |
8 #include "base/macros.h" | |
9 #include "base/supports_user_data.h" | |
10 #include "content/public/common/resource_type.h" | |
11 | |
12 namespace net { | |
13 class NetworkDelegate; | |
14 class URLRequest; | |
15 class URLRequestInterceptor; | |
16 class URLRequestJob; | |
17 } | |
18 | |
19 namespace offline_pages { | |
20 | |
21 // Class for servicing requests based on their offline information. Created one | |
22 // per URLRequest and attached to each request. | |
23 // | |
24 // For each supported profile, OfflinePageRequestHandler::CreateInterceptor | |
25 // should be called once to install the custom interceptor. | |
26 // | |
27 // For each request: | |
28 // 1) When a request is starting, OfflinePageRequestHandler::InitializeHandler | |
29 // will be called to create a new handler and attach to the request. | |
30 // 2) When a request is being processed, MaybeInterceptRequest of custom | |
31 // interceptor will be inquired. | |
32 // 2.1) If the attached OfflinePageRequestHandler for the request is found, | |
33 // delegate to OfflinePageRequestHandler::MaybeCreateJob to do the work. | |
34 // 2.1.1) Do immediate checks for those scenarios that the interception | |
35 // is not needed. Bail out if so. | |
36 // 2.1.2) Start an async task to try to find the offline page. | |
37 // 2.1.3) Return a custom URLRequestJob that is put on hold to wait | |
38 // for the result of finding offline page. | |
39 // 2.2) Otherwise, bail out without interception. | |
40 class OfflinePageRequestHandler : public base::SupportsUserData::Data { | |
41 public: | |
42 // Attaches a newly created handler if the given |request| needs to | |
43 // be handled by offline pages. | |
44 static void InitializeHandler(net::URLRequest* request, | |
45 content::ResourceType resource_type); | |
46 | |
47 // Returns the handler attached to |request|. This may return null if no | |
48 // handler is attached. | |
49 static OfflinePageRequestHandler* GetHandler(net::URLRequest* request); | |
50 | |
51 // Creates a protocol interceptor for offline pages. Created one per | |
52 // supported, i.e. non-incognito, profile. | |
53 // |profile_id|, which identifies the profile, is passed as a void* to ensure | |
54 // it's not accidently used on the IO thread. | |
55 static std::unique_ptr<net::URLRequestInterceptor> CreateInterceptor( | |
56 void* profile_id); | |
57 | |
58 ~OfflinePageRequestHandler() override; | |
59 | |
60 net::URLRequestJob* MaybeCreateJob( | |
61 net::URLRequest* request, | |
62 net::NetworkDelegate* network_delegate, | |
63 void* profile_id); | |
64 | |
65 private: | |
66 OfflinePageRequestHandler(); | |
67 | |
68 DISALLOW_COPY_AND_ASSIGN(OfflinePageRequestHandler); | |
69 }; | |
70 | |
71 } // namespace offline_pages | |
72 | |
73 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_OFFLINE_PAGE_REQUEST_HANDLER_H_ | |
OLD | NEW |