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   void Initialize(Profile* profile);
     56 
     57   // BrowserContextKeyedService implementation.
     58   virtual void Shutdown() OVERRIDE;
     59 
     60   // Returns a dictionary of values in signin_status_ for use in
     61   // about:signin-internals. The values are formatted as shown -
     62   //
     63   // { "signin_info" :
     64   //     [ {"title": "Basic Information",
     65   //        "data": [List of {"label" : "foo-field", "value" : "foo"} elems]
     66   //       },
     67   //       { "title": "Detailed Information",
     68   //        "data": [List of {"label" : "foo-field", "value" : "foo"} elems]
     69   //       }],
     70   //   "token_info" :
     71   //     [ List of {"name": "foo-name", "token" : "foo-token",
     72   //                 "status": "foo_stat", "time" : "foo_time"} elems]
     73   //  }
     74   scoped_ptr<DictionaryValue> GetSigninStatus();
     75 
     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;
     80 
     81  private:
     82   void NotifyObservers();
     83 
     84   // Weak pointer to parent profile.
     85   Profile* profile_;
     86 
     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_;
     90 
     91   ObserverList<Observer> signin_observers_;
     92 
     93   DISALLOW_COPY_AND_ASSIGN(AboutSigninInternals);
     94 };
     95 
     96 #endif  // CHROME_BROWSER_SIGNIN_ABOUT_SIGNIN_INTERNALS_H_
     97