| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_CHROMEOS_LOGIN_PROFILE_IMAGE_DOWNLOADER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_PROFILE_IMAGE_DOWNLOADER_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_PROFILE_IMAGE_DOWNLOADER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_PROFILE_IMAGE_DOWNLOADER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 // Reports on success or failure of Profile image download. | 26 // Reports on success or failure of Profile image download. |
| 27 class Delegate { | 27 class Delegate { |
| 28 public: | 28 public: |
| 29 virtual ~Delegate() {} | 29 virtual ~Delegate() {} |
| 30 | 30 |
| 31 // Called when image is successfully downloaded and decoded. | 31 // Called when image is successfully downloaded and decoded. |
| 32 virtual void OnDownloadSuccess(const SkBitmap& image) = 0; | 32 virtual void OnDownloadSuccess(const SkBitmap& image) = 0; |
| 33 | 33 |
| 34 // Called on download failure. | 34 // Called on download failure. |
| 35 virtual void OnDownloadFailure() {} | 35 virtual void OnDownloadFailure() {} |
| 36 |
| 37 // Called when user has the default profile image and we won't download |
| 38 // it. |
| 39 virtual void OnDownloadDefaultImage() {} |
| 36 }; | 40 }; |
| 37 | 41 |
| 38 explicit ProfileImageDownloader(Delegate* delegate); | 42 explicit ProfileImageDownloader(Delegate* delegate); |
| 39 virtual ~ProfileImageDownloader(); | 43 virtual ~ProfileImageDownloader(); |
| 40 | 44 |
| 41 // Starts downloading the picture if the necessary authorization token is | 45 // Starts downloading the picture if the necessary authorization token is |
| 42 // ready. If not, subscribes to token service and starts fetching if the | 46 // ready. If not, subscribes to token service and starts fetching if the |
| 43 // token is available. | 47 // token is available. |
| 44 void Start(); | 48 void Start(); |
| 45 | 49 |
| 46 private: | 50 private: |
| 47 // Overriden from content::URLFetcherDelegate: | 51 // Overriden from content::URLFetcherDelegate: |
| 48 virtual void OnURLFetchComplete(const content::URLFetcher* source) OVERRIDE; | 52 virtual void OnURLFetchComplete(const content::URLFetcher* source) OVERRIDE; |
| 49 | 53 |
| 50 // Overriden from ImageDecoder::Delegate: | 54 // Overriden from ImageDecoder::Delegate: |
| 51 virtual void OnImageDecoded(const ImageDecoder* decoder, | 55 virtual void OnImageDecoded(const ImageDecoder* decoder, |
| 52 const SkBitmap& decoded_image) OVERRIDE; | 56 const SkBitmap& decoded_image) OVERRIDE; |
| 53 virtual void OnDecodeImageFailed(const ImageDecoder* decoder) OVERRIDE; | 57 virtual void OnDecodeImageFailed(const ImageDecoder* decoder) OVERRIDE; |
| 54 | 58 |
| 55 // Overriden from content::NotificationObserver: | 59 // Overriden from content::NotificationObserver: |
| 56 virtual void Observe(int type, | 60 virtual void Observe(int type, |
| 57 const content::NotificationSource& source, | 61 const content::NotificationSource& source, |
| 58 const content::NotificationDetails& details) OVERRIDE; | 62 const content::NotificationDetails& details) OVERRIDE; |
| 59 | 63 |
| 60 // Searches for profile image URL in user entry response from Picasa. | 64 // Searches for profile image URL in user entry response from Picasa. |
| 61 // Returns an empty string on failure. | 65 // Returns an empty string on failure. |
| 62 std::string GetProfileImageURL(const std::string& data) const; | 66 std::string GetProfileImageURL(const std::string& data) const; |
| 63 | 67 |
| 68 // Returns true if the image url is url of the default profile picture. |
| 69 bool IsDefaultProfileImageURL(const std::string& url) const; |
| 70 |
| 64 // Issues the first request to get user profile image. | 71 // Issues the first request to get user profile image. |
| 65 void StartFetchingImage(); | 72 void StartFetchingImage(); |
| 66 | 73 |
| 67 Delegate* delegate_; | 74 Delegate* delegate_; |
| 68 std::string auth_token_; | 75 std::string auth_token_; |
| 69 scoped_ptr<content::URLFetcher> user_entry_fetcher_; | 76 scoped_ptr<content::URLFetcher> user_entry_fetcher_; |
| 70 scoped_ptr<content::URLFetcher> profile_image_fetcher_; | 77 scoped_ptr<content::URLFetcher> profile_image_fetcher_; |
| 71 content::NotificationRegistrar registrar_; | 78 content::NotificationRegistrar registrar_; |
| 72 | 79 |
| 73 DISALLOW_COPY_AND_ASSIGN(ProfileImageDownloader); | 80 DISALLOW_COPY_AND_ASSIGN(ProfileImageDownloader); |
| 74 }; | 81 }; |
| 75 | 82 |
| 76 } // namespace chromeos | 83 } // namespace chromeos |
| 77 | 84 |
| 78 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_PROFILE_IMAGE_DOWNLOADER_H_ | 85 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_PROFILE_IMAGE_DOWNLOADER_H_ |
| OLD | NEW |