Chromium Code Reviews| Index: components/offline_pages/request_header/offline_page_header.h |
| diff --git a/components/offline_pages/request_header/offline_page_header.h b/components/offline_pages/request_header/offline_page_header.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f7b0e562f744d9668392fc7b791d6c055fd3a86b |
| --- /dev/null |
| +++ b/components/offline_pages/request_header/offline_page_header.h |
| @@ -0,0 +1,79 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef COMPONENTS_OFFLINE_PAGES_REQUEST_HEADER_OFFLINE_PAGE_HEADER_H_ |
| +#define COMPONENTS_OFFLINE_PAGES_REQUEST_HEADER_OFFLINE_PAGE_HEADER_H_ |
| + |
| +#include <string> |
| + |
| +namespace offline_pages { |
| + |
| +// Header that defines the custom behavior to load offline pages. Its value is a |
| +// comma/space separated name-value pair. |
| +extern const char kOfflinePageHeader[]; |
| + |
| +// The name used in name-value pair of kOfflinePageHeader to tell if the offline |
| +// info in this header should be persisted across session restore. |
| +extern const char kOfflinePageHeaderPersistKey[]; |
| + |
| +// The name used in name-value pair of kOfflinePageHeader to denote the reason |
| +// for loading offline page. |
| +extern const char kOfflinePageHeaderReasonKey[]; |
| +// Possible values in name-value pair that denote the reason for loading offline |
| +// page. |
| +// The offline page should be loaded even when the network is connected. This is |
| +// because the live version failed to load due to certain net error. |
| +extern const char kOfflinePageHeaderReasonValueDueToNetError[]; |
| +// The offline page should be loaded because the user clicks to open the |
| +// downloaded page explicitly. |
| +extern const char kOfflinePageHeaderReasonValueFromDownload[]; |
| +// This only happens after the offline page is loaded due to above reason and |
| +// then the user reload current page. The network condition should be checked |
| +// this time to decide if a live version should be tried again. |
| +extern const char kOfflinePageHeaderReasonValueReload[]; |
| + |
| +// The name used in name-value pair of kOfflinePageHeader to denote the offline |
| +// ID of the offline page to load. |
| +extern const char kOfflinePageHeaderIDKey[]; |
| + |
| +// Used to parse the extra request header string that defines offline page |
| +// loading behaviors. |
| +struct OfflinePageHeader { |
| + public: |
| + enum class Reason { |
| + NONE, |
| + NET_ERROR, |
| + DOWNLOAD, |
| + RELOAD |
| + }; |
| + |
| + OfflinePageHeader(); |
| + |
| + // 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.
|
| + explicit OfflinePageHeader(const std::string& header_value); |
| + |
| + ~OfflinePageHeader(); |
| + |
| + // Returns the full header string, including both key and value, that could be |
| + // passed to set extra request header. |
| + std::string GetCompleteHeaderString() const; |
| + |
| + void Clear(); |
| + |
| + // Returns false if failed to construct from a request header value string. |
| + 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.
|
| + |
| + // Flag to indicate if the header should be persisted across session restore. |
| + bool need_to_persist; |
| + |
| + // Describes the reason to load offline page. |
| + Reason reason; |
| + |
| + // The offline ID of the page to load. |
| + std::string id; |
| +}; |
| + |
| +} // namespace offline_pages |
| + |
| +#endif // COMPONENTS_OFFLINE_PAGES_REQUEST_HEADER_OFFLINE_PAGE_HEADER_H_ |