Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / supervised_user / child_accounts / child_account_service.h
blobddd830339f48bf40c24097744681659ee4f8f238
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/callback_forward.h"
12 #include "base/macros.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/weak_ptr.h"
15 #include "base/time/time.h"
16 #include "base/timer/timer.h"
17 #include "chrome/browser/supervised_user/child_accounts/family_info_fetcher.h"
18 #include "chrome/browser/supervised_user/supervised_user_service.h"
19 #include "components/keyed_service/core/keyed_service.h"
20 #include "components/signin/core/browser/account_tracker_service.h"
21 #include "net/base/backoff_entry.h"
23 namespace base {
24 class FilePath;
27 namespace user_prefs {
28 class PrefRegistrySyncable;
31 class Profile;
33 // This class handles detection of child accounts (on sign-in as well as on
34 // browser restart), and triggers the appropriate behavior (e.g. enable the
35 // supervised user experience, fetch information about the parent(s)).
36 class ChildAccountService : public KeyedService,
37 public FamilyInfoFetcher::Consumer,
38 public AccountTrackerService::Observer,
39 public SupervisedUserService::Delegate {
40 public:
41 ~ChildAccountService() override;
43 static bool IsChildAccountDetectionEnabled();
45 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
47 void Init();
49 // Sets whether the signed-in account is a child account.
50 // Public so it can be called on platforms where child account detection
51 // happens outside of this class (like Android).
52 void SetIsChildAccount(bool is_child_account);
54 // Responds whether at least one request for child status was successful.
55 // And we got answer whether the profile belongs to a child account or not.
56 bool IsChildAccountStatusKnown();
58 // KeyedService:
59 void Shutdown() override;
61 void AddChildStatusReceivedCallback(const base::Closure& callback);
63 private:
64 friend class ChildAccountServiceFactory;
65 // Use |ChildAccountServiceFactory::GetForProfile(...)| to get an instance of
66 // this service.
67 explicit ChildAccountService(Profile* profile);
69 // SupervisedUserService::Delegate implementation.
70 bool SetActive(bool active) override;
72 // AccountTrackerService::Observer implementation.
73 void OnAccountUpdated(const AccountInfo& info) override;
75 // FamilyInfoFetcher::Consumer implementation.
76 void OnGetFamilyMembersSuccess(
77 const std::vector<FamilyInfoFetcher::FamilyMember>& members) override;
78 void OnFailure(FamilyInfoFetcher::ErrorCode error) override;
80 void StartFetchingFamilyInfo();
81 void CancelFetchingFamilyInfo();
82 void ScheduleNextFamilyInfoUpdate(base::TimeDelta delay);
84 void PropagateChildStatusToUser(bool is_child);
86 void SetFirstCustodianPrefs(const FamilyInfoFetcher::FamilyMember& custodian);
87 void SetSecondCustodianPrefs(
88 const FamilyInfoFetcher::FamilyMember& custodian);
89 void ClearFirstCustodianPrefs();
90 void ClearSecondCustodianPrefs();
92 // Owns us via the KeyedService mechanism.
93 Profile* profile_;
95 bool active_;
97 scoped_ptr<FamilyInfoFetcher> family_fetcher_;
98 // If fetching the family info fails, retry with exponential backoff.
99 base::OneShotTimer<ChildAccountService> family_fetch_timer_;
100 net::BackoffEntry family_fetch_backoff_;
102 // Callbacks to run when the user status becomes known.
103 std::vector<base::Closure> status_received_callback_list_;
105 base::WeakPtrFactory<ChildAccountService> weak_ptr_factory_;
107 DISALLOW_COPY_AND_ASSIGN(ChildAccountService);
110 #endif // CHROME_BROWSER_SUPERVISED_USER_CHILD_ACCOUNTS_CHILD_ACCOUNT_SERVICE_H_