| 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/memory/weak_ptr.h" |
| 10 #include "base/supports_user_data.h" |
| 11 #include "chrome/browser/android/offline_pages/offline_page_request_redirect_job
.h" |
| 12 #include "content/public/common/resource_type.h" |
| 13 |
| 14 namespace net { |
| 15 class NetworkDelegate; |
| 16 class URLRequest; |
| 17 class URLRequestInterceptor; |
| 18 } |
| 19 |
| 20 namespace offline_pages { |
| 21 |
| 22 // Class for servicing requests based on their offline information. Created one |
| 23 // per URLRequest and attached to each request. |
| 24 class OfflinePageRequestHandler : |
| 25 public base::SupportsUserData::Data, |
| 26 public OfflinePageRequestRedirectJob::Delegate { |
| 27 public: |
| 28 // Attaches a newly created handler if the given |request| needs to |
| 29 // be handled by offline pages. |
| 30 static void InitializeHandler(net::URLRequest* request, |
| 31 content::ResourceType resource_type); |
| 32 |
| 33 // Returns the handler attached to |request|. This may return null |
| 34 // if no handler is attached. |
| 35 static OfflinePageRequestHandler* GetHandler(net::URLRequest* request); |
| 36 |
| 37 // Creates a protocol interceptor for offline pages. |
| 38 static std::unique_ptr<net::URLRequestInterceptor> CreateInterceptor( |
| 39 void* profile_id); |
| 40 |
| 41 ~OfflinePageRequestHandler() override; |
| 42 |
| 43 // OfflinePageRequestRedirectJob::Delegate overrides: |
| 44 void OnPrepareToRestart() override; |
| 45 |
| 46 net::URLRequestJob* MaybeCreateJob(net::URLRequest* request, |
| 47 net::NetworkDelegate* network_delegate, |
| 48 void* profile_id); |
| 49 |
| 50 private: |
| 51 OfflinePageRequestHandler(); |
| 52 |
| 53 // Invoked from UI thread. |
| 54 void GetRedirectUrl(const GURL& url, void* profile_id); |
| 55 |
| 56 base::WeakPtr<OfflinePageRequestRedirectJob> redirect_job_; |
| 57 |
| 58 // True if the next time this request is started, the request should be |
| 59 // serviced from the default handler. |
| 60 bool use_default_ = false; |
| 61 |
| 62 base::WeakPtrFactory<OfflinePageRequestHandler> weak_ptr_factory_; |
| 63 |
| 64 DISALLOW_COPY_AND_ASSIGN(OfflinePageRequestHandler); |
| 65 }; |
| 66 |
| 67 } // namespace offline_pages |
| 68 |
| 69 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_OFFLINE_PAGE_REQUEST_HANDLER_H_ |
| OLD | NEW |