summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/webui/profile_info_watcher.h
blob: 114282d6a329af6c410104b0f2c4f80dcc11a7c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_UI_WEBUI_PROFILE_INFO_WATCHER_H_
#define CHROME_BROWSER_UI_WEBUI_PROFILE_INFO_WATCHER_H_

#include <string>

#include "base/callback.h"
#include "base/macros.h"
#include "chrome/browser/profiles/profile_attributes_storage.h"
#include "components/prefs/pref_member.h"

class Profile;
class SigninManagerBase;

// Watches profiles for changes in their cached info (e.g. the authenticated
// username changes).
class ProfileInfoWatcher : public ProfileAttributesStorage::Observer {
 public:
  ProfileInfoWatcher(Profile* profile, const base::Closure& callback);
  ~ProfileInfoWatcher() override;

  // Gets the authenticated username (e.g. username@gmail.com) for |profile_|.
  std::string GetAuthenticatedUsername() const;

 private:
  // ProfileAttributesStorage::Observer:
  void OnProfileAuthInfoChanged(const base::FilePath& profile_path) override;

  // Gets the SigninManagerBase for |profile_|.
  SigninManagerBase* GetSigninManager() const;

  // Runs |callback_| when a profile changes. No-ops if |GetSigninManager()|
  // returns nullptr.
  void RunCallback();

  // Weak reference to the profile this class observes.
  Profile* const profile_;

  // Called when the authenticated username changes.
  base::Closure callback_;

  BooleanPrefMember signin_allowed_pref_;

  DISALLOW_COPY_AND_ASSIGN(ProfileInfoWatcher);
};

#endif  // CHROME_BROWSER_UI_WEBUI_PROFILE_INFO_WATCHER_H_