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

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: address (many) comments by Greg 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 2016 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
5 #ifndef COMPONENTS_METRICS_FILE_METRICS_PROVIDER_H_
6 #define COMPONENTS_METRICS_FILE_METRICS_PROVIDER_H_
7
8 #include <list>
9 #include <string>
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 "base/time/time.h"
17 #include "components/metrics/metrics_provider.h"
18
19 class PrefRegistrySimple;
20 class PrefService;
21
22 namespace base {
23 class MemoryMappedFile;
24 class PersistentMemoryAllocator;
25 }
26
27 namespace metrics {
28
29 class MetricsService;
30
31 // FileMetricsProvider gathers and logs histograms written to files on disk.
32 // Any number of files can be registered and the will be polled once per
grt (UTC plus 2) 2016/02/08 18:09:19 "and the will be polled"
bcwhite 2016/02/09 21:08:46 Done.
33 // upload cycle (at startup and about every 30 minutes thereafter) for data
34 // to send.
35 class FileMetricsProvider
36 : public metrics::MetricsProvider {
37 public:
38 enum FileType {
39 // "Atomic" files are a collection of histograms that are written
40 // completely in a single atomic operation (typically a write followed
41 // by an atomic rename) and the file is never updated again except to
42 // be replaced by a completely new set of histograms. This is the only
43 // option that can be used if the file is not writeable by *this*
44 // process.
45 FILE_HISTOGRAMS_ATOMIC,
46
47 // "Active" files may be open by one or more other processes and updated
48 // at any time with new samples or new histograms. Such files may also be
49 // inactive for any period of time only to be opened again and have new
50 // data written to it. Because the file will be actively watched by *this*
grt (UTC plus 2) 2016/02/08 18:09:19 nit: it -> them since the subject is "Such files"
bcwhite 2016/02/09 21:08:46 Done.
51 // process, the underlying file cannot be deleted on operating systems
52 // that do not support delete-while-open (e.g. Windows).
grt (UTC plus 2) 2016/02/08 18:09:19 Windows does, sorta. If all openers use FLAG_SHARE
grt (UTC plus 2) 2016/02/15 15:42:39 Please update the comment here, as Windows does su
bcwhite 2016/02/15 19:22:10 Done, but differently since on reflection, the fil
53 // TODO(bcwhite): Enable when read/write mem-mapped files are supported.
54 //FILE_HISTOGRAMS_ACTIVE,
55 };
56
57 private:
58 // This is fully defined in the header file (rather than just a forward
59 // declaration) so it can be known to tests.
60 struct FileInformation {
61 FileInformation();
62 ~FileInformation();
63
64 base::FilePath path;
65 FileType type;
66 std::string prefs_key;
67 base::Time last_seen;
68 scoped_ptr<base::MemoryMappedFile> mapped;
69 scoped_ptr<base::PersistentMemoryAllocator> allocator;
70
71 private:
72 DISALLOW_COPY_AND_ASSIGN(FileInformation);
73 };
74
75 public:
76 typedef std::list<scoped_ptr<FileInformation>> FileInformationList;
77
78 FileMetricsProvider(metrics::MetricsService* metrics_service,
79 PrefService* local_state);
80 ~FileMetricsProvider() override;
81
82 // Indicate a file to be monitored and how the file is used. Because some
83 // metadata must persist across process restarts, registry entries are used
grt (UTC plus 2) 2016/02/08 18:09:19 regarding "registry entries", do you mean "prefere
bcwhite 2016/02/09 21:08:46 Done. Was thinking in terms of "PrefRegistry".
84 // based on the |prefs_key| name. Call RegisterPrefs() with the same name
85 // to create the necessary keys in advance.
86 void RegisterFile(const base::FilePath& path, FileType type,
87 const base::StringPiece& prefs_key);
88
89 static void RegisterPrefs(PrefRegistrySimple* prefs,
90 const base::StringPiece& key);
91
92 private:
93 friend class FileMetricsProviderTest;
94 FRIEND_TEST_ALL_PREFIXES(FileMetricsProviderTest, AccessMetrics);
95
96 static void CheckAndMapNewMetricFilesOnBlockingPool(
97 FileInformationList* files,
98 base::Callback<void(FileInformationList*)> callback);
99 static bool CheckAndMapNewMetrics(FileInformation* file);
100
101 void ScheduleFilesCheck();
102 void RecordFileInformation(FileInformationList* files);
103 void RecordFileAsSeen(FileInformation* file);
104
105 // metrics::MetricsDataProvider:
106 void OnDidCreateMetricsLog() override;
107 void RecordHistogramSnapshots(base::HistogramSnapshotManager* hsm) override;
108
109 base::Lock lock_;
110 FileInformationList metrics_files_;
111 FileInformationList metrics_found_;
112 metrics::MetricsService* metrics_service_;
113 PrefService* pref_service_;
114
115 DISALLOW_COPY_AND_ASSIGN(FileMetricsProvider);
116 };
117
118 } // namespace metrics
119
120 #endif // COMPONENTS_METRICS_FILE_METRICS_PROVIDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698