Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(136)

Side by Side Diff: components/offline_pages/offline_page_metadata_store.h

Issue 2353393002: [Offline pages] Extracting and templatizing types for store callbacks (Closed)
Patch Set: Removing offline_store_types_impl.h Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include "components/offline_pages/offline_page_item.h"
14 #include "components/offline_pages/offline_page_types.h" 14 #include "components/offline_pages/offline_store_types.h"
15 15
16 class GURL; 16 class GURL;
17 17
18 namespace offline_pages { 18 namespace offline_pages {
19 19
20 // TODO(fgorski): This enum is meant to replace |LoadStatus|. 20 typedef StoreUpdateResult<OfflinePageItem> OfflinePagesUpdateResult;
21 // Current store state. When LOADED, the store is operational. When
22 // initialization or reset fails, it is reflected appropriately.
23 enum class StoreState {
24 NOT_LOADED, // Store is not loaded yet.
25 LOADED, // Store is properly loaded and operational.
26 FAILED_LOADING, // Store initialization failed.
27 FAILED_RESET, // Resetting the store failed.
28 };
29
30 class StoreUpdateResult {
31 public:
32 explicit StoreUpdateResult(StoreState state);
33 ~StoreUpdateResult();
34
35 // List of Offline ID to item action status mappings.
36 // It is meant to be consumed by the original caller of the operation.
37 std::vector<std::pair<int64_t, ItemActionStatus>> item_statuses;
38
39 // List of successfully updated offline page items as seen after operation
40 // concludes. It is meant to be used when passing to the observers.
41 std::vector<OfflinePageItem> updated_items;
42
43 // State of the store after the operation is done.
44 StoreState store_state;
45 };
46 21
47 // OfflinePageMetadataStore keeps metadata for the offline pages. 22 // OfflinePageMetadataStore keeps metadata for the offline pages.
48 // Ability to create multiple instances of the store as well as behavior of 23 // Ability to create multiple instances of the store as well as behavior of
49 // asynchronous operations when the object is being destroyed, before such 24 // asynchronous operations when the object is being destroyed, before such
50 // operation finishes will depend on implementation. It should be possible to 25 // operation finishes will depend on implementation. It should be possible to
51 // issue multiple asynchronous operations in parallel. 26 // issue multiple asynchronous operations in parallel.
52 class OfflinePageMetadataStore { 27 class OfflinePageMetadataStore {
53 public: 28 public:
54 // This enum is used in an UMA histogram. Hence the entries here shouldn't 29 // This enum is used in an UMA histogram. Hence the entries here shouldn't
55 // be deleted or re-ordered and new ones should be added to the end. 30 // be deleted or re-ordered and new ones should be added to the end.
56 enum LoadStatus { 31 enum LoadStatus {
57 LOAD_SUCCEEDED, 32 LOAD_SUCCEEDED,
58 STORE_INIT_FAILED, 33 STORE_INIT_FAILED,
59 STORE_LOAD_FAILED, 34 STORE_LOAD_FAILED,
60 DATA_PARSING_FAILED, 35 DATA_PARSING_FAILED,
61 36
62 // NOTE: always keep this entry at the end. 37 // NOTE: always keep this entry at the end.
63 LOAD_STATUS_COUNT 38 LOAD_STATUS_COUNT
64 }; 39 };
65 40
66 typedef base::Callback<void(LoadStatus, const std::vector<OfflinePageItem>&)> 41 typedef base::Callback<void(LoadStatus, const std::vector<OfflinePageItem>&)>
67 LoadCallback; 42 LoadCallback;
68 typedef base::Callback<void(ItemActionStatus)> AddCallback; 43 typedef base::Callback<void(ItemActionStatus)> AddCallback;
69 typedef base::Callback<void(std::unique_ptr<StoreUpdateResult>)> 44 typedef base::Callback<void(std::unique_ptr<OfflinePagesUpdateResult>)>
70 UpdateCallback; 45 UpdateCallback;
71 typedef base::Callback<void(bool)> ResetCallback; 46 typedef base::Callback<void(bool)> ResetCallback;
72 47
73 OfflinePageMetadataStore(); 48 OfflinePageMetadataStore();
74 virtual ~OfflinePageMetadataStore(); 49 virtual ~OfflinePageMetadataStore();
75 50
76 // Get all of the offline pages from the store. 51 // Get all of the offline pages from the store.
77 virtual void GetOfflinePages(const LoadCallback& callback) = 0; 52 virtual void GetOfflinePages(const LoadCallback& callback) = 0;
78 53
79 // Asynchronously adds an offline page item metadata to the store. 54 // Asynchronously adds an offline page item metadata to the store.
(...skipping 12 matching lines...) Expand all
92 // Resets the store. 67 // Resets the store.
93 virtual void Reset(const ResetCallback& callback) = 0; 68 virtual void Reset(const ResetCallback& callback) = 0;
94 69
95 // Gets the store state. 70 // Gets the store state.
96 virtual StoreState state() const = 0; 71 virtual StoreState state() const = 0;
97 }; 72 };
98 73
99 } // namespace offline_pages 74 } // namespace offline_pages
100 75
101 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_METADATA_STORE_H_ 76 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_METADATA_STORE_H_
OLDNEW
« no previous file with comments | « components/offline_pages/background/request_queue_store.h ('k') | components/offline_pages/offline_page_metadata_store.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698