1 // Copyright (c) 2012 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_SIGNIN_ABOUT_SIGNIN_INTERNALS_H_
6 #define CHROME_BROWSER_SIGNIN_ABOUT_SIGNIN_INTERNALS_H_
11 #include "base/memory/scoped_ptr.h"
12 #include "base/observer_list.h"
13 #include "base/values.h"
14 #include "chrome/browser/signin/signin_internals_util.h"
15 #include "chrome/browser/signin/signin_manager.h"
16 #include "chrome/browser/signin/signin_manager_factory.h"
17 #include "chrome/common/chrome_version_info.h"
18 #include "components/browser_context_keyed_service/browser_context_keyed_service.h"
22 // This class collects authentication, signin and token information
23 // to propagate to about:signin-internals via SigninInternalsUI.
24 class AboutSigninInternals
25 : public BrowserContextKeyedService,
26 public signin_internals_util::SigninDiagnosticsObserver {
30 // |info| will contain the dictionary of signin_status_ values as indicated
31 // in the comments for GetSigninStatus() below.
32 virtual void OnSigninStateChanged(scoped_ptr<DictionaryValue> info) = 0;
35 AboutSigninInternals();
36 virtual ~AboutSigninInternals();
38 // Each instance of SigninInternalsUI adds itself as an observer to be
39 // notified of all updates that AboutSigninInternals receives.
40 void AddSigninObserver(Observer* observer);
41 void RemoveSigninObserver(Observer* observer);
43 // Pulls all signin values that have been persisted in the user prefs.
44 void RefreshSigninPrefs();
46 // SigninManager::SigninDiagnosticsObserver implementation.
47 virtual void NotifySigninValueChanged(
48 const signin_internals_util::UntimedSigninStatusField& field,
49 const std::string& value) OVERRIDE;
51 virtual void NotifySigninValueChanged(
52 const signin_internals_util::TimedSigninStatusField& field,
53 const std::string& value) OVERRIDE;
55 void Initialize(Profile* profile);
57 // BrowserContextKeyedService implementation.
58 virtual void Shutdown() OVERRIDE;
60 // Returns a dictionary of values in signin_status_ for use in
61 // about:signin-internals. The values are formatted as shown -
64 // [ {"title": "Basic Information",
65 // "data": [List of {"label" : "foo-field", "value" : "foo"} elems]
67 // { "title": "Detailed Information",
68 // "data": [List of {"label" : "foo-field", "value" : "foo"} elems]
71 // [ List of {"name": "foo-name", "token" : "foo-token",
72 // "status": "foo_stat", "time" : "foo_time"} elems]
74 scoped_ptr<DictionaryValue> GetSigninStatus();
76 // Returns the time of the last fetch/refresh for the token specified by
77 // |token_name|. See signin_internals_util::kTokenPrefsArray for valid token
78 // names. If |token_name| is invalid, returns base::Time().
79 base::Time GetTokenTime(const std::string& token_name) const;
82 void NotifyObservers();
84 // Weak pointer to parent profile.
87 // Encapsulates the actual signin and token related values.
88 // Most of the values are mirrored in the prefs for persistance.
89 signin_internals_util::SigninStatus signin_status_;
91 ObserverList<Observer> signin_observers_;
93 DISALLOW_COPY_AND_ASSIGN(AboutSigninInternals);
96 #endif // CHROME_BROWSER_SIGNIN_ABOUT_SIGNIN_INTERNALS_H_