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/timer/timer.h"
12 #include "chrome/browser/profiles/profile_downloader.h"
13 #include "chrome/browser/profiles/profile_downloader_delegate.h"
14 #include "components/keyed_service/core/keyed_service.h"
15 #include "components/signin/core/browser/signin_manager.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 KeyedService
,
23 public ProfileDownloaderDelegate
,
24 public SigninManagerBase::Observer
{
26 explicit GAIAInfoUpdateService(Profile
* profile
);
27 ~GAIAInfoUpdateService() override
;
29 // Updates the GAIA info for the profile associated with this instance.
30 virtual void Update();
32 // Checks if downloading GAIA info for the given profile is allowed.
33 static bool ShouldUseGAIAProfileInfo(Profile
* profile
);
35 // ProfileDownloaderDelegate:
36 bool NeedsProfilePicture() const override
;
37 int GetDesiredImageSideLength() const override
;
38 Profile
* GetBrowserProfile() override
;
39 std::string
GetCachedPictureURL() const override
;
40 bool IsPreSignin() const override
;
41 void OnProfileDownloadSuccess(ProfileDownloader
* downloader
) override
;
42 void OnProfileDownloadFailure(
43 ProfileDownloader
* downloader
,
44 ProfileDownloaderDelegate::FailureReason reason
) override
;
46 // Overridden from KeyedService:
47 void Shutdown() override
;
50 FRIEND_TEST_ALL_PREFIXES(GAIAInfoUpdateServiceTest
, ScheduleUpdate
);
52 void OnUsernameChanged(const std::string
& username
);
53 void ScheduleNextUpdate();
55 // Overridden from SigninManagerBase::Observer:
56 void GoogleSigninSucceeded(const std::string
& account_id
,
57 const std::string
& username
,
58 const std::string
& password
) override
;
59 void GoogleSignedOut(const std::string
& account_id
,
60 const std::string
& username
) override
;
63 scoped_ptr
<ProfileDownloader
> profile_image_downloader_
;
64 base::Time last_updated_
;
65 base::OneShotTimer
<GAIAInfoUpdateService
> timer_
;
67 DISALLOW_COPY_AND_ASSIGN(GAIAInfoUpdateService
);
70 #endif // CHROME_BROWSER_PROFILES_GAIA_INFO_UPDATE_SERVICE_H_