| 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 |
| 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 "base/string16.h" | 13 #include "base/string16.h" |
| 14 #include "chrome/browser/image_decoder.h" | 14 #include "chrome/browser/image_decoder.h" |
| 15 #include "content/public/browser/notification_observer.h" | 15 #include "content/public/browser/notification_observer.h" |
| 16 #include "content/public/browser/notification_registrar.h" | 16 #include "content/public/browser/notification_registrar.h" |
| 17 #include "content/public/common/url_fetcher_delegate.h" | 17 #include "content/public/common/url_fetcher_delegate.h" |
| 18 #include "googleurl/src/gurl.h" | 18 #include "googleurl/src/gurl.h" |
| 19 #include "third_party/skia/include/core/SkBitmap.h" | 19 #include "third_party/skia/include/core/SkBitmap.h" |
| 20 #include "chrome/common/net/gaia/oauth2_access_token_consumer.h" |
| 20 | 21 |
| 21 class ProfileDownloaderDelegate; | 22 class ProfileDownloaderDelegate; |
| 23 class OAuth2AccessTokenFetcher; |
| 22 | 24 |
| 23 // Downloads user profile information. The profile picture is decoded in a | 25 // Downloads user profile information. The profile picture is decoded in a |
| 24 // sandboxed process. | 26 // sandboxed process. |
| 25 class ProfileDownloader : public content::URLFetcherDelegate, | 27 class ProfileDownloader : public content::URLFetcherDelegate, |
| 26 public ImageDecoder::Delegate, | 28 public ImageDecoder::Delegate, |
| 27 public content::NotificationObserver { | 29 public content::NotificationObserver, |
| 30 public OAuth2AccessTokenConsumer { |
| 28 public: | 31 public: |
| 29 explicit ProfileDownloader(ProfileDownloaderDelegate* delegate); | 32 explicit ProfileDownloader(ProfileDownloaderDelegate* delegate); |
| 30 virtual ~ProfileDownloader(); | 33 virtual ~ProfileDownloader(); |
| 31 | 34 |
| 32 // Starts downloading profile information if the necessary authorization token | 35 // Starts downloading profile information if the necessary authorization token |
| 33 // is ready. If not, subscribes to token service and starts fetching if the | 36 // is ready. If not, subscribes to token service and starts fetching if the |
| 34 // token is available. Should not be called more than once. | 37 // token is available. Should not be called more than once. |
| 35 virtual void Start(); | 38 virtual void Start(); |
| 36 | 39 |
| 37 // On successful download this returns the full name of the user. For example | 40 // On successful download this returns the full name of the user. For example |
| (...skipping 12 matching lines...) Expand all Loading... |
| 50 // Overriden from ImageDecoder::Delegate: | 53 // Overriden from ImageDecoder::Delegate: |
| 51 virtual void OnImageDecoded(const ImageDecoder* decoder, | 54 virtual void OnImageDecoded(const ImageDecoder* decoder, |
| 52 const SkBitmap& decoded_image) OVERRIDE; | 55 const SkBitmap& decoded_image) OVERRIDE; |
| 53 virtual void OnDecodeImageFailed(const ImageDecoder* decoder) OVERRIDE; | 56 virtual void OnDecodeImageFailed(const ImageDecoder* decoder) OVERRIDE; |
| 54 | 57 |
| 55 // Overriden from content::NotificationObserver: | 58 // Overriden from content::NotificationObserver: |
| 56 virtual void Observe(int type, | 59 virtual void Observe(int type, |
| 57 const content::NotificationSource& source, | 60 const content::NotificationSource& source, |
| 58 const content::NotificationDetails& details) OVERRIDE; | 61 const content::NotificationDetails& details) OVERRIDE; |
| 59 | 62 |
| 63 // Overriden from OAuth2AccessTokenConsumer: |
| 64 virtual void OnGetTokenSuccess(const std::string& access_token) OVERRIDE; |
| 65 virtual void OnGetTokenFailure(const GoogleServiceAuthError& error) OVERRIDE; |
| 66 |
| 60 // Parses the entry response from Picasa and gets the nick name and | 67 // Parses the entry response from Picasa and gets the nick name and |
| 61 // and profile image URL. Returns false to indicate a parsing error. | 68 // and profile image URL. Returns false to indicate a parsing error. |
| 62 bool GetProfileNickNameAndImageURL(const std::string& data, | 69 bool GetProfileNickNameAndImageURL(const std::string& data, |
| 63 string16* nick_name, | 70 string16* nick_name, |
| 64 std::string* url) const; | 71 std::string* url) const; |
| 65 | 72 |
| 66 // Returns true if the image url is url of the default profile picture. | 73 // Returns true if the image url is url of the default profile picture. |
| 67 bool IsDefaultProfileImageURL(const std::string& url) const; | 74 bool IsDefaultProfileImageURL(const std::string& url) const; |
| 68 | 75 |
| 69 // Issues the first request to get user profile image. | 76 // Issues the first request to get user profile image. |
| 70 void StartFetchingImage(); | 77 void StartFetchingImage(); |
| 71 | 78 |
| 79 // Gets the authorization header. |
| 80 const char* GetAuthorizationHeader() const; |
| 81 |
| 82 // Starts fetching OAuth2 access token. This is needed before the GAIA info |
| 83 // can be downloaded. |
| 84 void StartFetchingOAuth2AccessToken(); |
| 85 |
| 72 ProfileDownloaderDelegate* delegate_; | 86 ProfileDownloaderDelegate* delegate_; |
| 73 std::string auth_token_; | 87 std::string auth_token_; |
| 74 scoped_ptr<content::URLFetcher> user_entry_fetcher_; | 88 scoped_ptr<content::URLFetcher> user_entry_fetcher_; |
| 75 scoped_ptr<content::URLFetcher> profile_image_fetcher_; | 89 scoped_ptr<content::URLFetcher> profile_image_fetcher_; |
| 90 scoped_ptr<OAuth2AccessTokenFetcher> oauth2_access_token_fetcher_; |
| 76 content::NotificationRegistrar registrar_; | 91 content::NotificationRegistrar registrar_; |
| 77 string16 profile_full_name_; | 92 string16 profile_full_name_; |
| 78 SkBitmap profile_picture_; | 93 SkBitmap profile_picture_; |
| 79 | 94 |
| 80 DISALLOW_COPY_AND_ASSIGN(ProfileDownloader); | 95 DISALLOW_COPY_AND_ASSIGN(ProfileDownloader); |
| 81 }; | 96 }; |
| 82 | 97 |
| 83 #endif // CHROME_BROWSER_PROFILES_PROFILE_DOWNLOADER_H_ | 98 #endif // CHROME_BROWSER_PROFILES_PROFILE_DOWNLOADER_H_ |
| OLD | NEW |