1 // Copyright 2013 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. 4 5 #ifndef CHROME_BROWSER_MANAGED_MODE_CUSTODIAN_PROFILE_DOWNLOADER_SERVICE_H_ 6 #define CHROME_BROWSER_MANAGED_MODE_CUSTODIAN_PROFILE_DOWNLOADER_SERVICE_H_ 7 8 #include "base/callback.h" 9 #include "chrome/browser/profiles/profile_downloader.h" 10 #include "chrome/browser/profiles/profile_downloader_delegate.h" 11 #include "components/browser_context_keyed_service/browser_context_keyed_service.h" 12 13 class CustodianProfileDownloaderService : public BrowserContextKeyedService, 14 public ProfileDownloaderDelegate { 15 public: 16 // Callback for DownloadProfile() below. If the GAIA profile download is 17 // successful, the profile's full (display) name will be returned. 18 typedef base::Callback<void(const string16& /* full name */)> 19 DownloadProfileCallback; 20 21 virtual ~CustodianProfileDownloaderService(); 22 23 // Downloads the GAIA account information for the |custodian_profile_|. 24 // This is a best-effort attempt with no error reporting nor timeout. 25 // If the download is successful, the profile's full (display) name will 26 // be returned via the callback. If the download fails or never completes, 27 // the callback will not be called. 28 void DownloadProfile(const DownloadProfileCallback& callback); 29 30 // ProfileDownloaderDelegate: 31 virtual bool NeedsProfilePicture() const OVERRIDE; 32 virtual int GetDesiredImageSideLength() const OVERRIDE; 33 virtual std::string GetCachedPictureURL() const OVERRIDE; 34 virtual Profile* GetBrowserProfile() OVERRIDE; 35 virtual void OnProfileDownloadSuccess(ProfileDownloader* downloader) OVERRIDE; 36 virtual void OnProfileDownloadFailure( 37 ProfileDownloader* downloader, 38 ProfileDownloaderDelegate::FailureReason reason) OVERRIDE; 39 40 private: 41 friend class CustodianProfileDownloaderServiceFactory; 42 // Use |CustodianProfileDownloaderServiceFactory::GetForProfile(...)| to 43 // get instances of this service. 44 explicit CustodianProfileDownloaderService(Profile* custodian_profile); 45 46 scoped_ptr<ProfileDownloader> profile_downloader_; 47 DownloadProfileCallback download_callback_; 48 49 // Owns us via the BrowserContextKeyedService mechanism. 50 Profile* custodian_profile_; 51 52 std::string last_downloaded_profile_email_; 53 std::string in_progress_profile_email_; 54 }; 55 56 #endif // CHROME_BROWSER_MANAGED_MODE_CUSTODIAN_PROFILE_DOWNLOADER_SERVICE_H_ 57