File: networking_log.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (88 lines) | stat: -rw-r--r-- 3,072 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef ASH_SYSTEM_DIAGNOSTICS_NETWORKING_LOG_H_
#define ASH_SYSTEM_DIAGNOSTICS_NETWORKING_LOG_H_

#include <string>
#include <vector>

#include "ash/ash_export.h"
#include "ash/system/diagnostics/async_log.h"
#include "ash/webui/diagnostics_ui/mojom/network_health_provider.mojom.h"
#include "base/gtest_prod_util.h"

namespace ash {
namespace diagnostics {

class ASH_EXPORT NetworkingLog {
 public:
  explicit NetworkingLog(const base::FilePath& log_base_path);

  NetworkingLog(const NetworkingLog&) = delete;
  NetworkingLog& operator=(const NetworkingLog&) = delete;

  ~NetworkingLog();

  // Returns the networking info section as a string.
  std::string GetNetworkInfo() const;

  // Returns the networking events section as a string.
  std::string GetNetworkEvents() const;

  // Updates the list of valid networks and which is active.
  void UpdateNetworkList(const std::vector<std::string>& observer_guids,
                         std::string active_guid);

  // Update the state of the network. Networks can be identified by
  // the `observer_guid` property.
  void UpdateNetworkState(mojom::NetworkPtr network);

 private:
  FRIEND_TEST_ALL_PREFIXES(NetworkHealthProviderTest, NetworkingLog);
  friend class NetworkHealthProviderTest;

  // Test only. Get the count of UpdateNetworkList() being called.
  size_t update_network_list_call_count_for_testing() const;

  // Writes the `event_string` to the `event_log_`.
  void LogEvent(const std::string& event_string);

  // Logs an event whenever a new network is seen in the network list
  // sent to UpdateNetworkList().
  void LogNetworkAdded(const mojom::NetworkPtr& network);

  // Logs an event whenever a network is removed from the network list
  // sent to UpdateNetworkList().
  void LogNetworkRemoved(const mojom::NetworkPtr& network);

  // Top level function that determines which state changes should be
  // logged and calls the appropriate specialized method below.
  void LogNetworkChanges(const mojom::NetworkPtr& network);

  // Logs when the state of the network changes.
  void LogNetworkStateChanged(const mojom::NetworkPtr& old_state,
                              const mojom::NetworkPtr& new_state);

  // Logs when a WiFi network is joined.
  void LogJoinedWiFiNetwork(const mojom::NetworkPtr& network);

  // Logs when a WiFi network is left.
  void LogLeftWiFiNetwork(const mojom::NetworkPtr& network,
                          const std::string& old_ssid);

  // Logs when a WiFi network roams between access points.
  void LogWiFiRoamedAccessPoint(const mojom::NetworkPtr& network,
                                const std::string& old_bssid);

  AsyncLog event_log_;
  std::string active_guid_;
  base::flat_map<std::string, mojom::NetworkPtr> latest_network_states_;
  size_t update_network_list_call_count_for_testing_ = 0;
};

}  // namespace diagnostics
}  // namespace ash

#endif  // ASH_SYSTEM_DIAGNOSTICS_NETWORKING_LOG_H_