networking_log.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 ASH_SYSTEM_DIAGNOSTICS_NETWORKING_LOG_H_
  5. #define ASH_SYSTEM_DIAGNOSTICS_NETWORKING_LOG_H_
  6. #include <string>
  7. #include <vector>
  8. #include "ash/ash_export.h"
  9. #include "ash/system/diagnostics/async_log.h"
  10. #include "ash/webui/diagnostics_ui/mojom/network_health_provider.mojom.h"
  11. namespace ash {
  12. namespace diagnostics {
  13. class ASH_EXPORT NetworkingLog {
  14. public:
  15. explicit NetworkingLog(const base::FilePath& log_base_path);
  16. NetworkingLog(const NetworkingLog&) = delete;
  17. NetworkingLog& operator=(const NetworkingLog&) = delete;
  18. ~NetworkingLog();
  19. // Returns the networking info section as a string.
  20. std::string GetNetworkInfo() const;
  21. // Returns the networking events section as a string.
  22. std::string GetNetworkEvents() const;
  23. // Updates the list of valid networks and which is active.
  24. void UpdateNetworkList(const std::vector<std::string>& observer_guids,
  25. std::string active_guid);
  26. // Update the state of the network. Networks can be identified by
  27. // the `observer_guid` property.
  28. void UpdateNetworkState(mojom::NetworkPtr network);
  29. private:
  30. // Writes the `event_string` to the `event_log_`.
  31. void LogEvent(const std::string& event_string);
  32. // Logs an event whenever a new network is seen in the network list
  33. // sent to UpdateNetworkList().
  34. void LogNetworkAdded(const mojom::NetworkPtr& network);
  35. // Logs an event whenever a network is removed from the network list
  36. // sent to UpdateNetworkList().
  37. void LogNetworkRemoved(const mojom::NetworkPtr& network);
  38. // Top level function that determines which state changes should be
  39. // logged and calls the appropriate specialized method below.
  40. void LogNetworkChanges(const mojom::NetworkPtr& network);
  41. // Logs when the state of the network changes.
  42. void LogNetworkStateChanged(const mojom::NetworkPtr& old_state,
  43. const mojom::NetworkPtr& new_state);
  44. // Logs when a WiFi network is joined.
  45. void LogJoinedWiFiNetwork(const mojom::NetworkPtr& network);
  46. // Logs when a WiFi network is left.
  47. void LogLeftWiFiNetwork(const mojom::NetworkPtr& network,
  48. const std::string& old_ssid);
  49. // Logs when a WiFi network roams between access points.
  50. void LogWiFiRoamedAccessPoint(const mojom::NetworkPtr& network,
  51. const std::string& old_bssid);
  52. AsyncLog event_log_;
  53. std::string active_guid_;
  54. base::flat_map<std::string, mojom::NetworkPtr> latest_network_states_;
  55. };
  56. } // namespace diagnostics
  57. } // namespace ash
  58. #endif // ASH_WEBUI_DIAGNOSTICS_UI_BACKEND_NETWORKING_LOG_H_