File: profile_statistics_aggregator.h

package info (click to toggle)
chromium 138.0.7204.183-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 6,080,960 kB
  • sloc: cpp: 34,937,079; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,954; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,811; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (103 lines) | stat: -rw-r--r-- 3,875 bytes parent folder | download | duplicates (4)
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_PROFILES_PROFILE_STATISTICS_AGGREGATOR_H_
#define CHROME_BROWSER_PROFILES_PROFILE_STATISTICS_AGGREGATOR_H_

#include <memory>
#include <vector>

#include "base/functional/callback_forward.h"
#include "base/memory/raw_ptr.h"
#include "chrome/browser/profiles/profile_statistics_common.h"
#include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
#include "components/browsing_data/core/counters/browsing_data_counter.h"
#include "components/password_manager/core/browser/password_store/password_store_interface.h"
#include "device/fido/platform_credential_store.h"

class PrefService;

namespace autofill {
class EntityDataManager;
class PersonalDataManager;
}  // namespace autofill

namespace bookmarks {
class BookmarkModel;
}  // namespace bookmarks

namespace history {
class HistoryService;
}  // namespace history

class ProfileStatisticsAggregator {
  // This class is used internally by ProfileStatistics
  //
  // The class collects statistical information about the profile and returns
  // the information via a callback function. Currently bookmarks, history,
  // logins and sites with autofill forms are counted.

 public:
  ProfileStatisticsAggregator(
      scoped_refptr<autofill::AutofillWebDataService> autofill_web_data_service,
      autofill::PersonalDataManager* personal_data_manager,
      const autofill::EntityDataManager* entity_data_manager,
      bookmarks::BookmarkModel* bookmark_model,
      history::HistoryService* history_service,
      scoped_refptr<password_manager::PasswordStoreInterface>
          profile_password_store,
      PrefService* pref_service,
      std::unique_ptr<device::fido::PlatformCredentialStore>
          platform_credential_store,
      base::OnceClosure done_callback);
  ProfileStatisticsAggregator(const ProfileStatisticsAggregator&) = delete;
  ProfileStatisticsAggregator& operator=(const ProfileStatisticsAggregator&) =
      delete;
  ~ProfileStatisticsAggregator();

  void AddCallbackAndStartAggregator(
      profiles::ProfileStatisticsCallback stats_callback);

 private:
  // Start gathering statistics. Also cancels existing statistics tasks.
  void StartAggregator();

  // Callback functions
  // Appends result to |profile_category_stats_|, and then calls
  // the external callback.
  void StatisticsCallback(const char* category, int count);

  // Callback for counters.
  void OnCounterResult(
      std::unique_ptr<browsing_data::BrowsingDataCounter::Result> result);

  // Registers, initializes and starts a BrowsingDataCounter.
  void AddCounter(std::unique_ptr<browsing_data::BrowsingDataCounter> counter);

  const scoped_refptr<autofill::AutofillWebDataService>
      autofill_web_data_service_;
  const raw_ptr<autofill::PersonalDataManager> personal_data_manager_;
  const raw_ptr<const autofill::EntityDataManager> entity_data_manager_;
  const raw_ptr<bookmarks::BookmarkModel> bookmark_model_;
  const raw_ptr<history::HistoryService> history_service_;
  const scoped_refptr<password_manager::PasswordStoreInterface>
      profile_password_store_;
  const raw_ptr<PrefService> pref_service_;

  std::unique_ptr<device::fido::PlatformCredentialStore>
      platform_credential_store_;

  profiles::ProfileCategoryStats profile_category_stats_;

  // Callback function to be called when results arrive. Will be called
  // multiple times (once for each statistics).
  std::vector<profiles::ProfileStatisticsCallback> stats_callbacks_;

  // Callback function to be called when all statistics are calculated.
  base::OnceClosure done_callback_;

  std::vector<std::unique_ptr<browsing_data::BrowsingDataCounter>> counters_;
};

#endif  // CHROME_BROWSER_PROFILES_PROFILE_STATISTICS_AGGREGATOR_H_