| 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 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "chrome/browser/chromeos/login/image_decoder.h" | 13 #include "chrome/browser/chromeos/login/image_decoder.h" |
| 14 #include "content/public/browser/notification_observer.h" | 14 #include "content/public/browser/notification_observer.h" |
| 15 #include "content/public/browser/notification_registrar.h" | 15 #include "content/public/browser/notification_registrar.h" |
| 16 #include "content/public/common/url_fetcher_delegate.h" | 16 #include "content/public/common/url_fetcher_delegate.h" |
| 17 #include "googleurl/src/gurl.h" | 17 #include "googleurl/src/gurl.h" |
| 18 | 18 |
| 19 namespace chromeos { | 19 namespace chromeos { |
| 20 | 20 |
| 21 // Downloads user profile image, decodes it in a sandboxed process. | 21 // Downloads user profile image, decodes it in a sandboxed process. |
| 22 class ProfileImageDownloader : public content::URLFetcherDelegate, | 22 class ProfileImageDownloader : public content::URLFetcherDelegate, |
| 23 public ImageDecoder::Delegate, | 23 public ImageDecoder::Delegate, |
| 24 public content::NotificationObserver { | 24 public content::NotificationObserver { |
| 25 public: | 25 public: |
| 26 // Enum for reporting histograms about profile picture download. |
| 27 enum DownloadResult { |
| 28 kDownloadSuccessChanged, |
| 29 kDownloadSuccess, |
| 30 kDownloadFailure, |
| 31 kDownloadDefault, |
| 32 |
| 33 // Must be the last, convenient count. |
| 34 kDownloadResultsCount |
| 35 }; |
| 36 |
| 26 // Reports on success or failure of Profile image download. | 37 // Reports on success or failure of Profile image download. |
| 27 class Delegate { | 38 class Delegate { |
| 28 public: | 39 public: |
| 29 virtual ~Delegate() {} | 40 virtual ~Delegate() {} |
| 30 | 41 |
| 31 // Called when image is successfully downloaded and decoded. | 42 // Called when image is successfully downloaded and decoded. |
| 32 virtual void OnDownloadSuccess(const SkBitmap& image) = 0; | 43 virtual void OnDownloadSuccess(const SkBitmap& image) = 0; |
| 33 | 44 |
| 34 // Called on download failure. | 45 // Called on download failure. |
| 35 virtual void OnDownloadFailure() {} | 46 virtual void OnDownloadFailure() {} |
| 47 |
| 48 // Called when user has the default profile image and we won't download |
| 49 // it. |
| 50 virtual void OnDownloadDefaultImage() {} |
| 36 }; | 51 }; |
| 37 | 52 |
| 38 explicit ProfileImageDownloader(Delegate* delegate); | 53 explicit ProfileImageDownloader(Delegate* delegate); |
| 39 virtual ~ProfileImageDownloader(); | 54 virtual ~ProfileImageDownloader(); |
| 40 | 55 |
| 41 // Starts downloading the picture if the necessary authorization token is | 56 // Starts downloading the picture if the necessary authorization token is |
| 42 // ready. If not, subscribes to token service and starts fetching if the | 57 // ready. If not, subscribes to token service and starts fetching if the |
| 43 // token is available. | 58 // token is available. |
| 44 void Start(); | 59 void Start(); |
| 45 | 60 |
| 46 private: | 61 private: |
| 47 // Overriden from content::URLFetcherDelegate: | 62 // Overriden from content::URLFetcherDelegate: |
| 48 virtual void OnURLFetchComplete(const content::URLFetcher* source) OVERRIDE; | 63 virtual void OnURLFetchComplete(const content::URLFetcher* source) OVERRIDE; |
| 49 | 64 |
| 50 // Overriden from ImageDecoder::Delegate: | 65 // Overriden from ImageDecoder::Delegate: |
| 51 virtual void OnImageDecoded(const ImageDecoder* decoder, | 66 virtual void OnImageDecoded(const ImageDecoder* decoder, |
| 52 const SkBitmap& decoded_image) OVERRIDE; | 67 const SkBitmap& decoded_image) OVERRIDE; |
| 53 virtual void OnDecodeImageFailed(const ImageDecoder* decoder) OVERRIDE; | 68 virtual void OnDecodeImageFailed(const ImageDecoder* decoder) OVERRIDE; |
| 54 | 69 |
| 55 // Overriden from content::NotificationObserver: | 70 // Overriden from content::NotificationObserver: |
| 56 virtual void Observe(int type, | 71 virtual void Observe(int type, |
| 57 const content::NotificationSource& source, | 72 const content::NotificationSource& source, |
| 58 const content::NotificationDetails& details) OVERRIDE; | 73 const content::NotificationDetails& details) OVERRIDE; |
| 59 | 74 |
| 60 // Searches for profile image URL in user entry response from Picasa. | 75 // Searches for profile image URL in user entry response from Picasa. |
| 61 // Returns an empty string on failure. | 76 // Returns an empty string on failure. |
| 62 std::string GetProfileImageURL(const std::string& data) const; | 77 std::string GetProfileImageURL(const std::string& data) const; |
| 63 | 78 |
| 79 // Returns true if the image url is url of the default profile picture. |
| 80 bool IsDefaultProfileImageURL(const std::string& url) const; |
| 81 |
| 64 // Issues the first request to get user profile image. | 82 // Issues the first request to get user profile image. |
| 65 void StartFetchingImage(); | 83 void StartFetchingImage(); |
| 66 | 84 |
| 67 Delegate* delegate_; | 85 Delegate* delegate_; |
| 68 std::string auth_token_; | 86 std::string auth_token_; |
| 69 scoped_ptr<content::URLFetcher> user_entry_fetcher_; | 87 scoped_ptr<content::URLFetcher> user_entry_fetcher_; |
| 70 scoped_ptr<content::URLFetcher> profile_image_fetcher_; | 88 scoped_ptr<content::URLFetcher> profile_image_fetcher_; |
| 71 content::NotificationRegistrar registrar_; | 89 content::NotificationRegistrar registrar_; |
| 72 | 90 |
| 73 DISALLOW_COPY_AND_ASSIGN(ProfileImageDownloader); | 91 DISALLOW_COPY_AND_ASSIGN(ProfileImageDownloader); |
| 74 }; | 92 }; |
| 75 | 93 |
| 76 } // namespace chromeos | 94 } // namespace chromeos |
| 77 | 95 |
| 78 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_PROFILE_IMAGE_DOWNLOADER_H_ | 96 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_PROFILE_IMAGE_DOWNLOADER_H_ |
| OLD | NEW |