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