Re-enable child account detection, now behind a flag.
[chromium-blink-merge.git] / chrome / browser / supervised_user / child_accounts / child_account_service.h
bloba0b434ff808559354c3b767d3ecb52e00f352a16
1 // Copyright 2014 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.
5 #ifndef CHROME_BROWSER_SUPERVISED_USER_CHILD_ACCOUNTS_CHILD_ACCOUNT_SERVICE_H_
6 #define CHROME_BROWSER_SUPERVISED_USER_CHILD_ACCOUNTS_CHILD_ACCOUNT_SERVICE_H_
8 #include <string>
9 #include <vector>
11 #include "base/macros.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h"
14 #include "base/time/time.h"
15 #include "base/timer/timer.h"
16 #include "chrome/browser/supervised_user/child_accounts/family_info_fetcher.h"
17 #include "chrome/browser/supervised_user/supervised_user_service.h"
18 #include "components/keyed_service/core/keyed_service.h"
19 #include "components/signin/core/browser/account_service_flag_fetcher.h"
20 #include "components/signin/core/browser/signin_manager_base.h"
21 #include "net/base/backoff_entry.h"
23 namespace base {
24 class FilePath;
27 class Profile;
29 // This class handles detection of child accounts (on sign-in as well as on
30 // browser restart), and triggers the appropriate behavior (e.g. enable the
31 // supervised user experience, fetch information about the parent(s)).
32 class ChildAccountService : public KeyedService,
33 public FamilyInfoFetcher::Consumer,
34 public SigninManagerBase::Observer,
35 public SupervisedUserService::Delegate {
36 public:
37 ~ChildAccountService() override;
39 static bool IsChildAccountDetectionEnabled();
41 void Init();
43 // Sets whether the signed-in account is a child account.
44 // Public so it can be called on platforms where child account detection
45 // happens outside of this class (like Android).
46 void SetIsChildAccount(bool is_child_account);
48 // KeyedService:
49 void Shutdown() override;
51 private:
52 friend class ChildAccountServiceFactory;
53 // Use |ChildAccountServiceFactory::GetForProfile(...)| to get an instance of
54 // this service.
55 explicit ChildAccountService(Profile* profile);
57 // SupervisedUserService::Delegate implementation.
58 bool SetActive(bool active) override;
59 base::FilePath GetBlacklistPath() const override;
60 GURL GetBlacklistURL() const override;
61 std::string GetSafeSitesCx() const override;
63 // SigninManagerBase::Observer implementation.
64 void GoogleSigninSucceeded(const std::string& account_id,
65 const std::string& username,
66 const std::string& password) override;
67 void GoogleSignedOut(const std::string& account_id,
68 const std::string& username) override;
70 // FamilyInfoFetcher::Consumer implementation.
71 void OnGetFamilyMembersSuccess(
72 const std::vector<FamilyInfoFetcher::FamilyMember>& members) override;
73 void OnFailure(FamilyInfoFetcher::ErrorCode error) override;
75 void StartFetchingFamilyInfo();
76 void CancelFetchingFamilyInfo();
77 void ScheduleNextFamilyInfoUpdate(base::TimeDelta delay);
79 void StartFetchingServiceFlags();
80 void CancelFetchingServiceFlags();
81 void OnFlagsFetched(AccountServiceFlagFetcher::ResultCode,
82 const std::vector<std::string>& flags);
83 void ScheduleNextStatusFlagUpdate(base::TimeDelta delay);
85 void PropagateChildStatusToUser(bool is_child);
87 void SetFirstCustodianPrefs(const FamilyInfoFetcher::FamilyMember& custodian);
88 void SetSecondCustodianPrefs(
89 const FamilyInfoFetcher::FamilyMember& custodian);
90 void ClearFirstCustodianPrefs();
91 void ClearSecondCustodianPrefs();
93 void EnableExperimentalFiltering();
95 // Owns us via the KeyedService mechanism.
96 Profile* profile_;
98 bool active_;
100 // The user for which we are currently trying to fetch the child account flag.
101 // Empty when we are not currently fetching.
102 std::string account_id_;
104 scoped_ptr<AccountServiceFlagFetcher> flag_fetcher_;
105 // If fetching the account service flag fails, retry with exponential backoff.
106 base::OneShotTimer<ChildAccountService> flag_fetch_timer_;
107 net::BackoffEntry flag_fetch_backoff_;
109 scoped_ptr<FamilyInfoFetcher> family_fetcher_;
110 // If fetching the family info fails, retry with exponential backoff.
111 base::OneShotTimer<ChildAccountService> family_fetch_timer_;
112 net::BackoffEntry family_fetch_backoff_;
114 base::WeakPtrFactory<ChildAccountService> weak_ptr_factory_;
116 DISALLOW_COPY_AND_ASSIGN(ChildAccountService);
119 #endif // CHROME_BROWSER_SUPERVISED_USER_CHILD_ACCOUNTS_CHILD_ACCOUNT_SERVICE_H_