Chromium Code Reviews| Index: chrome/browser/android/offline_pages/offline_page_request_handler.h |
| diff --git a/chrome/browser/android/offline_pages/offline_page_request_handler.h b/chrome/browser/android/offline_pages/offline_page_request_handler.h |
| index 350402899d25b40a2704c671ac3817d2a8851eb2..8ecab466f096f52677f160000082af73fa4c6222 100644 |
| --- a/chrome/browser/android/offline_pages/offline_page_request_handler.h |
| +++ b/chrome/browser/android/offline_pages/offline_page_request_handler.h |
| @@ -6,7 +6,10 @@ |
| #define CHROME_BROWSER_ANDROID_OFFLINE_PAGES_OFFLINE_PAGE_REQUEST_HANDLER_H_ |
| #include "base/macros.h" |
| +#include "base/memory/weak_ptr.h" |
| #include "base/supports_user_data.h" |
| +#include "chrome/browser/android/offline_pages/offline_page_request_job.h" |
| +#include "content/public/browser/resource_request_info.h" |
| #include "content/public/common/resource_type.h" |
| namespace net { |
| @@ -18,6 +21,62 @@ class URLRequestJob; |
| namespace offline_pages { |
| +// This enum is used to tell current network state that will affect offline |
| +// page loading. |
| +enum class NetworkState { |
| + // No network connection. |
| + DISCONNECTED_NETWORK, |
| + // Prohibitively slow means that the NetworkQualityEstimator reported a |
| + // connection slow enough to warrant showing an offline page if available. |
| + PROHIBITIVELY_SLOW_NETWORK, |
| + // Network error received due to bad network, i.e. connected to a hotspot or |
| + // proxy that does not have a working network. |
| + FLAKY_NETWORK, |
| + // Network is in working condition. |
| + CONNECTED_NETWORK, |
| + // Network condition check will be skipped. This will force to load the |
| + // offline page if it is available. |
| + SKIPPED_NETWORK_CHECK |
| +}; |
| + |
| +// This enum is used for UMA reporting. It contains all possible outcomes of |
| +// handling requests that might service offline page in different network |
| +// conditions. Generally one of these outcomes will happen. |
| +// The fringe errors (like no OfflinePageModel, etc.) are not reported due |
| +// to their low probability. |
| +// NOTE: because this is used for UMA reporting, these values should not be |
| +// changed or reused; new values should be ended immediately before the MAX |
| +// value. Make sure to update the histogram enum |
| +// (OfflinePagesAggregatedRequestResult in histograms.xml) accordingly. |
| +// Public for testing. |
| +enum class AggregatedRequestResult { |
| + SHOW_OFFLINE_ON_DISCONNECTED_NETWORK, |
| + PAGE_NOT_FOUND_ON_DISCONNECTED_NETWORK, |
| + SHOW_OFFLINE_ON_FLAKY_NETWORK, |
| + PAGE_NOT_FOUND_ON_FLAKY_NETWORK, |
| + SHOW_OFFLINE_ON_PROHIBITIVELY_SLOW_NETWORK, |
| + PAGE_NOT_FOUND_ON_PROHIBITIVELY_SLOW_NETWORK, |
| + PAGE_NOT_FRESH_ON_PROHIBITIVELY_SLOW_NETWORK, |
| + SHOW_OFFLINE_ON_CONNECTED_NETWORK, |
| + PAGE_NOT_FOUND_ON_CONNECTED_NETWORK, |
| + NO_TAB_ID, |
| + NO_WEB_CONTENTS, |
| + SHOW_NET_ERROR_PAGE, |
| + AGGREGATED_REQUEST_RESULT_MAX, |
|
fgorski
2016/08/15 21:38:32
nit: add a comment that new values are added above
jianli
2016/08/15 23:15:43
Such comment is already added at line 48.
|
| +}; |
| + |
| +// Header that indicates that the offline page should be loaded if it exists |
| +// regardless current network conditions. Its value is a comma/space separated |
| +// name-value pair that may provide reason or define custom behavior. |
| +extern const char kLoadingOfflinePageHeader[]; |
| + |
| +// The name used in name-value pair of kLoadingOfflinePageHeader to denote the |
| +// reason for loading offline page. |
| +extern const char kLoadingOfflinePageReason[]; |
| +// Possible values in name-value pair that denote the reason for loading offline |
| +// page. |
| +extern const char kLoadingOfflinePageDueToNetError[]; |
| + |
| // Class for servicing requests based on their offline information. Created one |
| // per URLRequest and attached to each request. |
| // |
| @@ -37,7 +96,8 @@ namespace offline_pages { |
| // 2.1.3) Return a custom URLRequestJob that is put on hold to wait |
| // for the result of finding offline page. |
| // 2.2) Otherwise, bail out without interception. |
| -class OfflinePageRequestHandler : public base::SupportsUserData::Data { |
| +class OfflinePageRequestHandler : public base::SupportsUserData::Data, |
| + public OfflinePageRequestJob::Delegate { |
| public: |
| // Attaches a newly created handler if the given |request| needs to |
| // be handled by offline pages. |
| @@ -55,15 +115,37 @@ class OfflinePageRequestHandler : public base::SupportsUserData::Data { |
| static std::unique_ptr<net::URLRequestInterceptor> CreateInterceptor( |
| void* profile_id); |
| + static void ReportAggregatedRequestResult(AggregatedRequestResult result); |
| + |
| ~OfflinePageRequestHandler() override; |
| + // OfflinePageRequestJob::Delegate overrides: |
| + void OnPrepareToRestart() override; |
| + |
| net::URLRequestJob* MaybeCreateJob( |
| net::URLRequest* request, |
| net::NetworkDelegate* network_delegate, |
| void* profile_id); |
| private: |
| - OfflinePageRequestHandler(); |
| + explicit OfflinePageRequestHandler(NetworkState network_state); |
| + |
| + // Invoked from UI thread. |
| + void GetOfflineFileURL( |
| + const GURL& online_url, |
| + void* profile_id, |
| + content::ResourceRequestInfo::WebContentsGetter web_contents_getter); |
| + void FailedToGetOfflineFileURL(); |
| + |
| + base::WeakPtr<OfflinePageRequestJob> offline_job_; |
| + |
| + // True if the next time this request is started, the request should be |
| + // serviced from the default handler. |
| + bool use_default_ = false; |
| + |
| + NetworkState network_state_; |
| + |
| + base::WeakPtrFactory<OfflinePageRequestHandler> weak_ptr_factory_; |
| DISALLOW_COPY_AND_ASSIGN(OfflinePageRequestHandler); |
| }; |