#ifndef COMPONENTS_COMMERCE_CORE_ACCOUNT_CHECKER_H_
#define COMPONENTS_COMMERCE_CORE_ACCOUNT_CHECKER_H_
#include <memory>
#include <string>
#include "base/memory/scoped_refptr.h"
#include "components/endpoint_fetcher/endpoint_fetcher.h"
#include "components/signin/public/identity_manager/identity_manager.h"
#include "components/sync/base/data_type.h"
#include "components/sync/base/user_selectable_type.h"
#include "components/sync/service/sync_service.h"
#include "net/traffic_annotation/network_traffic_annotation.h"
class GURL;
class PrefService;
class PrefChangeRegistrar;
namespace base {
class TimeDelta;
}
namespace network {
class SharedURLLoaderFactory;
}
namespace commerce {
extern const char kNotificationsPrefUrl[];
class AccountChecker {
public:
AccountChecker(const AccountChecker&) = delete;
virtual ~AccountChecker();
virtual bool IsSignedIn();
virtual bool IsSyncTypeEnabled(syncer::UserSelectableType type);
virtual bool IsSyncAvailable();
virtual bool IsAnonymizedUrlDataCollectionEnabled();
virtual bool IsSubjectToParentalControls();
virtual bool CanUseModelExecutionFeatures();
virtual std::string GetCountry();
virtual std::string GetLocale();
virtual PrefService* GetPrefs();
protected:
friend class ShoppingService;
friend class MockAccountChecker;
AccountChecker(
std::string country,
std::string locale,
PrefService* pref_service,
signin::IdentityManager* identity_manager,
syncer::SyncService* sync_service,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory);
void FetchPriceEmailPref();
virtual std::unique_ptr<endpoint_fetcher::EndpointFetcher>
CreateEndpointFetcher(signin::OAuthConsumerId oauth_consumer_id,
const GURL& url,
const endpoint_fetcher::HttpMethod http_method,
const std::string& content_type,
const base::TimeDelta& timeout,
const std::string& post_data,
const net::NetworkTrafficAnnotationTag& annotation_tag);
private:
void OnPriceEmailPrefChanged();
void HandleSendPriceEmailPrefResponse(
std::unique_ptr<endpoint_fetcher::EndpointFetcher> endpoint_fetcher,
std::unique_ptr<endpoint_fetcher::EndpointResponse> responses);
void HandleFetchPriceEmailPrefResponse(
std::unique_ptr<endpoint_fetcher::EndpointFetcher> endpoint_fetcher,
std::unique_ptr<endpoint_fetcher::EndpointResponse> responses);
std::string country_;
std::string locale_;
raw_ptr<PrefService> pref_service_;
raw_ptr<signin::IdentityManager> identity_manager_;
raw_ptr<syncer::SyncService> sync_service_;
const scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory_;
std::unique_ptr<PrefChangeRegistrar> pref_change_registrar_;
bool is_waiting_for_pref_fetch_completion_;
bool ignore_next_email_pref_change_{false};
base::WeakPtrFactory<AccountChecker> weak_ptr_factory_;
};
}
#endif