| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_ANDROID_OFFLINE_PAGES_OFFLINE_PAGE_REQUEST_JOB_H_ | 5 #ifndef CHROME_BROWSER_ANDROID_OFFLINE_PAGES_OFFLINE_PAGE_REQUEST_JOB_H_ |
| 6 #define CHROME_BROWSER_ANDROID_OFFLINE_PAGES_OFFLINE_PAGE_REQUEST_JOB_H_ | 6 #define CHROME_BROWSER_ANDROID_OFFLINE_PAGES_OFFLINE_PAGE_REQUEST_JOB_H_ |
| 7 | 7 |
| 8 #include <memory> |
| 9 |
| 8 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| 9 #include "content/public/browser/resource_request_info.h" | 11 #include "content/public/browser/resource_request_info.h" |
| 10 #include "content/public/common/resource_type.h" | 12 #include "content/public/common/resource_type.h" |
| 11 #include "net/url_request/url_request_file_job.h" | 13 #include "net/url_request/url_request_file_job.h" |
| 12 | 14 |
| 13 namespace base { | 15 namespace base { |
| 14 class FilePath; | 16 class FilePath; |
| 15 } | 17 } |
| 16 | 18 |
| 17 namespace previews { | 19 namespace previews { |
| 18 class PreviewsDecider; | 20 class PreviewsDecider; |
| 19 } | 21 } |
| 20 | 22 |
| 21 namespace offline_pages { | 23 namespace offline_pages { |
| 24 struct OfflinePageHeader; |
| 25 struct OfflinePageItem; |
| 22 | 26 |
| 23 // A request job that serves content from offline file. | 27 // A request job that serves content from offline file. |
| 24 class OfflinePageRequestJob : public net::URLRequestFileJob { | 28 class OfflinePageRequestJob : public net::URLRequestFileJob { |
| 25 public: | 29 public: |
| 26 // This enum is used for UMA reporting. It contains all possible outcomes of | 30 // This enum is used for UMA reporting. It contains all possible outcomes of |
| 27 // handling requests that might service offline page in different network | 31 // handling requests that might service offline page in different network |
| 28 // conditions. Generally one of these outcomes will happen. | 32 // conditions. Generally one of these outcomes will happen. |
| 29 // The fringe errors (like no OfflinePageModel, etc.) are not reported due | 33 // The fringe errors (like no OfflinePageModel, etc.) are not reported due |
| 30 // to their low probability. | 34 // to their low probability. |
| 31 // NOTE: because this is used for UMA reporting, these values should not be | 35 // NOTE: because this is used for UMA reporting, these values should not be |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 net::URLRequest* request, | 77 net::URLRequest* request, |
| 74 net::NetworkDelegate* network_delegate, | 78 net::NetworkDelegate* network_delegate, |
| 75 previews::PreviewsDecider* previews_decider); | 79 previews::PreviewsDecider* previews_decider); |
| 76 | 80 |
| 77 ~OfflinePageRequestJob() override; | 81 ~OfflinePageRequestJob() override; |
| 78 | 82 |
| 79 // net::URLRequestJob overrides: | 83 // net::URLRequestJob overrides: |
| 80 void Start() override; | 84 void Start() override; |
| 81 void Kill() override; | 85 void Kill() override; |
| 82 | 86 |
| 83 void OnOfflineFilePathAvailable(const base::FilePath& offline_file_path); | 87 void OnOfflineFilePathAvailable( |
| 88 const base::FilePath& offline_file_path, |
| 89 std::unique_ptr<OfflinePageHeader> offline_header, |
| 90 std::unique_ptr<OfflinePageItem> offline_page); |
| 84 | 91 |
| 85 void SetDelegateForTesting(std::unique_ptr<Delegate> delegate); | 92 void SetDelegateForTesting(std::unique_ptr<Delegate> delegate); |
| 86 | 93 |
| 87 private: | 94 private: |
| 88 OfflinePageRequestJob(net::URLRequest* request, | 95 OfflinePageRequestJob(net::URLRequest* request, |
| 89 net::NetworkDelegate* network_delegate, | 96 net::NetworkDelegate* network_delegate, |
| 90 previews::PreviewsDecider* previews_decider); | 97 previews::PreviewsDecider* previews_decider); |
| 91 | 98 |
| 92 void StartAsync(); | 99 void StartAsync(); |
| 93 | 100 |
| 94 // Restarts the request job in order to fall back to the default handling. | 101 // Restarts the request job in order to fall back to the default handling. |
| 95 void FallbackToDefault(); | 102 void FallbackToDefault(); |
| 96 | 103 |
| 97 std::unique_ptr<Delegate> delegate_; | 104 std::unique_ptr<Delegate> delegate_; |
| 98 | 105 |
| 99 // Used to determine if an URLRequest is eligible for offline previews. | 106 // Used to determine if an URLRequest is eligible for offline previews. |
| 100 previews::PreviewsDecider* previews_decider_; | 107 previews::PreviewsDecider* previews_decider_; |
| 101 | 108 |
| 109 // Was this job started as an offline preview. |
| 110 bool was_started_as_preview_; |
| 111 |
| 102 base::WeakPtrFactory<OfflinePageRequestJob> weak_ptr_factory_; | 112 base::WeakPtrFactory<OfflinePageRequestJob> weak_ptr_factory_; |
| 103 | 113 |
| 104 DISALLOW_COPY_AND_ASSIGN(OfflinePageRequestJob); | 114 DISALLOW_COPY_AND_ASSIGN(OfflinePageRequestJob); |
| 105 }; | 115 }; |
| 106 | 116 |
| 107 } // namespace offline_pages | 117 } // namespace offline_pages |
| 108 | 118 |
| 109 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_OFFLINE_PAGE_REQUEST_JOB_H_ | 119 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_OFFLINE_PAGE_REQUEST_JOB_H_ |
| OLD | NEW |