Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_METADATA_STORE_H_ | 5 #ifndef COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_METADATA_STORE_H_ |
| 6 #define COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_METADATA_STORE_H_ | 6 #define COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_METADATA_STORE_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "components/offline_pages/offline_page_item.h" | |
| 13 | 14 |
| 14 class GURL; | 15 class GURL; |
| 15 | 16 |
| 16 namespace offline_pages { | 17 namespace offline_pages { |
| 17 | 18 |
| 18 struct OfflinePageItem; | 19 // TODO(fgorski): This enum is meant to replace |LoadStatus|. |
| 20 // Current store state. When LOADED, the store is operational. When | |
| 21 // initialization or reset fails, it is reflected appropriately. | |
| 22 enum class StoreState { | |
| 23 NOT_LOADED, | |
| 24 LOADED, | |
| 25 FAILED_INITIALIZATION, | |
|
Dmitry Titov
2016/09/20 20:43:37
It would be goog to have those values documented.
fgorski
2016/09/20 22:15:02
Done.
| |
| 26 FAILED_RESET, | |
| 27 }; | |
| 28 | |
| 29 // Statuses referring to actions taken on items in the store. | |
| 30 enum class ItemActionStatus { | |
| 31 SUCCESS, | |
| 32 ALREADY_EXISTS, | |
| 33 DOESNT_EXIST, | |
|
Dmitry Titov
2016/09/20 20:43:37
Naming suggestion: DOESNT_EXIST -> NOT_FOUND?
fgorski
2016/09/20 22:15:02
Done.
| |
| 34 STORE_ERROR, | |
| 35 }; | |
| 36 | |
| 37 class StoreUpdateResult { | |
| 38 public: | |
| 39 explicit StoreUpdateResult(StoreState state); | |
| 40 ~StoreUpdateResult(); | |
| 41 | |
| 42 // List of Offline ID to item action status mappings. | |
| 43 // It is meant to be consumed by the original caller of the operation. | |
| 44 std::vector<std::pair<int64_t, ItemActionStatus>> item_statuses; | |
| 45 | |
| 46 // List of successfully updated offline page items as seen after operation | |
| 47 // concludes. It is meant to be used when passing to the observers. | |
| 48 std::vector<OfflinePageItem> updated_items; | |
| 49 | |
| 50 // State of the store after the operation is done. | |
| 51 StoreState store_state; | |
| 52 }; | |
| 19 | 53 |
| 20 // OfflinePageMetadataStore keeps metadata for the offline pages. | 54 // OfflinePageMetadataStore keeps metadata for the offline pages. |
| 21 // Ability to create multiple instances of the store as well as behavior of | 55 // Ability to create multiple instances of the store as well as behavior of |
| 22 // asynchronous operations when the object is being destroyed, before such | 56 // asynchronous operations when the object is being destroyed, before such |
| 23 // operation finishes will depend on implementation. It should be possible to | 57 // operation finishes will depend on implementation. It should be possible to |
| 24 // issue multiple asynchronous operations in parallel. | 58 // issue multiple asynchronous operations in parallel. |
| 25 class OfflinePageMetadataStore { | 59 class OfflinePageMetadataStore { |
| 26 public: | 60 public: |
| 27 // This enum is used in an UMA histogram. Hence the entries here shouldn't | 61 // This enum is used in an UMA histogram. Hence the entries here shouldn't |
| 28 // be deleted or re-ordered and new ones should be added to the end. | 62 // be deleted or re-ordered and new ones should be added to the end. |
| 29 enum LoadStatus { | 63 enum LoadStatus { |
| 30 LOAD_SUCCEEDED, | 64 LOAD_SUCCEEDED, |
| 31 STORE_INIT_FAILED, | 65 STORE_INIT_FAILED, |
| 32 STORE_LOAD_FAILED, | 66 STORE_LOAD_FAILED, |
| 33 DATA_PARSING_FAILED, | 67 DATA_PARSING_FAILED, |
| 34 | 68 |
| 35 // NOTE: always keep this entry at the end. | 69 // NOTE: always keep this entry at the end. |
| 36 LOAD_STATUS_COUNT | 70 LOAD_STATUS_COUNT |
| 37 }; | 71 }; |
| 38 | 72 |
| 39 // TODO(fgorski): This enum is meant to replace |LoadStatus|. | |
| 40 // Current store state. When LOADED, the store is operational. When | |
| 41 // initialization or reset fails, it is reflected appropriately. | |
| 42 enum StoreState { | |
| 43 NOT_LOADED, | |
| 44 LOADED, | |
| 45 FAILED_INITIALIZATION, | |
| 46 FAILED_RESET, | |
| 47 }; | |
| 48 | |
| 49 // Statuses referring to actions taken on items in the store. | |
| 50 enum ItemActionStatus { | |
| 51 SUCCESS, | |
| 52 ALREADY_EXISTS, | |
| 53 DOESNT_EXIST, | |
| 54 STORE_ERROR, | |
| 55 }; | |
| 56 | |
| 57 typedef base::Callback<void(LoadStatus, const std::vector<OfflinePageItem>&)> | 73 typedef base::Callback<void(LoadStatus, const std::vector<OfflinePageItem>&)> |
| 58 LoadCallback; | 74 LoadCallback; |
| 59 typedef base::Callback<void(ItemActionStatus)> AddCallback; | 75 typedef base::Callback<void(ItemActionStatus)> AddCallback; |
| 60 typedef base::Callback<void(bool)> UpdateCallback; | 76 typedef base::Callback<void(std::unique_ptr<StoreUpdateResult>)> |
| 77 UpdateCallback; | |
| 61 typedef base::Callback<void(bool)> ResetCallback; | 78 typedef base::Callback<void(bool)> ResetCallback; |
| 62 | 79 |
| 63 OfflinePageMetadataStore(); | 80 OfflinePageMetadataStore(); |
| 64 virtual ~OfflinePageMetadataStore(); | 81 virtual ~OfflinePageMetadataStore(); |
| 65 | 82 |
| 66 // Get all of the offline pages from the store. | 83 // Get all of the offline pages from the store. |
| 67 virtual void GetOfflinePages(const LoadCallback& callback) = 0; | 84 virtual void GetOfflinePages(const LoadCallback& callback) = 0; |
| 68 | 85 |
| 69 // Asynchronously adds an offline page item metadata to the store. | 86 // Asynchronously adds an offline page item metadata to the store. |
| 70 virtual void AddOfflinePage(const OfflinePageItem& offline_page, | 87 virtual void AddOfflinePage(const OfflinePageItem& offline_page, |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 82 // Resets the store. | 99 // Resets the store. |
| 83 virtual void Reset(const ResetCallback& callback) = 0; | 100 virtual void Reset(const ResetCallback& callback) = 0; |
| 84 | 101 |
| 85 // Gets the store state. | 102 // Gets the store state. |
| 86 virtual StoreState state() const = 0; | 103 virtual StoreState state() const = 0; |
| 87 }; | 104 }; |
| 88 | 105 |
| 89 } // namespace offline_pages | 106 } // namespace offline_pages |
| 90 | 107 |
| 91 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_METADATA_STORE_H_ | 108 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_METADATA_STORE_H_ |
| OLD | NEW |