| 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/common/net/url_fetcher.h" | |
| 15 #include "content/public/browser/notification_observer.h" | 14 #include "content/public/browser/notification_observer.h" |
| 16 #include "content/public/browser/notification_registrar.h" | 15 #include "content/public/browser/notification_registrar.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 URLFetcher::Delegate, | 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 // 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 }; | 36 }; |
| 37 | 37 |
| 38 explicit ProfileImageDownloader(Delegate* delegate); | 38 explicit ProfileImageDownloader(Delegate* delegate); |
| 39 virtual ~ProfileImageDownloader(); | 39 virtual ~ProfileImageDownloader(); |
| 40 | 40 |
| 41 // Starts downloading the picture if the necessary authorization token is | 41 // Starts downloading the picture if the necessary authorization token is |
| 42 // ready. If not, subscribes to token service and starts fetching if the | 42 // ready. If not, subscribes to token service and starts fetching if the |
| 43 // token is available. | 43 // token is available. |
| 44 void Start(); | 44 void Start(); |
| 45 | 45 |
| 46 private: | 46 private: |
| 47 // Overriden from URLFetcher::Delegate: | 47 // Overriden from content::URLFetcherDelegate: |
| 48 virtual void OnURLFetchComplete(const URLFetcher* source, | 48 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE; |
| 49 const GURL& url, | |
| 50 const net::URLRequestStatus& status, | |
| 51 int response_code, | |
| 52 const net::ResponseCookies& cookies, | |
| 53 const std::string& data) OVERRIDE; | |
| 54 | 49 |
| 55 // Overriden from ImageDecoder::Delegate: | 50 // Overriden from ImageDecoder::Delegate: |
| 56 virtual void OnImageDecoded(const ImageDecoder* decoder, | 51 virtual void OnImageDecoded(const ImageDecoder* decoder, |
| 57 const SkBitmap& decoded_image) OVERRIDE; | 52 const SkBitmap& decoded_image) OVERRIDE; |
| 58 virtual void OnDecodeImageFailed(const ImageDecoder* decoder) OVERRIDE; | 53 virtual void OnDecodeImageFailed(const ImageDecoder* decoder) OVERRIDE; |
| 59 | 54 |
| 60 // Overriden from content::NotificationObserver: | 55 // Overriden from content::NotificationObserver: |
| 61 virtual void Observe(int type, | 56 virtual void Observe(int type, |
| 62 const content::NotificationSource& source, | 57 const content::NotificationSource& source, |
| 63 const content::NotificationDetails& details) OVERRIDE; | 58 const content::NotificationDetails& details) OVERRIDE; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 75 scoped_ptr<URLFetcher> profile_image_fetcher_; | 70 scoped_ptr<URLFetcher> profile_image_fetcher_; |
| 76 content::NotificationRegistrar registrar_; | 71 content::NotificationRegistrar registrar_; |
| 77 | 72 |
| 78 DISALLOW_COPY_AND_ASSIGN(ProfileImageDownloader); | 73 DISALLOW_COPY_AND_ASSIGN(ProfileImageDownloader); |
| 79 }; | 74 }; |
| 80 | 75 |
| 81 } // namespace chromeos | 76 } // namespace chromeos |
| 82 | 77 |
| 83 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_PROFILE_IMAGE_DOWNLOADER_H_ | 78 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_PROFILE_IMAGE_DOWNLOADER_H_ |
| 84 | 79 |
| OLD | NEW |