| 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 offline_pages { | 19 namespace offline_pages { |
| 20 struct OfflinePageHeader; |
| 21 struct OfflinePageItem; |
| 18 | 22 |
| 19 // A request job that serves content from offline file. | 23 // A request job that serves content from offline file. |
| 20 class OfflinePageRequestJob : public net::URLRequestFileJob { | 24 class OfflinePageRequestJob : public net::URLRequestFileJob { |
| 21 public: | 25 public: |
| 22 // This enum is used for UMA reporting. It contains all possible outcomes of | 26 // This enum is used for UMA reporting. It contains all possible outcomes of |
| 23 // handling requests that might service offline page in different network | 27 // handling requests that might service offline page in different network |
| 24 // conditions. Generally one of these outcomes will happen. | 28 // conditions. Generally one of these outcomes will happen. |
| 25 // The fringe errors (like no OfflinePageModel, etc.) are not reported due | 29 // The fringe errors (like no OfflinePageModel, etc.) are not reported due |
| 26 // to their low probability. | 30 // to their low probability. |
| 27 // NOTE: because this is used for UMA reporting, these values should not be | 31 // NOTE: because this is used for UMA reporting, these values should not be |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 // offline page cannot or should not be served. | 70 // offline page cannot or should not be served. |
| 67 static OfflinePageRequestJob* Create(net::URLRequest* request, | 71 static OfflinePageRequestJob* Create(net::URLRequest* request, |
| 68 net::NetworkDelegate* network_delegate); | 72 net::NetworkDelegate* network_delegate); |
| 69 | 73 |
| 70 ~OfflinePageRequestJob() override; | 74 ~OfflinePageRequestJob() override; |
| 71 | 75 |
| 72 // net::URLRequestJob overrides: | 76 // net::URLRequestJob overrides: |
| 73 void Start() override; | 77 void Start() override; |
| 74 void Kill() override; | 78 void Kill() override; |
| 75 | 79 |
| 76 void OnOfflineFilePathAvailable(const base::FilePath& offline_file_path); | 80 void OnOfflineFilePathAvailable( |
| 81 const base::FilePath& offline_file_path, |
| 82 std::unique_ptr<OfflinePageHeader> offline_header, |
| 83 std::unique_ptr<OfflinePageItem> offline_page); |
| 77 | 84 |
| 78 void SetDelegateForTesting(std::unique_ptr<Delegate> delegate); | 85 void SetDelegateForTesting(std::unique_ptr<Delegate> delegate); |
| 79 | 86 |
| 80 private: | 87 private: |
| 81 OfflinePageRequestJob(net::URLRequest* request, | 88 OfflinePageRequestJob(net::URLRequest* request, |
| 82 net::NetworkDelegate* network_delegate); | 89 net::NetworkDelegate* network_delegate); |
| 83 | 90 |
| 84 void StartAsync(); | 91 void StartAsync(); |
| 85 | 92 |
| 86 // Restarts the request job in order to fall back to the default handling. | 93 // Restarts the request job in order to fall back to the default handling. |
| 87 void FallbackToDefault(); | 94 void FallbackToDefault(); |
| 88 | 95 |
| 89 std::unique_ptr<Delegate> delegate_; | 96 std::unique_ptr<Delegate> delegate_; |
| 90 | 97 |
| 98 bool was_started_as_preview_; |
| 99 |
| 91 base::WeakPtrFactory<OfflinePageRequestJob> weak_ptr_factory_; | 100 base::WeakPtrFactory<OfflinePageRequestJob> weak_ptr_factory_; |
| 92 | 101 |
| 93 DISALLOW_COPY_AND_ASSIGN(OfflinePageRequestJob); | 102 DISALLOW_COPY_AND_ASSIGN(OfflinePageRequestJob); |
| 94 }; | 103 }; |
| 95 | 104 |
| 96 } // namespace offline_pages | 105 } // namespace offline_pages |
| 97 | 106 |
| 98 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_OFFLINE_PAGE_REQUEST_JOB_H_ | 107 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_OFFLINE_PAGE_REQUEST_JOB_H_ |
| OLD | NEW |