| Index: components/metrics/file_metrics_provider.h
|
| diff --git a/components/metrics/file_metrics_provider.h b/components/metrics/file_metrics_provider.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..d14cf6f442c17257617a2c4331d62d4011c213fe
|
| --- /dev/null
|
| +++ b/components/metrics/file_metrics_provider.h
|
| @@ -0,0 +1,107 @@
|
| +// Copyright 2016 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#ifndef COMPONENTS_METRICS_FILE_METRICS_PROVIDER_H_
|
| +#define COMPONENTS_METRICS_FILE_METRICS_PROVIDER_H_
|
| +
|
| +#include <list>
|
| +#include <string>
|
| +
|
| +#include "base/callback.h"
|
| +#include "base/files/file_path.h"
|
| +#include "base/gtest_prod_util.h"
|
| +#include "base/memory/scoped_ptr.h"
|
| +#include "base/memory/weak_ptr.h"
|
| +#include "base/synchronization/lock.h"
|
| +#include "base/threading/thread_checker.h"
|
| +#include "base/time/time.h"
|
| +#include "components/metrics/metrics_provider.h"
|
| +
|
| +class PrefRegistrySimple;
|
| +class PrefService;
|
| +
|
| +namespace base {
|
| +class MemoryMappedFile;
|
| +class PersistentMemoryAllocator;
|
| +class TaskRunner;
|
| +}
|
| +
|
| +namespace metrics {
|
| +
|
| +// FileMetricsProvider gathers and logs histograms written to files on disk.
|
| +// Any number of files can be registered and will be polled once per upload
|
| +// cycle (at startup and about every 30 minutes thereafter) for data to send.
|
| +class FileMetricsProvider
|
| + : public metrics::MetricsProvider {
|
| + public:
|
| + enum FileType {
|
| + // "Atomic" files are a collection of histograms that are written
|
| + // completely in a single atomic operation (typically a write followed
|
| + // by an atomic rename) and the file is never updated again except to
|
| + // be replaced by a completely new set of histograms. This is the only
|
| + // option that can be used if the file is not writeable by *this*
|
| + // process.
|
| + FILE_HISTOGRAMS_ATOMIC,
|
| +
|
| + // "Active" files may be open by one or more other processes and updated
|
| + // at any time with new samples or new histograms. Such files may also be
|
| + // inactive for any period of time only to be opened again and have new
|
| + // data written to them. The file should probably never be deleted because
|
| + // there would be no guarantee that the data has been reported.
|
| + // TODO(bcwhite): Enable when read/write mem-mapped files are supported.
|
| + //FILE_HISTOGRAMS_ACTIVE,
|
| + };
|
| +
|
| + private:
|
| + // Information about files being monitored, defined and used exclusively
|
| + // inside the .cc file.
|
| + struct FileInformation;
|
| +
|
| + public:
|
| + using FileInformationList = std::list<scoped_ptr<FileInformation>>;
|
| +
|
| + FileMetricsProvider(const scoped_refptr<base::TaskRunner>& task_runner,
|
| + PrefService* local_state);
|
| + ~FileMetricsProvider() override;
|
| +
|
| + // Indicate a file to be monitored and how the file is used. Because some
|
| + // metadata must persist across process restarts, preferences entries are
|
| + // used based on the |prefs_key| name. Call RegisterPrefs() with the same
|
| + // name to create the necessary keys in advance.
|
| + void RegisterFile(const base::FilePath& path, FileType type,
|
| + const base::StringPiece& prefs_key);
|
| +
|
| + static void RegisterPrefs(PrefRegistrySimple* prefs,
|
| + const base::StringPiece& key);
|
| +
|
| + private:
|
| + friend class FileMetricsProviderTest;
|
| + FRIEND_TEST_ALL_PREFIXES(FileMetricsProviderTest, AccessMetrics);
|
| +
|
| + static void CheckAndMapNewMetricFilesOnTaskRunner(
|
| + FileInformationList* files);
|
| + static bool CheckAndMapNewMetrics(FileInformation* file);
|
| +
|
| + void ScheduleFilesCheck();
|
| + void RecordFilesChecked(FileInformationList* checked);
|
| + void RecordFileAsSeen(FileInformation* file);
|
| +
|
| + // metrics::MetricsDataProvider:
|
| + void OnDidCreateMetricsLog() override;
|
| + void RecordHistogramSnapshots(base::HistogramSnapshotManager* hsm) override;
|
| +
|
| + scoped_refptr<base::TaskRunner> task_runner_;
|
| + FileInformationList files_to_check_;
|
| + FileInformationList files_to_read_;
|
| + PrefService* pref_service_;
|
| +
|
| + base::ThreadChecker thread_checker_;
|
| + base::WeakPtrFactory<FileMetricsProvider> weak_factory_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(FileMetricsProvider);
|
| +};
|
| +
|
| +} // namespace metrics
|
| +
|
| +#endif // COMPONENTS_METRICS_FILE_METRICS_PROVIDER_H_
|
|
|