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