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
|
// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_BREADCRUMBS_CORE_APPLICATION_BREADCRUMBS_LOGGER_H_
#define COMPONENTS_BREADCRUMBS_CORE_APPLICATION_BREADCRUMBS_LOGGER_H_
#include <memory>
#include <string>
#include "base/files/file_path.h"
#include "base/functional/callback.h"
#include "base/memory/memory_pressure_listener.h"
#include "base/metrics/user_metrics.h"
#if defined(TOOLKIT_VIEWS)
#include "ui/views/widget/any_widget_observer.h"
#endif // TOOLKIT_VIEWS
namespace base {
class TimeTicks;
} // namespace base
namespace breadcrumbs {
class BreadcrumbPersistentStorageManager;
// Listens for and logs application-wide breadcrumb events to the
// BreadcrumbManager.
class ApplicationBreadcrumbsLogger {
public:
// Breadcrumbs will be stored in a file in |storage_dir|.
explicit ApplicationBreadcrumbsLogger(
const base::FilePath& storage_dir,
base::RepeatingCallback<bool()> is_metrics_enabled_callback);
ApplicationBreadcrumbsLogger(const ApplicationBreadcrumbsLogger&) = delete;
~ApplicationBreadcrumbsLogger();
// Returns a pointer to the BreadcrumbPersistentStorageManager owned by this
// instance. May be null.
breadcrumbs::BreadcrumbPersistentStorageManager* GetPersistentStorageManager()
const;
private:
// Callback that processes and logs the user action |action| to the
// BreadcrumbManager.
void OnUserAction(const std::string& action, base::TimeTicks action_time);
// Callback which processes and logs memory pressure warnings to the
// BreadcrumbManager.
void OnMemoryPressure(
base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level);
#if defined(TOOLKIT_VIEWS)
// Callback invoked when a widget is closed.
void OnWidgetClosed(views::Widget* widget);
#endif // TOOLKIT_VIEWS
// Returns true if |action| (UMA User Action) is user triggered.
static bool IsUserTriggeredAction(const std::string& action);
// The callback invoked whenever a user action is registered.
base::ActionCallback user_action_callback_;
// A memory pressure listener which observes memory pressure events.
std::unique_ptr<base::MemoryPressureListener> memory_pressure_listener_;
#if defined(TOOLKIT_VIEWS)
// Widget listener which observes widget events.
views::AnyWidgetObserver any_widget_observer_;
#endif // TOOLKIT_VIEWS
// A strong pointer to the persistent breadcrumb manager listening for events
// from the BreadcrumbManager to store to disk.
std::unique_ptr<breadcrumbs::BreadcrumbPersistentStorageManager>
persistent_storage_manager_;
};
} // namespace breadcrumbs
#endif // COMPONENTS_BREADCRUMBS_CORE_APPLICATION_BREADCRUMBS_LOGGER_H_
|