#ifndef CHROME_BROWSER_ASH_ARC_SURVEY_ARC_SURVEY_SERVICE_H_
#define CHROME_BROWSER_ASH_ARC_SURVEY_ARC_SURVEY_SERVICE_H_
#include <stdint.h>
#include <map>
#include <memory>
#include <set>
#include "base/memory/raw_ptr.h"
#include "base/scoped_observation.h"
#include "base/time/time.h"
#include "chrome/browser/ash/app_list/arc/arc_app_list_prefs.h"
#include "components/keyed_service/core/keyed_service.h"
namespace content {
class BrowserContext;
}
namespace ash {
class HatsNotificationController;
}
namespace arc {
class ArcBridgeService;
class ArcSurveyServiceTest;
class ArcSurveyService : public KeyedService, public ArcAppListPrefs::Observer {
public:
using PackageNameMap = std::map<std::string, std::pair<int, base::Time>>;
using TaskIdMap = std::map<int32_t, std::string>;
static ArcSurveyService* GetForBrowserContext(
content::BrowserContext* context);
static ArcSurveyService* GetForBrowserContextForTesting(
content::BrowserContext* context);
ArcSurveyService(content::BrowserContext* context,
ArcBridgeService* arc_bridge_service);
ArcSurveyService(const ArcSurveyService&) = delete;
ArcSurveyService& operator=(const ArcSurveyService&) = delete;
~ArcSurveyService() override;
void OnTaskCreated(int32_t task_id,
const std::string& package_name,
const std::string& activity,
const std::string& intent,
int32_t session_id) override;
void OnTaskDestroyed(int32_t task_id) override;
void OnArcAppListPrefsDestroyed() override;
const PackageNameMap* GetPackageNameMapForTesting();
const TaskIdMap* GetTaskIdMapForTesting();
const std::set<std::string>* GetAllowedPackagesForTesting();
void AddAllowedPackageNameForTesting(const std::string& package_name);
static void EnsureFactoryBuilt();
private:
friend class ArcSurveyServiceTest;
bool LoadSurveyData(std::string survey_data);
base::ScopedObservation<ArcAppListPrefs, ArcAppListPrefs::Observer>
arc_prefs_observer_{this};
TaskIdMap task_id_map_;
PackageNameMap package_name_map_;
std::set<std::string> allowed_packages_;
base::TimeDelta elapsed_time_survey_trigger_;
const raw_ptr<Profile> profile_;
scoped_refptr<ash::HatsNotificationController> hats_notification_controller_;
};
}
#endif