| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 | 43 |
| 44 // Starts downloading profile information if the necessary authorization token | 44 // Starts downloading profile information if the necessary authorization token |
| 45 // is ready. If not, subscribes to token service and starts fetching if the | 45 // is ready. If not, subscribes to token service and starts fetching if the |
| 46 // token is available. Should not be called more than once. | 46 // token is available. Should not be called more than once. |
| 47 virtual void Start(); | 47 virtual void Start(); |
| 48 | 48 |
| 49 // On successful download this returns the full name of the user. For example | 49 // On successful download this returns the full name of the user. For example |
| 50 // "Pat Smith". | 50 // "Pat Smith". |
| 51 virtual string16 GetProfileFullName() const; | 51 virtual string16 GetProfileFullName() const; |
| 52 | 52 |
| 53 // On successful download this returns G+ locale preference of the user. |
| 54 virtual std::string GetProfileLocale() const; |
| 55 |
| 53 // On successful download this returns the profile picture of the user. | 56 // On successful download this returns the profile picture of the user. |
| 54 // For users with no profile picture set (that is, they have the default | 57 // For users with no profile picture set (that is, they have the default |
| 55 // profile picture) this will return an Null bitmap. | 58 // profile picture) this will return an Null bitmap. |
| 56 virtual SkBitmap GetProfilePicture() const; | 59 virtual SkBitmap GetProfilePicture() const; |
| 57 | 60 |
| 58 // Gets the profile picture status. | 61 // Gets the profile picture status. |
| 59 virtual PictureStatus GetProfilePictureStatus() const; | 62 virtual PictureStatus GetProfilePictureStatus() const; |
| 60 | 63 |
| 61 // Gets the URL for the profile picture. This can be cached so that the same | 64 // Gets the URL for the profile picture. This can be cached so that the same |
| 62 // picture is not downloaded multiple times. This value should only be used | 65 // picture is not downloaded multiple times. This value should only be used |
| (...skipping 16 matching lines...) Expand all Loading... |
| 79 // Overriden from OAuth2TokenService::Observer: | 82 // Overriden from OAuth2TokenService::Observer: |
| 80 virtual void OnRefreshTokenAvailable(const std::string& account_id) OVERRIDE; | 83 virtual void OnRefreshTokenAvailable(const std::string& account_id) OVERRIDE; |
| 81 | 84 |
| 82 // Overriden from OAuth2TokenService::Consumer: | 85 // Overriden from OAuth2TokenService::Consumer: |
| 83 virtual void OnGetTokenSuccess(const OAuth2TokenService::Request* request, | 86 virtual void OnGetTokenSuccess(const OAuth2TokenService::Request* request, |
| 84 const std::string& access_token, | 87 const std::string& access_token, |
| 85 const base::Time& expiration_time) OVERRIDE; | 88 const base::Time& expiration_time) OVERRIDE; |
| 86 virtual void OnGetTokenFailure(const OAuth2TokenService::Request* request, | 89 virtual void OnGetTokenFailure(const OAuth2TokenService::Request* request, |
| 87 const GoogleServiceAuthError& error) OVERRIDE; | 90 const GoogleServiceAuthError& error) OVERRIDE; |
| 88 | 91 |
| 89 // Parses the entry response and gets the name and and profile image URL. | 92 // Parses the entry response and gets the name, profile image URL and locale. |
| 90 // |data| should be the JSON formatted data return by the response. | 93 // |data| should be the JSON formatted data return by the response. |
| 91 // Returns false to indicate a parsing error. | 94 // Returns false to indicate a parsing error. |
| 92 static bool GetProfileNameAndImageURL(const std::string& data, | 95 static bool ParseProfileJSON(const std::string& data, |
| 93 string16* nick_name, | 96 string16* nick_name, |
| 94 std::string* url, | 97 std::string* url, |
| 95 int image_size); | 98 int image_size, |
| 96 | 99 std::string* profile_locale); |
| 97 // Returns true if the image url is url of the default profile picture. | 100 // Returns true if the image url is url of the default profile picture. |
| 98 static bool IsDefaultProfileImageURL(const std::string& url); | 101 static bool IsDefaultProfileImageURL(const std::string& url); |
| 99 | 102 |
| 100 // Issues the first request to get user profile image. | 103 // Issues the first request to get user profile image. |
| 101 void StartFetchingImage(); | 104 void StartFetchingImage(); |
| 102 | 105 |
| 103 // Gets the authorization header. | 106 // Gets the authorization header. |
| 104 const char* GetAuthorizationHeader() const; | 107 const char* GetAuthorizationHeader() const; |
| 105 | 108 |
| 106 // Starts fetching OAuth2 access token. This is needed before the GAIA info | 109 // Starts fetching OAuth2 access token. This is needed before the GAIA info |
| 107 // can be downloaded. | 110 // can be downloaded. |
| 108 void StartFetchingOAuth2AccessToken(); | 111 void StartFetchingOAuth2AccessToken(); |
| 109 | 112 |
| 110 ProfileDownloaderDelegate* delegate_; | 113 ProfileDownloaderDelegate* delegate_; |
| 111 std::string auth_token_; | 114 std::string auth_token_; |
| 112 scoped_ptr<net::URLFetcher> user_entry_fetcher_; | 115 scoped_ptr<net::URLFetcher> user_entry_fetcher_; |
| 113 scoped_ptr<net::URLFetcher> profile_image_fetcher_; | 116 scoped_ptr<net::URLFetcher> profile_image_fetcher_; |
| 114 scoped_ptr<OAuth2TokenService::Request> oauth2_access_token_request_; | 117 scoped_ptr<OAuth2TokenService::Request> oauth2_access_token_request_; |
| 115 string16 profile_full_name_; | 118 string16 profile_full_name_; |
| 119 std::string profile_locale_; |
| 116 SkBitmap profile_picture_; | 120 SkBitmap profile_picture_; |
| 117 PictureStatus picture_status_; | 121 PictureStatus picture_status_; |
| 118 std::string picture_url_; | 122 std::string picture_url_; |
| 119 | 123 |
| 120 DISALLOW_COPY_AND_ASSIGN(ProfileDownloader); | 124 DISALLOW_COPY_AND_ASSIGN(ProfileDownloader); |
| 121 }; | 125 }; |
| 122 | 126 |
| 123 #endif // CHROME_BROWSER_PROFILES_PROFILE_DOWNLOADER_H_ | 127 #endif // CHROME_BROWSER_PROFILES_PROFILE_DOWNLOADER_H_ |
| OLD | NEW |