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_JOB_H_ |
| 6 #define CHROME_BROWSER_ANDROID_OFFLINE_PAGES_OFFLINE_PAGE_REQUEST_JOB_H_ |
| 7 |
| 8 #include "base/memory/weak_ptr.h" |
| 9 #include "content/public/common/resource_type.h" |
| 10 #include "net/url_request/url_request_file_job.h" |
| 11 |
| 12 namespace base { |
| 13 class FilePath; |
| 14 } |
| 15 |
| 16 namespace offline_pages { |
| 17 |
| 18 // This enum is used for UMA reporting. It contains all possible outcomes of |
| 19 // handling requests that might service offline page in different network |
| 20 // conditions. Generally one of these outcomes will happen. |
| 21 // The fringe errors (like no OfflinePageModel, etc.) are not reported due |
| 22 // to their low probability. |
| 23 // NOTE: because this is used for UMA reporting, these values should not be |
| 24 // changed or reused; new values should be ended immediately before the MAX |
| 25 // value. Make sure to update the histogram enum |
| 26 // (OfflinePagesAggregatedRequestResult in histograms.xml) accordingly. |
| 27 // Public for testing. |
| 28 enum class AggregatedRequestResult { |
| 29 SHOW_OFFLINE_ON_DISCONNECTED_NETWORK, |
| 30 PAGE_NOT_FOUND_ON_DISCONNECTED_NETWORK, |
| 31 SHOW_OFFLINE_ON_FLAKY_NETWORK, |
| 32 PAGE_NOT_FOUND_ON_FLAKY_NETWORK, |
| 33 SHOW_OFFLINE_ON_PROHIBITIVELY_SLOW_NETWORK, |
| 34 PAGE_NOT_FOUND_ON_PROHIBITIVELY_SLOW_NETWORK, |
| 35 PAGE_NOT_FRESH_ON_PROHIBITIVELY_SLOW_NETWORK, |
| 36 SHOW_OFFLINE_ON_CONNECTED_NETWORK, |
| 37 PAGE_NOT_FOUND_ON_CONNECTED_NETWORK, |
| 38 NO_TAB_ID, |
| 39 NO_WEB_CONTENTS, |
| 40 SHOW_NET_ERROR_PAGE, |
| 41 AGGREGATED_REQUEST_RESULT_MAX |
| 42 }; |
| 43 |
| 44 // Header that indicates that the offline page should be loaded if it exists |
| 45 // regardless current network conditions. Its value is a comma/space separated |
| 46 // name-value pair that may provide reason or define custom behavior. |
| 47 extern const char kLoadingOfflinePageHeader[]; |
| 48 // The name used in name-value pair of kLoadingOfflinePageHeader to denote the |
| 49 // reason for loading offline page. |
| 50 extern const char kLoadingOfflinePageReason[]; |
| 51 // Possible values in name-value pair that denote the reason for loading offline |
| 52 // page. |
| 53 extern const char kLoadingOfflinePageDueToNetError[]; |
| 54 |
| 55 // A request job that serves content from offline file. |
| 56 class OfflinePageRequestJob : public net::URLRequestFileJob { |
| 57 public: |
| 58 // Reports the aggregated result combining both request result and network |
| 59 // state. |
| 60 static void ReportAggregatedRequestResult(AggregatedRequestResult result); |
| 61 |
| 62 // Creates and stores the |OfflinePageRequestInfo| data in |request|. |
| 63 static void SetOfflinePageRequestInfoForRequest( |
| 64 net::URLRequest* request, content::ResourceType resource_type); |
| 65 |
| 66 // Creates and returns a job to serve the offline page. Nullptr is returned if |
| 67 // offline page cannot be served. |
| 68 static OfflinePageRequestJob* Create(void* profile_id, |
| 69 net::URLRequest* request, |
| 70 net::NetworkDelegate* network_delegate); |
| 71 |
| 72 ~OfflinePageRequestJob() override; |
| 73 |
| 74 // net::URLRequestJob overrides: |
| 75 void Start() override; |
| 76 void Kill() override; |
| 77 |
| 78 void OnOfflineFilePathAvailable(const base::FilePath& offline_file_path); |
| 79 |
| 80 private: |
| 81 OfflinePageRequestJob(void* profile_id, |
| 82 net::URLRequest* request, |
| 83 net::NetworkDelegate* network_delegate); |
| 84 |
| 85 void StartAsync(); |
| 86 |
| 87 // Restarts the request job in order to fall back to the default handling. |
| 88 void FallbackToDefault(); |
| 89 |
| 90 // The profile for processing offline pages. |
| 91 void* profile_id_; |
| 92 |
| 93 base::WeakPtrFactory<OfflinePageRequestJob> weak_ptr_factory_; |
| 94 |
| 95 DISALLOW_COPY_AND_ASSIGN(OfflinePageRequestJob); |
| 96 }; |
| 97 |
| 98 } // namespace offline_pages |
| 99 |
| 100 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_OFFLINE_PAGE_REQUEST_JOB_H_ |
OLD | NEW |