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.
5 #ifndef CHROME_BROWSER_PROFILES_GAIA_INFO_UPDATE_SERVICE_H_
6 #define CHROME_BROWSER_PROFILES_GAIA_INFO_UPDATE_SERVICE_H_
8 #include "base/compiler_specific.h"
9 #include "base/gtest_prod_util.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/prefs/pref_member.h"
12 #include "base/timer.h"
13 #include "chrome/browser/profiles/profile_downloader.h"
14 #include "chrome/browser/profiles/profile_downloader_delegate.h"
15 #include "chrome/browser/profiles/profile_keyed_service.h"
18 class ProfileDownloader
;
20 // 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 class GAIAInfoUpdateService
: public ProfileDownloaderDelegate
,
23 public ProfileKeyedService
{
25 explicit GAIAInfoUpdateService(Profile
* profile
);
26 virtual ~GAIAInfoUpdateService();
28 // Updates the GAIA info for the profile associated with this instance.
29 virtual void Update();
31 // Checks if downloading GAIA info for the given profile is allowed.
32 static bool ShouldUseGAIAProfileInfo(Profile
* profile
);
34 // ProfileDownloaderDelegate:
35 virtual bool NeedsProfilePicture() const OVERRIDE
;
36 virtual int GetDesiredImageSideLength() const OVERRIDE
;
37 virtual Profile
* GetBrowserProfile() OVERRIDE
;
38 virtual std::string
GetCachedPictureURL() const OVERRIDE
;
39 virtual void OnProfileDownloadSuccess(ProfileDownloader
* downloader
) OVERRIDE
;
40 virtual void OnProfileDownloadFailure(
41 ProfileDownloader
* downloader
,
42 ProfileDownloaderDelegate::FailureReason reason
) OVERRIDE
;
45 FRIEND_TEST_ALL_PREFIXES(GAIAInfoUpdateServiceTest
, ScheduleUpdate
);
47 void OnUsernameChanged();
48 void ScheduleNextUpdate();
51 scoped_ptr
<ProfileDownloader
> profile_image_downloader_
;
52 StringPrefMember username_pref_
;
53 base::Time last_updated_
;
54 base::OneShotTimer
<GAIAInfoUpdateService
> timer_
;
56 DISALLOW_COPY_AND_ASSIGN(GAIAInfoUpdateService
);
59 #endif // CHROME_BROWSER_PROFILES_GAIA_INFO_UPDATE_SERVICE_H_