Chromium Code Reviews| 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. | |
|
Dmitry Titov
2016/09/17 02:22:54
Please add comment here that if parse fails it's e
jianli
2016/09/19 21:29:05
Done.
| |
| 54 explicit OfflinePageHeader(const std::string& header_value); | |
| 55 | |
| 56 ~OfflinePageHeader(); | |
| 57 | |
| 58 // Returns the full header string, including both key and value, that could be | |
| 59 // passed to set extra request header. | |
| 60 std::string GetCompleteHeaderString() const; | |
| 61 | |
| 62 void Clear(); | |
| 63 | |
| 64 // Returns false if failed to construct from a request header value string. | |
| 65 bool is_valid; | |
|
Dmitry Titov
2016/09/17 02:22:54
This is only useful for tests, to see if parsing f
jianli
2016/09/19 21:29:05
Done.
| |
| 66 | |
| 67 // Flag to indicate if the header should be persisted across session restore. | |
| 68 bool need_to_persist; | |
| 69 | |
| 70 // Describes the reason to load offline page. | |
| 71 Reason reason; | |
| 72 | |
| 73 // The offline ID of the page to load. | |
| 74 std::string id; | |
| 75 }; | |
| 76 | |
| 77 } // namespace offline_pages | |
| 78 | |
| 79 #endif // COMPONENTS_OFFLINE_PAGES_REQUEST_HEADER_OFFLINE_PAGE_HEADER_H_ | |
| OLD | NEW |