logger.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 COMPONENTS_QUERY_TILES_LOGGER_H_
  5. #define COMPONENTS_QUERY_TILES_LOGGER_H_
  6. namespace base {
  7. class Value;
  8. }
  9. namespace query_tiles {
  10. // A helper class to expose internals of the query-tiles service to a logging
  11. // component and/or debug UI.
  12. class Logger {
  13. public:
  14. class Observer {
  15. public:
  16. virtual ~Observer() = default;
  17. // Called whenever the service status changes.
  18. virtual void OnServiceStatusChanged(const base::Value& status) = 0;
  19. // Called when the tile group data is available.
  20. virtual void OnTileDataAvailable(const base::Value& status) = 0;
  21. };
  22. virtual ~Logger() = default;
  23. virtual void AddObserver(Observer* observer) = 0;
  24. virtual void RemoveObserver(Observer* observer) = 0;
  25. Logger(const Logger& other) = delete;
  26. Logger& operator=(const Logger& other) = delete;
  27. // Returns the current status of query tile service.
  28. // The serialized format will be:
  29. // {
  30. // fetcherStatus:[INITIAL, SUCCESS, FAIL, SUSPEND]
  31. // groupStatus:[SUCCESS, UN_INIT, NO_TILES, DB_FAIL]
  32. // }
  33. virtual base::Value GetServiceStatus() = 0;
  34. // Returns the formatted raw data stored in database.
  35. // The serialized format will be:
  36. // {
  37. // groupInfo(string)
  38. // tileProto(string)
  39. // }
  40. virtual base::Value GetTileData() = 0;
  41. protected:
  42. Logger() = default;
  43. };
  44. } // namespace query_tiles
  45. #endif // COMPONENTS_QUERY_TILES_LOGGER_H_