| 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_PROFILES_GAIA_INFO_UPDATE_SERVICE_H_ |   5 #ifndef CHROME_BROWSER_PROFILES_GAIA_INFO_UPDATE_SERVICE_H_ | 
|   6 #define CHROME_BROWSER_PROFILES_GAIA_INFO_UPDATE_SERVICE_H_ |   6 #define CHROME_BROWSER_PROFILES_GAIA_INFO_UPDATE_SERVICE_H_ | 
|   7  |   7  | 
|   8 #include "base/compiler_specific.h" |   8 #include "base/compiler_specific.h" | 
|   9 #include "base/gtest_prod_util.h" |   9 #include "base/gtest_prod_util.h" | 
|  10 #include "base/memory/scoped_ptr.h" |  10 #include "base/memory/scoped_ptr.h" | 
|  11 #include "base/prefs/public/pref_observer.h" |  | 
|  12 #include "base/timer.h" |  11 #include "base/timer.h" | 
|  13 #include "chrome/browser/api/prefs/pref_member.h" |  12 #include "chrome/browser/api/prefs/pref_member.h" | 
|  14 #include "chrome/browser/profiles/profile_downloader.h" |  13 #include "chrome/browser/profiles/profile_downloader.h" | 
|  15 #include "chrome/browser/profiles/profile_downloader_delegate.h" |  14 #include "chrome/browser/profiles/profile_downloader_delegate.h" | 
|  16  |  15  | 
|  17 class Profile; |  16 class Profile; | 
|  18 class ProfileDownloader; |  17 class ProfileDownloader; | 
|  19  |  18  | 
|  20 // This service kicks off a download of the user's name and profile picture. |  19 // This service kicks off a download of the user's name and profile picture. | 
|  21 // The results are saved in the profile info cache. |  20 // The results are saved in the profile info cache. | 
|  22 class GAIAInfoUpdateService : public ProfileDownloaderDelegate, |  21 class GAIAInfoUpdateService : public ProfileDownloaderDelegate { | 
|  23                               public PrefObserver { |  | 
|  24  public: |  22  public: | 
|  25   explicit GAIAInfoUpdateService(Profile* profile); |  23   explicit GAIAInfoUpdateService(Profile* profile); | 
|  26   virtual ~GAIAInfoUpdateService(); |  24   virtual ~GAIAInfoUpdateService(); | 
|  27  |  25  | 
|  28   // Updates the GAIA info for the profile associated with this instance. |  26   // Updates the GAIA info for the profile associated with this instance. | 
|  29   virtual void Update(); |  27   virtual void Update(); | 
|  30  |  28  | 
|  31   // Checks if downloading GAIA info for the given profile is allowed. |  29   // Checks if downloading GAIA info for the given profile is allowed. | 
|  32   static bool ShouldUseGAIAProfileInfo(Profile* profile); |  30   static bool ShouldUseGAIAProfileInfo(Profile* profile); | 
|  33  |  31  | 
|  34   // Register prefs for a profile. |  32   // Register prefs for a profile. | 
|  35   static void RegisterUserPrefs(PrefServiceBase* prefs); |  33   static void RegisterUserPrefs(PrefServiceBase* prefs); | 
|  36  |  34  | 
|  37   // ProfileDownloaderDelegate: |  35   // ProfileDownloaderDelegate: | 
|  38   virtual bool NeedsProfilePicture() const OVERRIDE; |  36   virtual bool NeedsProfilePicture() const OVERRIDE; | 
|  39   virtual int GetDesiredImageSideLength() const OVERRIDE; |  37   virtual int GetDesiredImageSideLength() const OVERRIDE; | 
|  40   virtual Profile* GetBrowserProfile() OVERRIDE; |  38   virtual Profile* GetBrowserProfile() OVERRIDE; | 
|  41   virtual std::string GetCachedPictureURL() const OVERRIDE; |  39   virtual std::string GetCachedPictureURL() const OVERRIDE; | 
|  42   virtual void OnProfileDownloadSuccess(ProfileDownloader* downloader) OVERRIDE; |  40   virtual void OnProfileDownloadSuccess(ProfileDownloader* downloader) OVERRIDE; | 
|  43   virtual void OnProfileDownloadFailure(ProfileDownloader* downloader) OVERRIDE; |  41   virtual void OnProfileDownloadFailure(ProfileDownloader* downloader) OVERRIDE; | 
|  44  |  42  | 
|  45  private: |  43  private: | 
|  46   FRIEND_TEST_ALL_PREFIXES(GAIAInfoUpdateServiceTest, ScheduleUpdate); |  44   FRIEND_TEST_ALL_PREFIXES(GAIAInfoUpdateServiceTest, ScheduleUpdate); | 
|  47  |  45  | 
|  48   // PrefObserver: |  | 
|  49   virtual void OnPreferenceChanged(PrefServiceBase* service, |  | 
|  50                                    const std::string& pref_name) OVERRIDE; |  | 
|  51  |  | 
|  52  |  | 
|  53   void OnUsernameChanged(); |  46   void OnUsernameChanged(); | 
|  54   void ScheduleNextUpdate(); |  47   void ScheduleNextUpdate(); | 
|  55  |  48  | 
|  56   Profile* profile_; |  49   Profile* profile_; | 
|  57   scoped_ptr<ProfileDownloader> profile_image_downloader_; |  50   scoped_ptr<ProfileDownloader> profile_image_downloader_; | 
|  58   StringPrefMember username_pref_; |  51   StringPrefMember username_pref_; | 
|  59   base::Time last_updated_; |  52   base::Time last_updated_; | 
|  60   base::OneShotTimer<GAIAInfoUpdateService> timer_; |  53   base::OneShotTimer<GAIAInfoUpdateService> timer_; | 
|  61  |  54  | 
|  62   DISALLOW_COPY_AND_ASSIGN(GAIAInfoUpdateService); |  55   DISALLOW_COPY_AND_ASSIGN(GAIAInfoUpdateService); | 
|  63 }; |  56 }; | 
|  64  |  57  | 
|  65 #endif  // CHROME_BROWSER_PROFILES_GAIA_INFO_UPDATE_SERVICE_H_ |  58 #endif  // CHROME_BROWSER_PROFILES_GAIA_INFO_UPDATE_SERVICE_H_ | 
| OLD | NEW |