OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_SUPERVISED_USER_CHILD_ACCOUNTS_CHILD_ACCOUNT_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_SUPERVISED_USER_CHILD_ACCOUNTS_CHILD_ACCOUNT_SERVICE_H_ |
6 #define CHROME_BROWSER_SUPERVISED_USER_CHILD_ACCOUNTS_CHILD_ACCOUNT_SERVICE_H_ | 6 #define CHROME_BROWSER_SUPERVISED_USER_CHILD_ACCOUNTS_CHILD_ACCOUNT_SERVICE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
| 11 #include "base/callback.h" |
11 #include "base/macros.h" | 12 #include "base/macros.h" |
12 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
13 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
14 #include "base/time/time.h" | 15 #include "base/time/time.h" |
15 #include "base/timer/timer.h" | 16 #include "base/timer/timer.h" |
16 #include "chrome/browser/supervised_user/child_accounts/family_info_fetcher.h" | 17 #include "chrome/browser/supervised_user/child_accounts/family_info_fetcher.h" |
17 #include "chrome/browser/supervised_user/supervised_user_service.h" | 18 #include "chrome/browser/supervised_user/supervised_user_service.h" |
18 #include "components/keyed_service/core/keyed_service.h" | 19 #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/account_service_flag_fetcher.h" |
20 #include "components/signin/core/browser/signin_manager_base.h" | 21 #include "components/signin/core/browser/signin_manager_base.h" |
21 #include "net/base/backoff_entry.h" | 22 #include "net/base/backoff_entry.h" |
22 | 23 |
23 namespace base { | 24 namespace base { |
24 class FilePath; | 25 class FilePath; |
25 } | 26 } |
26 | 27 |
| 28 namespace user_prefs { |
| 29 class PrefRegistrySyncable; |
| 30 } |
| 31 |
27 class Profile; | 32 class Profile; |
28 | 33 |
29 // This class handles detection of child accounts (on sign-in as well as on | 34 // 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 | 35 // browser restart), and triggers the appropriate behavior (e.g. enable the |
31 // supervised user experience, fetch information about the parent(s)). | 36 // supervised user experience, fetch information about the parent(s)). |
32 class ChildAccountService : public KeyedService, | 37 class ChildAccountService : public KeyedService, |
33 public FamilyInfoFetcher::Consumer, | 38 public FamilyInfoFetcher::Consumer, |
34 public SigninManagerBase::Observer, | 39 public SigninManagerBase::Observer, |
35 public SupervisedUserService::Delegate { | 40 public SupervisedUserService::Delegate { |
36 public: | 41 public: |
37 ~ChildAccountService() override; | 42 ~ChildAccountService() override; |
38 | 43 |
39 static bool IsChildAccountDetectionEnabled(); | 44 static bool IsChildAccountDetectionEnabled(); |
40 | 45 |
| 46 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); |
| 47 |
41 void Init(); | 48 void Init(); |
42 | 49 |
43 // Sets whether the signed-in account is a child account. | 50 // Sets whether the signed-in account is a child account. |
44 // Public so it can be called on platforms where child account detection | 51 // Public so it can be called on platforms where child account detection |
45 // happens outside of this class (like Android). | 52 // happens outside of this class (like Android). |
46 void SetIsChildAccount(bool is_child_account); | 53 void SetIsChildAccount(bool is_child_account); |
47 | 54 |
| 55 // Responds whether at least one request for child status was successful. |
| 56 // And we got answer whether the profile belongs to a child account or not. |
| 57 bool IsChildAccountStatusKnown(); |
| 58 |
48 // KeyedService: | 59 // KeyedService: |
49 void Shutdown() override; | 60 void Shutdown() override; |
50 | 61 |
| 62 void AddChildStatusReceivedCallback(const base::Closure& callback); |
| 63 |
51 private: | 64 private: |
52 friend class ChildAccountServiceFactory; | 65 friend class ChildAccountServiceFactory; |
53 // Use |ChildAccountServiceFactory::GetForProfile(...)| to get an instance of | 66 // Use |ChildAccountServiceFactory::GetForProfile(...)| to get an instance of |
54 // this service. | 67 // this service. |
55 explicit ChildAccountService(Profile* profile); | 68 explicit ChildAccountService(Profile* profile); |
56 | 69 |
57 // SupervisedUserService::Delegate implementation. | 70 // SupervisedUserService::Delegate implementation. |
58 bool SetActive(bool active) override; | 71 bool SetActive(bool active) override; |
59 base::FilePath GetBlacklistPath() const override; | 72 base::FilePath GetBlacklistPath() const override; |
60 GURL GetBlacklistURL() const override; | 73 GURL GetBlacklistURL() const override; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 scoped_ptr<AccountServiceFlagFetcher> flag_fetcher_; | 117 scoped_ptr<AccountServiceFlagFetcher> flag_fetcher_; |
105 // If fetching the account service flag fails, retry with exponential backoff. | 118 // If fetching the account service flag fails, retry with exponential backoff. |
106 base::OneShotTimer<ChildAccountService> flag_fetch_timer_; | 119 base::OneShotTimer<ChildAccountService> flag_fetch_timer_; |
107 net::BackoffEntry flag_fetch_backoff_; | 120 net::BackoffEntry flag_fetch_backoff_; |
108 | 121 |
109 scoped_ptr<FamilyInfoFetcher> family_fetcher_; | 122 scoped_ptr<FamilyInfoFetcher> family_fetcher_; |
110 // If fetching the family info fails, retry with exponential backoff. | 123 // If fetching the family info fails, retry with exponential backoff. |
111 base::OneShotTimer<ChildAccountService> family_fetch_timer_; | 124 base::OneShotTimer<ChildAccountService> family_fetch_timer_; |
112 net::BackoffEntry family_fetch_backoff_; | 125 net::BackoffEntry family_fetch_backoff_; |
113 | 126 |
| 127 // Callbacks to run when the user status becomes known. |
| 128 std::vector<base::Closure> status_received_callback_list_; |
| 129 |
114 base::WeakPtrFactory<ChildAccountService> weak_ptr_factory_; | 130 base::WeakPtrFactory<ChildAccountService> weak_ptr_factory_; |
115 | 131 |
116 DISALLOW_COPY_AND_ASSIGN(ChildAccountService); | 132 DISALLOW_COPY_AND_ASSIGN(ChildAccountService); |
117 }; | 133 }; |
118 | 134 |
119 #endif // CHROME_BROWSER_SUPERVISED_USER_CHILD_ACCOUNTS_CHILD_ACCOUNT_SERVICE_H
_ | 135 #endif // CHROME_BROWSER_SUPERVISED_USER_CHILD_ACCOUNTS_CHILD_ACCOUNT_SERVICE_H
_ |
OLD | NEW |