| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_SIGNIN_SIGNIN_TRACKER_H_ | 5 #ifndef CHROME_BROWSER_SIGNIN_SIGNIN_TRACKER_H_ |
| 6 #define CHROME_BROWSER_SIGNIN_SIGNIN_TRACKER_H_ | 6 #define CHROME_BROWSER_SIGNIN_SIGNIN_TRACKER_H_ |
| 7 | 7 |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "content/public/browser/notification_observer.h" | 9 #include "chrome/browser/signin/signin_manager_base.h" |
| 10 #include "content/public/browser/notification_registrar.h" | |
| 11 #include "content/public/browser/notification_types.h" | |
| 12 #include "google_apis/gaia/google_service_auth_error.h" | 10 #include "google_apis/gaia/google_service_auth_error.h" |
| 13 #include "google_apis/gaia/merge_session_helper.h" | 11 #include "google_apis/gaia/merge_session_helper.h" |
| 14 #include "google_apis/gaia/oauth2_token_service.h" | 12 #include "google_apis/gaia/oauth2_token_service.h" |
| 15 | 13 |
| 16 class Profile; | 14 class Profile; |
| 17 | 15 |
| 18 // The signin flow logic is spread across several classes with varying | 16 // The signin flow logic is spread across several classes with varying |
| 19 // responsibilities: | 17 // responsibilities: |
| 20 // | 18 // |
| 21 // SigninTracker (this class) - This class listens to notifications from various | 19 // SigninTracker (this class) - This class listens to notifications from various |
| (...skipping 19 matching lines...) Expand all Loading... |
| 41 // SigninTracker, SigninManager only knows about the GAIA login state and is | 39 // SigninTracker, SigninManager only knows about the GAIA login state and is |
| 42 // not aware of the state of any signed in services. | 40 // not aware of the state of any signed in services. |
| 43 // | 41 // |
| 44 // OAuth2TokenService - Maintains and manages OAuth2 tokens for the accounts | 42 // OAuth2TokenService - Maintains and manages OAuth2 tokens for the accounts |
| 45 // connected to this profile. | 43 // connected to this profile. |
| 46 // | 44 // |
| 47 // ProfileSyncService - Provides the external API for interacting with the | 45 // ProfileSyncService - Provides the external API for interacting with the |
| 48 // sync framework. Listens for notifications for tokens to know when to startup | 46 // sync framework. Listens for notifications for tokens to know when to startup |
| 49 // sync, and provides an Observer interface to notify the UI layer of changes | 47 // sync, and provides an Observer interface to notify the UI layer of changes |
| 50 // in sync state so they can be reflected in the UI. | 48 // in sync state so they can be reflected in the UI. |
| 51 class SigninTracker : public content::NotificationObserver, | 49 class SigninTracker : public SigninManagerBase::Observer, |
| 52 public OAuth2TokenService::Observer, | 50 public OAuth2TokenService::Observer, |
| 53 public MergeSessionHelper::Observer { | 51 public MergeSessionHelper::Observer { |
| 54 public: | 52 public: |
| 55 class Observer { | 53 class Observer { |
| 56 public: | 54 public: |
| 57 // The signin attempt failed, and the cause is passed in |error|. | 55 // The signin attempt failed, and the cause is passed in |error|. |
| 58 virtual void SigninFailed(const GoogleServiceAuthError& error) = 0; | 56 virtual void SigninFailed(const GoogleServiceAuthError& error) = 0; |
| 59 | 57 |
| 60 // The signin attempt succeeded. | 58 // The signin attempt succeeded. |
| 61 virtual void SigninSuccess() = 0; | 59 virtual void SigninSuccess() = 0; |
| 62 | 60 |
| 63 // The signed in account has been merged into the content area cookie jar. | 61 // The signed in account has been merged into the content area cookie jar. |
| 64 // This will be called only after a call to SigninSuccess(). | 62 // This will be called only after a call to SigninSuccess(). |
| 65 virtual void MergeSessionComplete(const GoogleServiceAuthError& error) = 0; | 63 virtual void MergeSessionComplete(const GoogleServiceAuthError& error) = 0; |
| 66 }; | 64 }; |
| 67 | 65 |
| 68 // Creates a SigninTracker that tracks the signin status on the passed | 66 // Creates a SigninTracker that tracks the signin status on the passed |
| 69 // |profile|, and notifies the |observer| on status changes. |observer| must | 67 // |profile|, and notifies the |observer| on status changes. |observer| must |
| 70 // be non-null and must outlive the SigninTracker. | 68 // be non-null and must outlive the SigninTracker. |
| 71 SigninTracker(Profile* profile, Observer* observer); | 69 SigninTracker(Profile* profile, Observer* observer); |
| 72 virtual ~SigninTracker(); | 70 virtual ~SigninTracker(); |
| 73 | 71 |
| 74 // content::NotificationObserver implementation. | 72 // SigninManagerBase::Observer implementation. |
| 75 virtual void Observe(int type, | 73 virtual void GoogleSigninFailed(const GoogleServiceAuthError& error) OVERRIDE; |
| 76 const content::NotificationSource& source, | |
| 77 const content::NotificationDetails& details) OVERRIDE; | |
| 78 | 74 |
| 79 // OAuth2TokenService::Observer implementation. | 75 // OAuth2TokenService::Observer implementation. |
| 80 virtual void OnRefreshTokenAvailable(const std::string& account_id) OVERRIDE; | 76 virtual void OnRefreshTokenAvailable(const std::string& account_id) OVERRIDE; |
| 81 virtual void OnRefreshTokenRevoked(const std::string& account_id) OVERRIDE; | 77 virtual void OnRefreshTokenRevoked(const std::string& account_id) OVERRIDE; |
| 82 | 78 |
| 83 private: | 79 private: |
| 84 // Initializes this by adding notifications and observers. | 80 // Initializes this by adding notifications and observers. |
| 85 void Initialize(); | 81 void Initialize(); |
| 86 | 82 |
| 87 // MergeSessionHelper::Observer implementation. | 83 // MergeSessionHelper::Observer implementation. |
| 88 virtual void MergeSessionCompleted( | 84 virtual void MergeSessionCompleted( |
| 89 const std::string& account_id, | 85 const std::string& account_id, |
| 90 const GoogleServiceAuthError& error) OVERRIDE; | 86 const GoogleServiceAuthError& error) OVERRIDE; |
| 91 | 87 |
| 92 // The profile whose signin status we are tracking. | 88 // The profile whose signin status we are tracking. |
| 93 Profile* profile_; | 89 Profile* profile_; |
| 94 | 90 |
| 95 // Weak pointer to the observer we call when the signin state changes. | 91 // Weak pointer to the observer we call when the signin state changes. |
| 96 Observer* observer_; | 92 Observer* observer_; |
| 97 | 93 |
| 98 // Used to listen to notifications from the SigninManager. | |
| 99 content::NotificationRegistrar registrar_; | |
| 100 | |
| 101 DISALLOW_COPY_AND_ASSIGN(SigninTracker); | 94 DISALLOW_COPY_AND_ASSIGN(SigninTracker); |
| 102 }; | 95 }; |
| 103 | 96 |
| 104 #endif // CHROME_BROWSER_SIGNIN_SIGNIN_TRACKER_H_ | 97 #endif // CHROME_BROWSER_SIGNIN_SIGNIN_TRACKER_H_ |
| OLD | NEW |