Home | History | Annotate | Download | only in signin
      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.
      4 
      5 #ifndef CHROME_BROWSER_SIGNIN_ABOUT_SIGNIN_INTERNALS_H_
      6 #define CHROME_BROWSER_SIGNIN_ABOUT_SIGNIN_INTERNALS_H_
      7 
      8 #include <map>
      9 #include <string>
     10 
     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"
     19 
     20 class Profile;
     21 
     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 {
     27  public:
     28   class Observer {
     29    public:
     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;
     33   };
     34 
     35   AboutSigninInternals();
     36   virtual ~AboutSigninInternals();
     37 
     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);
     42 
     43   // Pulls all signin values that have been persisted in the user prefs.
     44   void RefreshSigninPrefs();
     45 
     46   // SigninManager::SigninDiagnosticsObserver implementation.
     47   virtual void NotifySigninValueChanged(
     48       const signin_internals_util::UntimedSigninStatusField& field,
     49       const std::string& value) OVERRIDE;
     50 
     51   virtual void NotifySigninValueChanged(
     52       const signin_internals_util::TimedSigninStatusField& field,
     53       const std::string& value) OVERRIDE;
     54 
     55   virtual void NotifyTokenReceivedSuccess(const std::string& token_name,
     56                                           const std::string& token,
     57                                           bool update_time) OVERRIDE;
     58 
     59   virtual void NotifyTokenReceivedFailure(const std::string& token_name,
     60                                           const std::string& error) OVERRIDE;
     61 
     62   virtual void NotifyClearStoredToken(const std::string& token_name) OVERRIDE;
     63 
     64   void Initialize(Profile* profile);
     65 
     66   // BrowserContextKeyedService implementation.
     67   virtual void Shutdown() OVERRIDE;
     68 
     69   // Returns a dictionary of values in signin_status_ for use in
     70   // about:signin-internals. The values are formatted as shown -
     71   //
     72   // { "signin_info" :
     73   //     [ {"title": "Basic Information",
     74   //        "data": [List of {"label" : "foo-field", "value" : "foo"} elems]
     75   //       },
     76   //       { "title": "Detailed Information",
     77   //        "data": [List of {"label" : "foo-field", "value" : "foo"} elems]
     78   //       }],
     79   //   "token_info" :
     80   //     [ List of {"name": "foo-name", "token" : "foo-token",
     81   //                 "status": "foo_stat", "time" : "foo_time"} elems]
     82   //  }
     83   scoped_ptr<DictionaryValue> GetSigninStatus();
     84 
     85   // Returns the time of the last fetch/refresh for the token specified by
     86   // |token_name|. See signin_internals_util::kTokenPrefsArray for valid token
     87   // names. If |token_name| is invalid, returns base::Time().
     88   base::Time GetTokenTime(const std::string& token_name) const;
     89 
     90  private:
     91   void NotifyObservers();
     92 
     93   // Weak pointer to parent profile.
     94   Profile* profile_;
     95 
     96   // Encapsulates the actual signin and token related values.
     97   // Most of the values are mirrored in the prefs for persistance.
     98   signin_internals_util::SigninStatus signin_status_;
     99 
    100   ObserverList<Observer> signin_observers_;
    101 
    102   DISALLOW_COPY_AND_ASSIGN(AboutSigninInternals);
    103 };
    104 
    105 #endif  // CHROME_BROWSER_SIGNIN_ABOUT_SIGNIN_INTERNALS_H_
    106