Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(394)

Side by Side Diff: components/metrics/file_metrics_provider.h

Issue 1537743006: Persist setup metrics and have Chrome report them during UMA upload. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@shared-histograms
Patch Set: moved allocator create/destroy to be beside snapshot (simpler code) Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
grt (UTC plus 2) 2016/02/04 15:36:44 2016 :-)
bcwhite 2016/02/04 21:51:15 Done.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef COMPONENTS_METRICS_FILE_METRICS_PROVIDER_H_
6 #define COMPONENTS_METRICS_FILE_METRICS_PROVIDER_H_
7
8 #include <atomic>
grt (UTC plus 2) 2016/02/04 15:36:44 unused
bcwhite 2016/02/04 21:51:15 Done.
9 #include <list>
10
11 #include "base/callback.h"
12 #include "base/files/file_path.h"
13 #include "base/gtest_prod_util.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/synchronization/lock.h"
16 #include "components/metrics/metrics_provider.h"
17
18 class PrefRegistrySimple;
19 class PrefService;
20
21 namespace base {
22 class MemoryMappedFile;
23 class PersistentMemoryAllocator;
24 }
25
26 namespace metrics {
27
28 class MetricsService;
29
30 // FileMetricsProvider gathers and logs histograms written to files on disk.
grt (UTC plus 2) 2016/02/04 15:36:44 Please add some more details. For example, how oft
bcwhite 2016/02/04 21:51:14 Done.
31 class FileMetricsProvider
32 : public metrics::MetricsProvider {
33 public:
34 enum FileType {
35 FILE_HISTOGRAMS_ATOMIC, // Written atomically and never updated.
36 // TODO(bcwhite): Enable when read/write mem-mapped files are supported.
37 //FILE_HISTOGRAMS_ACTIVE, // Metrics actively updated by other processes.
38 };
39
40 private:
41 // This is fully defined in the header file (rather than just a forward
42 // declaration) so it can be known to tests.
43 struct FileInformation {
44 base::FilePath path;
45 FileType type;
46 std::string prefs_key;
grt (UTC plus 2) 2016/02/04 15:36:43 #include <string> above
bcwhite 2016/02/04 21:51:14 Done.
47 base::Time last_seen;
grt (UTC plus 2) 2016/02/04 15:36:44 #include "base/time/time.h"
bcwhite 2016/02/04 21:51:15 Done.
48 scoped_ptr<base::MemoryMappedFile> mapped;
49 scoped_ptr<base::PersistentMemoryAllocator> allocator;
50
51 FileInformation();
grt (UTC plus 2) 2016/02/04 15:36:43 the ctor and dtor should come before the data memb
bcwhite 2016/02/04 21:51:15 Done.
52 ~FileInformation();
53
54 private:
55 DISALLOW_COPY_AND_ASSIGN(FileInformation);
56 };
57
58 public:
59 typedef std::list<scoped_ptr<FileInformation>> FileInformationList;
grt (UTC plus 2) 2016/02/04 15:36:44 nit: using FileInformationList = ...;
grt (UTC plus 2) 2016/02/08 18:09:18 ping (as per http://chromium-cpp.appspot.com/#core
bcwhite 2016/02/09 21:08:45 Right. I had wanted to talk with you about the re
60
61 FileMetricsProvider(metrics::MetricsService* metrics_service,
62 PrefService* local_state);
63 ~FileMetricsProvider() override;
64
65 void RegisterFile(const base::FilePath& path, FileType type,
grt (UTC plus 2) 2016/02/04 15:36:43 please document
bcwhite 2016/02/04 21:51:14 Done.
66 const std::string& prefs_key);
grt (UTC plus 2) 2016/02/04 15:36:44 nit: base::StringPiece prefs_key
bcwhite 2016/02/04 21:51:15 Done.
67
68 static void RegisterPrefs(PrefRegistrySimple* prefs, const std::string& key);
grt (UTC plus 2) 2016/02/04 15:36:43 nit: base::StringPiece key
bcwhite 2016/02/04 21:51:14 Done.
69
70 // metrics::MetricsDataProvider:
71 void OnDidCreateMetricsLog() override;
grt (UTC plus 2) 2016/02/04 15:36:43 prefer placing the inherited methods in the privat
bcwhite 2016/02/04 21:51:14 Done.
72 void RecordHistogramSnapshots(base::HistogramSnapshotManager* hsm) override;
73
74 private:
75 friend class FileMetricsProviderTest;
76 FRIEND_TEST_ALL_PREFIXES(FileMetricsProviderTest, AccessMetrics);
77
78 static void CheckAndMapNewMetricFiles(
79 FileInformationList* files,
80 base::Callback<void(FileInformationList*)> callback);
grt (UTC plus 2) 2016/02/04 15:36:44 note: pass callbacks by constref, although this ca
bcwhite 2016/02/09 21:08:45 Done.
81 static bool CheckAndMapNewMetrics(FileMetricsProvider::FileInformation* file);
grt (UTC plus 2) 2016/02/04 15:36:43 "FileMetricsProvider::" not needed here or in defi
bcwhite 2016/02/04 21:51:15 Done.
82
83 void ScheduleFilesCheck();
84 void RecordFileInformation(FileInformationList* files);
85 void RecordFileAsSeen(FileInformation* file);
86
87 base::Lock lock_;
grt (UTC plus 2) 2016/02/04 15:36:44 Is this lock needed? It looks like everything woul
88 FileInformationList metrics_files_;
grt (UTC plus 2) 2016/02/04 15:36:44 what's the advantage of having two lists? could th
bcwhite 2016/02/04 21:51:14 Unmapped files (i.e. those to be checked for somet
89 FileInformationList metrics_found_;
90 metrics::MetricsService* metrics_service_;
91 PrefService* pref_service_;
92
93 DISALLOW_COPY_AND_ASSIGN(FileMetricsProvider);
94 };
95
96 } // namespace metrics
97
98 #endif // COMPONENTS_METRICS_FILE_METRICS_PROVIDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698