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_PROFILES_PROFILE_DOWNLOADER_H_ | 5 #ifndef CHROME_BROWSER_PROFILES_PROFILE_DOWNLOADER_H_ |
6 #define CHROME_BROWSER_PROFILES_PROFILE_DOWNLOADER_H_ | 6 #define CHROME_BROWSER_PROFILES_PROFILE_DOWNLOADER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 11 matching lines...) Expand all Loading... |
22 class ProfileDownloaderDelegate; | 22 class ProfileDownloaderDelegate; |
23 class OAuth2AccessTokenFetcher; | 23 class OAuth2AccessTokenFetcher; |
24 | 24 |
25 // Downloads user profile information. The profile picture is decoded in a | 25 // Downloads user profile information. The profile picture is decoded in a |
26 // sandboxed process. | 26 // sandboxed process. |
27 class ProfileDownloader : public content::URLFetcherDelegate, | 27 class ProfileDownloader : public content::URLFetcherDelegate, |
28 public ImageDecoder::Delegate, | 28 public ImageDecoder::Delegate, |
29 public content::NotificationObserver, | 29 public content::NotificationObserver, |
30 public OAuth2AccessTokenConsumer { | 30 public OAuth2AccessTokenConsumer { |
31 public: | 31 public: |
| 32 enum PictureStatus { |
| 33 PICTURE_SUCCESS, |
| 34 PICTURE_FAILED, |
| 35 PICTURE_DEFAULT, |
| 36 PICTURE_CACHED, |
| 37 }; |
| 38 |
32 explicit ProfileDownloader(ProfileDownloaderDelegate* delegate); | 39 explicit ProfileDownloader(ProfileDownloaderDelegate* delegate); |
33 virtual ~ProfileDownloader(); | 40 virtual ~ProfileDownloader(); |
34 | 41 |
35 // Starts downloading profile information if the necessary authorization token | 42 // Starts downloading profile information if the necessary authorization token |
36 // is ready. If not, subscribes to token service and starts fetching if the | 43 // is ready. If not, subscribes to token service and starts fetching if the |
37 // token is available. Should not be called more than once. | 44 // token is available. Should not be called more than once. |
38 virtual void Start(); | 45 virtual void Start(); |
39 | 46 |
40 // On successful download this returns the full name of the user. For example | 47 // On successful download this returns the full name of the user. For example |
41 // "Pat Smith". | 48 // "Pat Smith". |
42 virtual string16 GetProfileFullName() const; | 49 virtual string16 GetProfileFullName() const; |
43 | 50 |
44 // On successful download this returns the profile picture of the user. | 51 // On successful download this returns the profile picture of the user. |
45 // For users with no profile picture set (that is, they have the default | 52 // For users with no profile picture set (that is, they have the default |
46 // profile picture) this will return an Null bitmap. | 53 // profile picture) this will return an Null bitmap. |
47 virtual SkBitmap GetProfilePicture() const; | 54 virtual SkBitmap GetProfilePicture() const; |
48 | 55 |
| 56 // Gets the profile picture status. |
| 57 virtual PictureStatus GetProfilePictureStatus() const; |
| 58 |
| 59 // Gets the URL for the profile picture. This can be cached so that the same |
| 60 // picture is not downloaded multiple times. This value should only be used |
| 61 // when the picture status is PICTURE_SUCCESS. |
| 62 virtual std::string GetProfilePictureURL() const; |
| 63 |
49 private: | 64 private: |
50 // Overriden from content::URLFetcherDelegate: | 65 // Overriden from content::URLFetcherDelegate: |
51 virtual void OnURLFetchComplete(const content::URLFetcher* source) OVERRIDE; | 66 virtual void OnURLFetchComplete(const content::URLFetcher* source) OVERRIDE; |
52 | 67 |
53 // Overriden from ImageDecoder::Delegate: | 68 // Overriden from ImageDecoder::Delegate: |
54 virtual void OnImageDecoded(const ImageDecoder* decoder, | 69 virtual void OnImageDecoded(const ImageDecoder* decoder, |
55 const SkBitmap& decoded_image) OVERRIDE; | 70 const SkBitmap& decoded_image) OVERRIDE; |
56 virtual void OnDecodeImageFailed(const ImageDecoder* decoder) OVERRIDE; | 71 virtual void OnDecodeImageFailed(const ImageDecoder* decoder) OVERRIDE; |
57 | 72 |
58 // Overriden from content::NotificationObserver: | 73 // Overriden from content::NotificationObserver: |
(...skipping 25 matching lines...) Expand all Loading... |
84 void StartFetchingOAuth2AccessToken(); | 99 void StartFetchingOAuth2AccessToken(); |
85 | 100 |
86 ProfileDownloaderDelegate* delegate_; | 101 ProfileDownloaderDelegate* delegate_; |
87 std::string auth_token_; | 102 std::string auth_token_; |
88 scoped_ptr<content::URLFetcher> user_entry_fetcher_; | 103 scoped_ptr<content::URLFetcher> user_entry_fetcher_; |
89 scoped_ptr<content::URLFetcher> profile_image_fetcher_; | 104 scoped_ptr<content::URLFetcher> profile_image_fetcher_; |
90 scoped_ptr<OAuth2AccessTokenFetcher> oauth2_access_token_fetcher_; | 105 scoped_ptr<OAuth2AccessTokenFetcher> oauth2_access_token_fetcher_; |
91 content::NotificationRegistrar registrar_; | 106 content::NotificationRegistrar registrar_; |
92 string16 profile_full_name_; | 107 string16 profile_full_name_; |
93 SkBitmap profile_picture_; | 108 SkBitmap profile_picture_; |
| 109 PictureStatus picture_status_; |
| 110 std::string picture_url_; |
94 | 111 |
95 DISALLOW_COPY_AND_ASSIGN(ProfileDownloader); | 112 DISALLOW_COPY_AND_ASSIGN(ProfileDownloader); |
96 }; | 113 }; |
97 | 114 |
98 #endif // CHROME_BROWSER_PROFILES_PROFILE_DOWNLOADER_H_ | 115 #endif // CHROME_BROWSER_PROFILES_PROFILE_DOWNLOADER_H_ |
OLD | NEW |