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 returns a job to serve the offline page. Nullptr is returned if | |
63 // offline page cannot be served. | |
Dmitry Titov
2016/08/20 01:08:14
"cannot or should not be served" would better desc
jianli
2016/08/20 01:48:52
Done.
| |
64 static OfflinePageRequestJob* Create(void* profile_id, | |
65 net::URLRequest* request, | |
66 net::NetworkDelegate* network_delegate); | |
67 | |
68 ~OfflinePageRequestJob() override; | |
69 | |
70 // net::URLRequestJob overrides: | |
71 void Start() override; | |
72 void Kill() override; | |
73 | |
74 void OnOfflineFilePathAvailable(const base::FilePath& offline_file_path); | |
75 | |
76 private: | |
77 OfflinePageRequestJob(void* profile_id, | |
78 net::URLRequest* request, | |
79 net::NetworkDelegate* network_delegate); | |
80 | |
81 void StartAsync(); | |
82 | |
83 // Restarts the request job in order to fall back to the default handling. | |
84 void FallbackToDefault(); | |
85 | |
86 // The profile for processing offline pages. | |
87 void* profile_id_; | |
88 | |
89 base::WeakPtrFactory<OfflinePageRequestJob> weak_ptr_factory_; | |
90 | |
91 DISALLOW_COPY_AND_ASSIGN(OfflinePageRequestJob); | |
92 }; | |
93 | |
94 } // namespace offline_pages | |
95 | |
96 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_OFFLINE_PAGE_REQUEST_JOB_H_ | |
OLD | NEW |