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 COMPONENTS_OFFLINE_PAGES_REQUEST_HEADER_OFFLINE_PAGE_HEADER_H_ | |
6 #define COMPONENTS_OFFLINE_PAGES_REQUEST_HEADER_OFFLINE_PAGE_HEADER_H_ | |
7 | |
8 #include <string> | |
9 | |
10 namespace offline_pages { | |
11 | |
12 // Header that defines the custom behavior to load offline pages. Its value is a | |
13 // comma/space separated name-value pair. | |
14 extern const char kOfflinePageHeader[]; | |
15 | |
16 // The name used in name-value pair of kOfflinePageHeader to tell if the offline | |
17 // info in this header should be persisted across session restore. | |
18 extern const char kOfflinePageHeaderPersistKey[]; | |
19 | |
20 // The name used in name-value pair of kOfflinePageHeader to denote the reason | |
21 // for loading offline page. | |
22 extern const char kOfflinePageHeaderReasonKey[]; | |
23 // Possible values in name-value pair that denote the reason for loading offline | |
24 // page. | |
25 // The offline page should be loaded even when the network is connected. This is | |
26 // because the live version failed to load due to certain net error. | |
27 extern const char kOfflinePageHeaderReasonValueDueToNetError[]; | |
28 // The offline page should be loaded because the user clicks to open the | |
29 // downloaded page explicitly. | |
30 extern const char kOfflinePageHeaderReasonValueFromDownload[]; | |
31 // This only happens after the offline page is loaded due to above reason and | |
32 // then the user reload current page. The network condition should be checked | |
33 // this time to decide if a live version should be tried again. | |
34 extern const char kOfflinePageHeaderReasonValueReload[]; | |
35 | |
36 // The name used in name-value pair of kOfflinePageHeader to denote the offline | |
37 // ID of the offline page to load. | |
38 extern const char kOfflinePageHeaderIDKey[]; | |
39 | |
40 // Used to parse the extra request header string that defines offline page | |
41 // loading behaviors. | |
42 struct OfflinePageHeader { | |
43 public: | |
44 enum class Reason { | |
45 NONE, | |
46 NET_ERROR, | |
47 DOWNLOAD, | |
48 RELOAD | |
49 }; | |
50 | |
51 OfflinePageHeader(); | |
52 | |
53 // Constructed from a request header value string. | |
54 // The struct members will be cleared if the parsing failed. | |
55 explicit OfflinePageHeader(const std::string& header_value); | |
56 | |
57 ~OfflinePageHeader(); | |
58 | |
59 // Returns the full header string, including both key and value, that could be | |
60 // passed to set extra request header. | |
61 std::string GetCompleteHeaderString() const; | |
62 | |
63 void Clear(); | |
64 | |
65 // Set if failed to parse a request header value string. For testing only. | |
66 bool did_fail_parsing_for_test; | |
67 | |
68 // Flag to indicate if the header should be persisted across session restore. | |
69 bool need_to_persist; | |
70 | |
71 // Describes the reason to load offline page. | |
72 Reason reason; | |
73 | |
74 // The offline ID of the page to load. | |
75 std::string id; | |
76 }; | |
77 | |
78 } // namespace offline_pages | |
79 | |
80 #endif // COMPONENTS_OFFLINE_PAGES_REQUEST_HEADER_OFFLINE_PAGE_HEADER_H_ | |
OLD | NEW |