blob: 8a83432157134bac0765648203c010dd61f16c98 [file] [log] [blame]
[email protected]0d02c332014-06-19 20:56:501// 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.
4
Colin Blundell021e3e4d2018-04-19 01:03:245#ifndef COMPONENTS_GCM_DRIVER_ACCOUNT_TRACKER_H_
6#define COMPONENTS_GCM_DRIVER_ACCOUNT_TRACKER_H_
[email protected]0d02c332014-06-19 20:56:507
8#include <map>
dchengf064ccc2016-04-08 17:35:409#include <memory>
[email protected]0d02c332014-06-19 20:56:5010#include <string>
11#include <vector>
12
[email protected]0d02c332014-06-19 20:56:5013#include "base/observer_list.h"
Henrique Ferreiro94eb46f2019-07-03 14:38:5614#include "components/signin/public/identity_manager/identity_manager.h"
Tanmoy Mollikc15f52972019-08-19 17:36:0315#include "google_apis/gaia/core_account_id.h"
[email protected]0d02c332014-06-19 20:56:5016
Colin Blundell021e3e4d2018-04-19 01:03:2417namespace gcm {
[email protected]0d02c332014-06-19 20:56:5018
[email protected]0d02c332014-06-19 20:56:5019// The AccountTracker keeps track of what accounts exist on the
Mihai Sardarescu386e6e512019-12-02 16:20:4020// profile and the state of their credentials.
Miyoung Shin23737f62019-07-23 15:43:3121class AccountTracker : public signin::IdentityManager::Observer {
[email protected]0d02c332014-06-19 20:56:5022 public:
Mihai Sardarescu386e6e512019-12-02 16:20:4023 explicit AccountTracker(signin::IdentityManager* identity_manager);
dchengf93bb582014-10-21 16:11:5624 ~AccountTracker() override;
[email protected]0d02c332014-06-19 20:56:5025
26 class Observer {
27 public:
Mihai Sardarescu386e6e512019-12-02 16:20:4028 virtual void OnAccountSignInChanged(const CoreAccountInfo& account,
[email protected]0d02c332014-06-19 20:56:5029 bool is_signed_in) = 0;
30 };
31
32 void Shutdown();
33
34 void AddObserver(Observer* observer);
35 void RemoveObserver(Observer* observer);
36
Mihai Sardarescu386e6e512019-12-02 16:20:4037 // Returns the list of accounts that are signed in, and for which gaia account
[email protected]0d02c332014-06-19 20:56:5038 // have been fetched. The primary account for the profile will be first
Mihai Sardarescu386e6e512019-12-02 16:20:4039 // in the vector. Additional accounts will be in order of their gaia account.
40 std::vector<CoreAccountInfo> GetAccounts() const;
Colin Blundell8f1112c12018-05-23 09:10:0941
42 private:
Colin Blundell8f1112c12018-05-23 09:10:0943 struct AccountState {
Mihai Sardarescu386e6e512019-12-02 16:20:4044 CoreAccountInfo account;
Colin Blundell8f1112c12018-05-23 09:10:0945 bool is_signed_in;
46 };
47
Miyoung Shin23737f62019-07-23 15:43:3148 // signin::IdentityManager::Observer implementation.
Sylvain Defresnebbed9512019-02-08 10:54:3049 void OnPrimaryAccountSet(
50 const CoreAccountInfo& primary_account_info) override;
Colin Blundell2b8d74782018-08-02 07:27:5251 void OnPrimaryAccountCleared(
Sylvain Defresne07a3bed2019-02-11 15:02:5152 const CoreAccountInfo& previous_primary_account_info) override;
Colin Blundellbc1d0fc2018-11-30 14:56:2053 void OnRefreshTokenUpdatedForAccount(
Gyuyoung Kimb70d3c72019-02-12 01:45:4354 const CoreAccountInfo& account_info) override;
Tanmoy Mollik66a47f782019-05-20 15:05:1855 void OnRefreshTokenRemovedForAccount(
56 const CoreAccountId& account_id) override;
[email protected]0d02c332014-06-19 20:56:5057
Mihai Sardarescu386e6e512019-12-02 16:20:4058 // Add |account_info| to the lists of accounts tracked by this AccountTracker.
59 void StartTrackingAccount(const CoreAccountInfo& account_info);
[email protected]0d02c332014-06-19 20:56:5060
Mihai Sardarescu386e6e512019-12-02 16:20:4061 // Stops tracking |account_id|. Notifies all observers if the account was
62 // previously signed in.
63 void StopTrackingAccount(const CoreAccountId account_id);
[email protected]0d02c332014-06-19 20:56:5064
Mihai Sardarescu386e6e512019-12-02 16:20:4065 // Stops tracking all accounts.
[email protected]0d02c332014-06-19 20:56:5066 void StopTrackingAllAccounts();
Mihai Sardarescu386e6e512019-12-02 16:20:4067
68 // Updates the is_signed_in corresponding to the given account. Notifies all
69 // observers of the signed in state changes.
70 void UpdateSignInState(const CoreAccountId& account_id, bool is_signed_in);
[email protected]0d02c332014-06-19 20:56:5071
Miyoung Shin23737f62019-07-23 15:43:3172 signin::IdentityManager* identity_manager_;
Tanmoy Mollikc15f52972019-08-19 17:36:0373 std::map<CoreAccountId, AccountState> accounts_;
Trent Apteda250ec3ab2018-08-19 08:52:1974 base::ObserverList<Observer>::Unchecked observer_list_;
[email protected]0d02c332014-06-19 20:56:5075 bool shutdown_called_;
76};
77
Colin Blundell021e3e4d2018-04-19 01:03:2478} // namespace gcm
[email protected]0d02c332014-06-19 20:56:5079
Colin Blundell021e3e4d2018-04-19 01:03:2480#endif // COMPONENTS_GCM_DRIVER_ACCOUNT_TRACKER_H_