browser_tabs_model.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // Copyright 2020 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 ASH_COMPONENTS_PHONEHUB_BROWSER_TABS_MODEL_H_
  5. #define ASH_COMPONENTS_PHONEHUB_BROWSER_TABS_MODEL_H_
  6. #include <ostream>
  7. #include <string>
  8. #include "base/time/time.h"
  9. #include "ui/gfx/image/image.h"
  10. #include "url/gurl.h"
  11. namespace ash {
  12. namespace phonehub {
  13. // Contains metadata about browser tabs that are open on the user's phone.
  14. class BrowserTabsModel {
  15. public:
  16. static const size_t kMaxMostRecentTabs;
  17. struct BrowserTabMetadata {
  18. BrowserTabMetadata(GURL url,
  19. const std::u16string& title,
  20. base::Time last_accessed_timestamp,
  21. const gfx::Image& favicon);
  22. BrowserTabMetadata(const BrowserTabMetadata& other);
  23. BrowserTabMetadata& operator=(const BrowserTabMetadata& other);
  24. bool operator==(const BrowserTabMetadata& other) const;
  25. bool operator!=(const BrowserTabMetadata& other) const;
  26. bool operator<(const BrowserTabMetadata& other) const;
  27. GURL url;
  28. std::u16string title;
  29. base::Time last_accessed_timestamp;
  30. gfx::Image favicon;
  31. };
  32. // |is_tab_sync_enabled| indicates whether the Chrome OS device is currently
  33. // syncing tab metadata. If that parameter is false, |most_recent_tabs_|
  34. // should be empty. If it is true, |most_recent_tabs_| can contain up to four.
  35. BrowserTabsModel(
  36. bool is_tab_sync_enabled,
  37. const std::vector<BrowserTabMetadata>& most_recent_tabs = {});
  38. BrowserTabsModel(const BrowserTabsModel& other);
  39. ~BrowserTabsModel();
  40. bool operator==(const BrowserTabsModel& other) const;
  41. bool operator!=(const BrowserTabsModel& other) const;
  42. bool is_tab_sync_enabled() const { return is_tab_sync_enabled_; }
  43. const std::vector<BrowserTabMetadata>& most_recent_tabs() const {
  44. return most_recent_tabs_;
  45. }
  46. private:
  47. bool is_tab_sync_enabled_;
  48. // Sorted from most recently visited to least recently visited.
  49. std::vector<BrowserTabMetadata> most_recent_tabs_;
  50. };
  51. std::ostream& operator<<(
  52. std::ostream& stream,
  53. BrowserTabsModel::BrowserTabMetadata browser_tab_metadata);
  54. } // namespace phonehub
  55. } // namespace ash
  56. // TODO(https://crbug.com/1164001): remove after the migration is finished.
  57. namespace chromeos {
  58. namespace phonehub {
  59. using ::ash::phonehub::BrowserTabsModel;
  60. }
  61. } // namespace chromeos
  62. #endif // ASH_COMPONENTS_PHONEHUB_BROWSER_TABS_MODEL_H_