| 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 offline_pages { | 17 namespace offline_pages { |
| 18 | 18 |
| 19 // Header that indicates that the offline page should be loaded if it exists | 19 // Header that indicates that the offline page should be loaded if it exists |
| 20 // regardless current network conditions. Its value is a comma/space separated | 20 // regardless current network conditions. Its value is a comma/space separated |
| 21 // name-value pair that may provide reason or define custom behavior. | 21 // name-value pair that may provide reason or define custom behavior. |
| 22 extern const char kLoadingOfflinePageHeader[]; | 22 extern const char kOfflinePageHeader[]; |
| 23 // The name used in name-value pair of kLoadingOfflinePageHeader to denote the | 23 // The name used in name-value pair of kOfflinePageHeader to tell if the offline |
| 24 // reason for loading offline page. | 24 // info in this header should be persisted across session restore. |
| 25 extern const char kLoadingOfflinePageReason[]; | 25 extern const char kOfflinePageHeaderPersistKey[]; |
| 26 // The name used in name-value pair of kOfflinePageHeader to denote the reason |
| 27 // for loading offline page. |
| 28 extern const char kOfflinePageHeaderReasonKey[]; |
| 26 // Possible values in name-value pair that denote the reason for loading offline | 29 // Possible values in name-value pair that denote the reason for loading offline |
| 27 // page. | 30 // page. |
| 28 extern const char kLoadingOfflinePageDueToNetError[]; | 31 extern const char kOfflinePageHeaderReasonValueDueToNetError[]; |
| 32 extern const char kOfflinePageHeaderReasonValueFromDownload[]; |
| 33 // The name used in name-value pair of kOfflinePageHeader to denote the offline |
| 34 // ID of the offline page to load. |
| 35 extern const char kOfflinePageHeaderIDKey[]; |
| 29 | 36 |
| 30 // A request job that serves content from offline file. | 37 // A request job that serves content from offline file. |
| 31 class OfflinePageRequestJob : public net::URLRequestFileJob { | 38 class OfflinePageRequestJob : public net::URLRequestFileJob { |
| 32 public: | 39 public: |
| 33 // This enum is used for UMA reporting. It contains all possible outcomes of | 40 // This enum is used for UMA reporting. It contains all possible outcomes of |
| 34 // handling requests that might service offline page in different network | 41 // handling requests that might service offline page in different network |
| 35 // conditions. Generally one of these outcomes will happen. | 42 // conditions. Generally one of these outcomes will happen. |
| 36 // The fringe errors (like no OfflinePageModel, etc.) are not reported due | 43 // The fringe errors (like no OfflinePageModel, etc.) are not reported due |
| 37 // to their low probability. | 44 // to their low probability. |
| 38 // NOTE: because this is used for UMA reporting, these values should not be | 45 // NOTE: because this is used for UMA reporting, these values should not be |
| (...skipping 29 matching lines...) Expand all Loading... |
| 68 | 75 |
| 69 virtual TabIdGetter GetTabIdGetter() const = 0; | 76 virtual TabIdGetter GetTabIdGetter() const = 0; |
| 70 }; | 77 }; |
| 71 | 78 |
| 72 // Reports the aggregated result combining both request result and network | 79 // Reports the aggregated result combining both request result and network |
| 73 // state. | 80 // state. |
| 74 static void ReportAggregatedRequestResult(AggregatedRequestResult result); | 81 static void ReportAggregatedRequestResult(AggregatedRequestResult result); |
| 75 | 82 |
| 76 // Creates and returns a job to serve the offline page. Nullptr is returned if | 83 // Creates and returns a job to serve the offline page. Nullptr is returned if |
| 77 // offline page cannot or should not be served. | 84 // offline page cannot or should not be served. |
| 78 static OfflinePageRequestJob* Create(void* profile_id, | 85 static OfflinePageRequestJob* Create(net::URLRequest* request, |
| 79 net::URLRequest* request, | |
| 80 net::NetworkDelegate* network_delegate); | 86 net::NetworkDelegate* network_delegate); |
| 81 | 87 |
| 82 ~OfflinePageRequestJob() override; | 88 ~OfflinePageRequestJob() override; |
| 83 | 89 |
| 84 // net::URLRequestJob overrides: | 90 // net::URLRequestJob overrides: |
| 85 void Start() override; | 91 void Start() override; |
| 86 void Kill() override; | 92 void Kill() override; |
| 87 | 93 |
| 88 void OnOfflineFilePathAvailable(const base::FilePath& offline_file_path); | 94 void OnOfflineFilePathAvailable(const base::FilePath& offline_file_path); |
| 89 | 95 |
| 90 void SetDelegateForTesting(std::unique_ptr<Delegate> delegate); | 96 void SetDelegateForTesting(std::unique_ptr<Delegate> delegate); |
| 91 | 97 |
| 92 private: | 98 private: |
| 93 OfflinePageRequestJob(void* profile_id, | 99 OfflinePageRequestJob(net::URLRequest* request, |
| 94 net::URLRequest* request, | |
| 95 net::NetworkDelegate* network_delegate); | 100 net::NetworkDelegate* network_delegate); |
| 96 | 101 |
| 97 void StartAsync(); | 102 void StartAsync(); |
| 98 | 103 |
| 99 // Restarts the request job in order to fall back to the default handling. | 104 // Restarts the request job in order to fall back to the default handling. |
| 100 void FallbackToDefault(); | 105 void FallbackToDefault(); |
| 101 | 106 |
| 102 // The profile for processing offline pages. | |
| 103 void* profile_id_; | |
| 104 | |
| 105 std::unique_ptr<Delegate> delegate_; | 107 std::unique_ptr<Delegate> delegate_; |
| 106 | 108 |
| 107 base::WeakPtrFactory<OfflinePageRequestJob> weak_ptr_factory_; | 109 base::WeakPtrFactory<OfflinePageRequestJob> weak_ptr_factory_; |
| 108 | 110 |
| 109 DISALLOW_COPY_AND_ASSIGN(OfflinePageRequestJob); | 111 DISALLOW_COPY_AND_ASSIGN(OfflinePageRequestJob); |
| 110 }; | 112 }; |
| 111 | 113 |
| 112 } // namespace offline_pages | 114 } // namespace offline_pages |
| 113 | 115 |
| 114 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_OFFLINE_PAGE_REQUEST_JOB_H_ | 116 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_OFFLINE_PAGE_REQUEST_JOB_H_ |
| OLD | NEW |