history_clusters_types.h 4.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. // Copyright 2021 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_HISTORY_CLUSTERS_CORE_HISTORY_CLUSTERS_TYPES_H_
  5. #define COMPONENTS_HISTORY_CLUSTERS_CORE_HISTORY_CLUSTERS_TYPES_H_
  6. #include <string>
  7. #include <vector>
  8. #include "base/callback.h"
  9. #include "components/history/core/browser/history_types.h"
  10. #include "third_party/abseil-cpp/absl/types/optional.h"
  11. namespace history_clusters {
  12. struct QueryClustersContinuationParams {
  13. QueryClustersContinuationParams() = default;
  14. QueryClustersContinuationParams(base::Time continuation_time,
  15. bool is_continuation,
  16. bool is_partial_day,
  17. bool exhausted_unclustered_visits,
  18. bool exhausted_all_visits)
  19. : continuation_time(continuation_time),
  20. is_continuation(is_continuation),
  21. is_partial_day(is_partial_day),
  22. exhausted_unclustered_visits(exhausted_unclustered_visits),
  23. exhausted_all_visits(exhausted_all_visits) {}
  24. // Returns a `QueryClustersContinuationParams` representing the done state.
  25. // Most of the values don't matter, but `exhausted_unclustered_visits` and
  26. // `exhausted_all_visits` should be true.
  27. static const QueryClustersContinuationParams DoneParams() {
  28. static QueryClustersContinuationParams kDoneParams = {base::Time(), true,
  29. false, true, true};
  30. return kDoneParams;
  31. }
  32. // The time already fetched visits up to and where the next request will
  33. // continue.
  34. base::Time continuation_time = base::Time();
  35. // False for the first request, true otherwise.
  36. bool is_continuation = false;
  37. // True if left off midday; i.e. not a day boundary. This occurs when the max
  38. // visit threshold was reached.
  39. bool is_partial_day = false;
  40. // True if unclustered visits were exhausted. If we're searching oldest to
  41. // newest, this is true iff `exhausted_all_visits` is true. Otherwise, this
  42. // may be true before `exhausted_all_visits` is true but not the reverse.
  43. bool exhausted_unclustered_visits = false;
  44. // True if both unclustered and clustered were exhausted.
  45. bool exhausted_all_visits = false;
  46. };
  47. using QueryClustersCallback =
  48. base::OnceCallback<void(std::vector<history::Cluster>,
  49. QueryClustersContinuationParams)>;
  50. // Tracks which fields have been or are pending recording. This helps 1) avoid
  51. // re-recording fields and 2) determine whether a visit is complete (i.e. has
  52. // all expected fields recorded).
  53. struct RecordingStatus {
  54. // Whether `url_row` and `visit_row` have been set.
  55. bool history_rows = false;
  56. // Whether a navigation has ended; i.e. another navigation has begun in the
  57. // same tab or the navigation's tab has been closed.
  58. bool navigation_ended = false;
  59. // Whether the `context_annotations` associated with navigation end have been
  60. // set. Should only be true if both `history_rows` and `navigation_ended` are
  61. // true.
  62. bool navigation_end_signals = false;
  63. // Whether the UKM `page_end_reason` `context_annotations` is expected to be
  64. // set.
  65. bool expect_ukm_page_end_signals = false;
  66. // Whether the UKM `page_end_reason` `context_annotations` has been set.
  67. // Should only be true if `expect_ukm_page_end_signals` is true.
  68. bool ukm_page_end_signals = false;
  69. };
  70. // A partially built VisitContextAnnotations with its state of completeness and
  71. // associated `URLRow` and `VisitRow` which are necessary to build it.
  72. struct IncompleteVisitContextAnnotations {
  73. IncompleteVisitContextAnnotations();
  74. IncompleteVisitContextAnnotations(const IncompleteVisitContextAnnotations&);
  75. ~IncompleteVisitContextAnnotations();
  76. RecordingStatus status;
  77. history::URLRow url_row;
  78. history::VisitRow visit_row;
  79. history::VisitContextAnnotations context_annotations;
  80. };
  81. // Used to track incomplete, unpersisted visits.
  82. using IncompleteVisitMap = std::map<int64_t, IncompleteVisitContextAnnotations>;
  83. } // namespace history_clusters
  84. #endif // COMPONENTS_HISTORY_CLUSTERS_CORE_HISTORY_CLUSTERS_TYPES_H_