[sql] Remove _HAS_EXCEPTIONS=0 from build info.
[chromium-blink-merge.git] / chrome / browser / supervised_user / child_accounts / child_account_service.h
blobae5f3424786b1ab2246011f5e9cf4e1b2851859c
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(
74 const AccountTrackerService::AccountInfo& info) override;
76 // FamilyInfoFetcher::Consumer implementation.
77 void OnGetFamilyMembersSuccess(
78 const std::vector<FamilyInfoFetcher::FamilyMember>& members) override;
79 void OnFailure(FamilyInfoFetcher::ErrorCode error) override;
81 void StartFetchingFamilyInfo();
82 void CancelFetchingFamilyInfo();
83 void ScheduleNextFamilyInfoUpdate(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 // Owns us via the KeyedService mechanism.
94 Profile* profile_;
96 bool active_;
98 scoped_ptr<FamilyInfoFetcher> family_fetcher_;
99 // If fetching the family info fails, retry with exponential backoff.
100 base::OneShotTimer<ChildAccountService> family_fetch_timer_;
101 net::BackoffEntry family_fetch_backoff_;
103 // Callbacks to run when the user status becomes known.
104 std::vector<base::Closure> status_received_callback_list_;
106 base::WeakPtrFactory<ChildAccountService> weak_ptr_factory_;
108 DISALLOW_COPY_AND_ASSIGN(ChildAccountService);
111 #endif // CHROME_BROWSER_SUPERVISED_USER_CHILD_ACCOUNTS_CHILD_ACCOUNT_SERVICE_H_