offline_store_types.h 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. #ifndef COMPONENTS_OFFLINE_PAGES_CORE_OFFLINE_STORE_TYPES_H_
  5. #define COMPONENTS_OFFLINE_PAGES_CORE_OFFLINE_STORE_TYPES_H_
  6. #include <stdint.h>
  7. #include <utility>
  8. #include <vector>
  9. // This file contains common types and callbacks used by storage of various
  10. // offline page related components.
  11. namespace offline_pages {
  12. // Current store state. When LOADED, the store is operational. When
  13. // loading or reset fails, it is reflected appropriately.
  14. enum class StoreState {
  15. NOT_LOADED, // Store is not loaded yet.
  16. LOADED, // Store is properly loaded and operational.
  17. FAILED_LOADING, // Store initialization failed.
  18. FAILED_RESET, // Resetting the store failed.
  19. INITIALIZING, // Store is in the process of initializing.
  20. };
  21. // Statuses referring to actions taken on items in the stores.
  22. // GENERATED_JAVA_ENUM_PACKAGE:org.chromium.components.offlinepages
  23. enum class ItemActionStatus {
  24. SUCCESS,
  25. ALREADY_EXISTS,
  26. NOT_FOUND,
  27. STORE_ERROR,
  28. };
  29. // Result for synchronous operations (like database and file operations) that
  30. // are part of the tasks used by Offline Pages.
  31. // Keep it in sync with OfflinePagesSyncOperationResult in enums.xml for
  32. // histograms usages.
  33. enum class SyncOperationResult {
  34. SUCCESS, // Successful operation
  35. INVALID_DB_CONNECTION, // Invalid database connection
  36. TRANSACTION_BEGIN_ERROR, // Failed when start a DB transaction
  37. TRANSACTION_COMMIT_ERROR, // Failed when commiting a DB transaction
  38. DB_OPERATION_ERROR, // Failed when executing a DB statement
  39. FILE_OPERATION_ERROR, // Failed while doing file operations
  40. kMaxValue = FILE_OPERATION_ERROR,
  41. };
  42. // List of item action statuses mapped to item ID.
  43. typedef std::vector<std::pair<int64_t, ItemActionStatus>> MultipleItemStatuses;
  44. // Collective result for store update.
  45. template <typename T>
  46. class StoreUpdateResult {
  47. public:
  48. explicit StoreUpdateResult(StoreState state) : store_state(state) {}
  49. ~StoreUpdateResult() {}
  50. // Move-only to avoid accidental copies.
  51. StoreUpdateResult(const StoreUpdateResult& other) = delete;
  52. StoreUpdateResult(StoreUpdateResult&& other) = default;
  53. StoreUpdateResult& operator=(const StoreUpdateResult&) = delete;
  54. StoreUpdateResult& operator=(StoreUpdateResult&&) = default;
  55. // List of Offline ID to item action status mappings.
  56. // It is meant to be consumed by the original caller of the operation.
  57. MultipleItemStatuses item_statuses;
  58. // List of successfully updated offline page items as seen after operation
  59. // concludes. It is meant to be used when passing to the observers.
  60. std::vector<T> updated_items;
  61. // State of the store after the operation is done.
  62. StoreState store_state;
  63. };
  64. // This enum is backed by a UMA histogram therefore its entries should not be
  65. // deleted or re-ordered and new ones should only be appended.
  66. // See enum definition with the same name in tools/metrics/histograms/enum.xml.
  67. enum class OfflinePagesStoreEvent {
  68. kOpenedFirstTime = 0,
  69. kReopened = 1,
  70. kClosed = 2,
  71. kCloseSkipped = 3,
  72. kMaxValue = kCloseSkipped,
  73. };
  74. } // namespace offline_pages
  75. #endif // COMPONENTS_OFFLINE_PAGES_CORE_OFFLINE_STORE_TYPES_H_