| 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 "base/memory/weak_ptr.h" | 8 #include "base/memory/weak_ptr.h" |
| 9 #include "content/public/browser/resource_request_info.h" | 9 #include "content/public/browser/resource_request_info.h" |
| 10 #include "content/public/common/resource_type.h" | 10 #include "content/public/common/resource_type.h" |
| 11 #include "net/url_request/url_request_file_job.h" | 11 #include "net/url_request/url_request_file_job.h" |
| 12 | 12 |
| 13 namespace base { | 13 namespace base { |
| 14 class FilePath; | 14 class FilePath; |
| 15 } | 15 } |
| 16 | 16 |
| 17 namespace previews { |
| 18 class PreviewsDecider; |
| 19 } |
| 20 |
| 17 namespace offline_pages { | 21 namespace offline_pages { |
| 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. |
| (...skipping 29 matching lines...) Expand all Loading... |
| 56 GetWebContentsGetter(net::URLRequest* request) const = 0; | 60 GetWebContentsGetter(net::URLRequest* request) const = 0; |
| 57 | 61 |
| 58 virtual TabIdGetter GetTabIdGetter() const = 0; | 62 virtual TabIdGetter GetTabIdGetter() const = 0; |
| 59 }; | 63 }; |
| 60 | 64 |
| 61 // Reports the aggregated result combining both request result and network | 65 // Reports the aggregated result combining both request result and network |
| 62 // state. | 66 // state. |
| 63 static void ReportAggregatedRequestResult(AggregatedRequestResult result); | 67 static void ReportAggregatedRequestResult(AggregatedRequestResult result); |
| 64 | 68 |
| 65 // Creates and returns a job to serve the offline page. Nullptr is returned if | 69 // Creates and returns a job to serve the offline page. Nullptr is returned if |
| 66 // offline page cannot or should not be served. | 70 // offline page cannot or should not be served. Embedder must gaurantee that |
| 67 static OfflinePageRequestJob* Create(net::URLRequest* request, | 71 // |previews_decider| outlives the returned instance. |
| 68 net::NetworkDelegate* network_delegate); | 72 static OfflinePageRequestJob* Create( |
| 73 net::URLRequest* request, |
| 74 net::NetworkDelegate* network_delegate, |
| 75 previews::PreviewsDecider* previews_decider); |
| 69 | 76 |
| 70 ~OfflinePageRequestJob() override; | 77 ~OfflinePageRequestJob() override; |
| 71 | 78 |
| 72 // net::URLRequestJob overrides: | 79 // net::URLRequestJob overrides: |
| 73 void Start() override; | 80 void Start() override; |
| 74 void Kill() override; | 81 void Kill() override; |
| 75 | 82 |
| 76 void OnOfflineFilePathAvailable(const base::FilePath& offline_file_path); | 83 void OnOfflineFilePathAvailable(const base::FilePath& offline_file_path); |
| 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, |
| 90 previews::PreviewsDecider* previews_decider); |
| 83 | 91 |
| 84 void StartAsync(); | 92 void StartAsync(); |
| 85 | 93 |
| 86 // Restarts the request job in order to fall back to the default handling. | 94 // Restarts the request job in order to fall back to the default handling. |
| 87 void FallbackToDefault(); | 95 void FallbackToDefault(); |
| 88 | 96 |
| 89 std::unique_ptr<Delegate> delegate_; | 97 std::unique_ptr<Delegate> delegate_; |
| 90 | 98 |
| 99 // Used to determine if an URLRequest is eligible for offline previews. |
| 100 previews::PreviewsDecider* previews_decider_; |
| 101 |
| 91 base::WeakPtrFactory<OfflinePageRequestJob> weak_ptr_factory_; | 102 base::WeakPtrFactory<OfflinePageRequestJob> weak_ptr_factory_; |
| 92 | 103 |
| 93 DISALLOW_COPY_AND_ASSIGN(OfflinePageRequestJob); | 104 DISALLOW_COPY_AND_ASSIGN(OfflinePageRequestJob); |
| 94 }; | 105 }; |
| 95 | 106 |
| 96 } // namespace offline_pages | 107 } // namespace offline_pages |
| 97 | 108 |
| 98 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_OFFLINE_PAGE_REQUEST_JOB_H_ | 109 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_OFFLINE_PAGE_REQUEST_JOB_H_ |
| OLD | NEW |