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

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

Issue 2343743002: [Offline pages] Updating the UpdateCallback in OPMStoreSQL (Closed)
Patch Set: Modifying the UpdateCallback, adding StoreUdpateResult 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 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,
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,
34 STORE_ERROR,
35 };
36
37 class StoreUpdateResult {
38 public:
39 explicit StoreUpdateResult(StoreState state);
40 ~StoreUpdateResult();
41
42 // TODO(fgorski): Consider adding a clear method.
43
44 // List of Offline ID to item action status mappings.
45 // It is meant to be consumed by the original caller of the operation.
46 std::vector<std::pair<int64_t, ItemActionStatus>> item_statuses;
dougarnett 2016/09/19 16:37:29 I still don't see the usefulness of including SUCC
fgorski 2016/09/19 23:24:30 I agree with you that there is certain information
dougarnett 2016/09/20 01:39:40 Perhaps my alternative wasn't clear, I was not pro
47
48 // List of update offline page items as seen after operation concludes.
dougarnett 2016/09/19 16:37:29 List of successfully updated ... ?
fgorski 2016/09/19 23:24:30 Done.
49 // It is meant to be used when passing to the observers.
50 std::vector<OfflinePageItem> updated_items;
51
52 // State of the store after the operation is done.
53 StoreState store_state;
54 };
19 55
20 // OfflinePageMetadataStore keeps metadata for the offline pages. 56 // OfflinePageMetadataStore keeps metadata for the offline pages.
21 // Ability to create multiple instances of the store as well as behavior of 57 // Ability to create multiple instances of the store as well as behavior of
22 // asynchronous operations when the object is being destroyed, before such 58 // asynchronous operations when the object is being destroyed, before such
23 // operation finishes will depend on implementation. It should be possible to 59 // operation finishes will depend on implementation. It should be possible to
24 // issue multiple asynchronous operations in parallel. 60 // issue multiple asynchronous operations in parallel.
25 class OfflinePageMetadataStore { 61 class OfflinePageMetadataStore {
26 public: 62 public:
27 // This enum is used in an UMA histogram. Hence the entries here shouldn't 63 // 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. 64 // be deleted or re-ordered and new ones should be added to the end.
29 enum LoadStatus { 65 enum LoadStatus {
30 LOAD_SUCCEEDED, 66 LOAD_SUCCEEDED,
31 STORE_INIT_FAILED, 67 STORE_INIT_FAILED,
32 STORE_LOAD_FAILED, 68 STORE_LOAD_FAILED,
33 DATA_PARSING_FAILED, 69 DATA_PARSING_FAILED,
34 70
35 // NOTE: always keep this entry at the end. 71 // NOTE: always keep this entry at the end.
36 LOAD_STATUS_COUNT 72 LOAD_STATUS_COUNT
37 }; 73 };
38 74
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>&)> 75 typedef base::Callback<void(LoadStatus, const std::vector<OfflinePageItem>&)>
58 LoadCallback; 76 LoadCallback;
59 typedef base::Callback<void(ItemActionStatus)> AddCallback; 77 typedef base::Callback<void(ItemActionStatus)> AddCallback;
60 typedef base::Callback<void(bool)> UpdateCallback; 78 typedef base::Callback<void(std::unique_ptr<StoreUpdateResult>)>
79 UpdateCallback;
61 typedef base::Callback<void(bool)> ResetCallback; 80 typedef base::Callback<void(bool)> ResetCallback;
62 81
63 OfflinePageMetadataStore(); 82 OfflinePageMetadataStore();
64 virtual ~OfflinePageMetadataStore(); 83 virtual ~OfflinePageMetadataStore();
65 84
66 // Get all of the offline pages from the store. 85 // Get all of the offline pages from the store.
67 virtual void GetOfflinePages(const LoadCallback& callback) = 0; 86 virtual void GetOfflinePages(const LoadCallback& callback) = 0;
68 87
69 // Asynchronously adds an offline page item metadata to the store. 88 // Asynchronously adds an offline page item metadata to the store.
70 virtual void AddOfflinePage(const OfflinePageItem& offline_page, 89 virtual void AddOfflinePage(const OfflinePageItem& offline_page,
(...skipping 11 matching lines...) Expand all
82 // Resets the store. 101 // Resets the store.
83 virtual void Reset(const ResetCallback& callback) = 0; 102 virtual void Reset(const ResetCallback& callback) = 0;
84 103
85 // Gets the store state. 104 // Gets the store state.
86 virtual StoreState state() const = 0; 105 virtual StoreState state() const = 0;
87 }; 106 };
88 107
89 } // namespace offline_pages 108 } // namespace offline_pages
90 109
91 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_METADATA_STORE_H_ 110 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_METADATA_STORE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698