device_activity_controller.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. // Copyright 2021 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. #ifndef ASH_COMPONENTS_DEVICE_ACTIVITY_DEVICE_ACTIVITY_CONTROLLER_H_
  5. #define ASH_COMPONENTS_DEVICE_ACTIVITY_DEVICE_ACTIVITY_CONTROLLER_H_
  6. #include <memory>
  7. #include "ash/components/device_activity/device_active_use_case.h"
  8. #include "base/component_export.h"
  9. #include "base/time/time.h"
  10. #include "chromeos/system/statistics_provider.h"
  11. #include "components/policy/core/common/cloud/cloud_policy_constants.h"
  12. #include "services/network/public/cpp/shared_url_loader_factory.h"
  13. class PrefRegistrySimple;
  14. class PrefService;
  15. namespace version_info {
  16. enum class Channel;
  17. } // namespace version_info
  18. namespace ash {
  19. namespace device_activity {
  20. class DeviceActivityClient;
  21. struct ChromeDeviceMetadataParameters;
  22. // Counts device actives in a privacy compliant way.
  23. class COMPONENT_EXPORT(ASH_DEVICE_ACTIVITY) DeviceActivityController {
  24. public:
  25. // Retrieves a singleton instance.
  26. static DeviceActivityController* Get();
  27. // Registers local state preferences.
  28. static void RegisterPrefs(PrefRegistrySimple* registry);
  29. // Determines the total start up delay before starting device activity
  30. // reporting.
  31. static base::TimeDelta DetermineStartUpDelay(base::Time chrome_first_run_ts);
  32. // Determines the market segment from the loaded ChromeOS device policies.
  33. static MarketSegment GetMarketSegment(
  34. policy::DeviceMode device_mode,
  35. policy::MarketSegment device_market_segment);
  36. DeviceActivityController(
  37. const ChromeDeviceMetadataParameters& chrome_passed_device_params,
  38. PrefService* local_state,
  39. scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
  40. base::TimeDelta start_up_delay);
  41. DeviceActivityController(const DeviceActivityController&) = delete;
  42. DeviceActivityController& operator=(const DeviceActivityController&) = delete;
  43. ~DeviceActivityController();
  44. private:
  45. // Start Device Activity reporting.
  46. void Start(PrefService* local_state,
  47. scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory);
  48. // Stop Device Activity reporting.
  49. void Stop();
  50. void OnPsmDeviceActiveSecretFetched(
  51. PrefService* local_state,
  52. scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
  53. const std::string& psm_device_active_secret);
  54. void OnMachineStatisticsLoaded(
  55. PrefService* local_state,
  56. scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
  57. const std::string& psm_device_active_secret);
  58. std::unique_ptr<DeviceActivityClient> da_client_network_;
  59. // Creates a copy of chrome parameters, which is owned throughout
  60. // |DeviceActivityController| object lifetime.
  61. const ChromeDeviceMetadataParameters chrome_passed_device_params_;
  62. // Singleton lives throughout class lifetime.
  63. chromeos::system::StatisticsProvider* const statistics_provider_;
  64. // Automatically cancels callbacks when the referent of weakptr gets
  65. // destroyed.
  66. base::WeakPtrFactory<DeviceActivityController> weak_factory_{this};
  67. };
  68. } // namespace device_activity
  69. } // namespace ash
  70. #endif // ASH_COMPONENTS_DEVICE_ACTIVITY_DEVICE_ACTIVITY_CONTROLLER_H_