| 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 #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/gtest_prod_util.h" | 12 #include "base/gtest_prod_util.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/string16.h" | 14 #include "base/string16.h" |
| 15 #include "chrome/browser/image_decoder.h" | 15 #include "chrome/browser/image_decoder.h" |
| 16 #include "chrome/common/net/gaia/oauth2_access_token_consumer.h" | 16 #include "chrome/common/net/gaia/oauth2_access_token_consumer.h" |
| 17 #include "content/public/browser/notification_observer.h" | 17 #include "content/public/browser/notification_observer.h" |
| 18 #include "content/public/browser/notification_registrar.h" | 18 #include "content/public/browser/notification_registrar.h" |
| 19 #include "content/public/common/url_fetcher_delegate.h" | |
| 20 #include "googleurl/src/gurl.h" | 19 #include "googleurl/src/gurl.h" |
| 20 #include "net/url_request/url_fetcher_delegate.h" |
| 21 #include "third_party/skia/include/core/SkBitmap.h" | 21 #include "third_party/skia/include/core/SkBitmap.h" |
| 22 | 22 |
| 23 class ProfileDownloaderDelegate; | 23 class ProfileDownloaderDelegate; |
| 24 class OAuth2AccessTokenFetcher; | 24 class OAuth2AccessTokenFetcher; |
| 25 | 25 |
| 26 namespace net { |
| 27 class URLFetcher; |
| 28 } // namespace net |
| 29 |
| 26 // Downloads user profile information. The profile picture is decoded in a | 30 // Downloads user profile information. The profile picture is decoded in a |
| 27 // sandboxed process. | 31 // sandboxed process. |
| 28 class ProfileDownloader : public content::URLFetcherDelegate, | 32 class ProfileDownloader : public net::URLFetcherDelegate, |
| 29 public ImageDecoder::Delegate, | 33 public ImageDecoder::Delegate, |
| 30 public content::NotificationObserver, | 34 public content::NotificationObserver, |
| 31 public OAuth2AccessTokenConsumer { | 35 public OAuth2AccessTokenConsumer { |
| 32 public: | 36 public: |
| 33 enum PictureStatus { | 37 enum PictureStatus { |
| 34 PICTURE_SUCCESS, | 38 PICTURE_SUCCESS, |
| 35 PICTURE_FAILED, | 39 PICTURE_FAILED, |
| 36 PICTURE_DEFAULT, | 40 PICTURE_DEFAULT, |
| 37 PICTURE_CACHED, | 41 PICTURE_CACHED, |
| 38 }; | 42 }; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 60 // 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 |
| 61 // 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 |
| 62 // when the picture status is PICTURE_SUCCESS. | 66 // when the picture status is PICTURE_SUCCESS. |
| 63 virtual std::string GetProfilePictureURL() const; | 67 virtual std::string GetProfilePictureURL() const; |
| 64 | 68 |
| 65 private: | 69 private: |
| 66 friend class ProfileDownloaderTest; | 70 friend class ProfileDownloaderTest; |
| 67 FRIEND_TEST_ALL_PREFIXES(ProfileDownloaderTest, ParseData); | 71 FRIEND_TEST_ALL_PREFIXES(ProfileDownloaderTest, ParseData); |
| 68 FRIEND_TEST_ALL_PREFIXES(ProfileDownloaderTest, DefaultURL); | 72 FRIEND_TEST_ALL_PREFIXES(ProfileDownloaderTest, DefaultURL); |
| 69 | 73 |
| 70 // Overriden from content::URLFetcherDelegate: | 74 // Overriden from net::URLFetcherDelegate: |
| 71 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | 75 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
| 72 | 76 |
| 73 // Overriden from ImageDecoder::Delegate: | 77 // Overriden from ImageDecoder::Delegate: |
| 74 virtual void OnImageDecoded(const ImageDecoder* decoder, | 78 virtual void OnImageDecoded(const ImageDecoder* decoder, |
| 75 const SkBitmap& decoded_image) OVERRIDE; | 79 const SkBitmap& decoded_image) OVERRIDE; |
| 76 virtual void OnDecodeImageFailed(const ImageDecoder* decoder) OVERRIDE; | 80 virtual void OnDecodeImageFailed(const ImageDecoder* decoder) OVERRIDE; |
| 77 | 81 |
| 78 // Overriden from content::NotificationObserver: | 82 // Overriden from content::NotificationObserver: |
| 79 virtual void Observe(int type, | 83 virtual void Observe(int type, |
| 80 const content::NotificationSource& source, | 84 const content::NotificationSource& source, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 100 | 104 |
| 101 // Gets the authorization header. | 105 // Gets the authorization header. |
| 102 const char* GetAuthorizationHeader() const; | 106 const char* GetAuthorizationHeader() const; |
| 103 | 107 |
| 104 // Starts fetching OAuth2 access token. This is needed before the GAIA info | 108 // Starts fetching OAuth2 access token. This is needed before the GAIA info |
| 105 // can be downloaded. | 109 // can be downloaded. |
| 106 void StartFetchingOAuth2AccessToken(); | 110 void StartFetchingOAuth2AccessToken(); |
| 107 | 111 |
| 108 ProfileDownloaderDelegate* delegate_; | 112 ProfileDownloaderDelegate* delegate_; |
| 109 std::string auth_token_; | 113 std::string auth_token_; |
| 110 scoped_ptr<content::URLFetcher> user_entry_fetcher_; | 114 scoped_ptr<net::URLFetcher> user_entry_fetcher_; |
| 111 scoped_ptr<content::URLFetcher> profile_image_fetcher_; | 115 scoped_ptr<net::URLFetcher> profile_image_fetcher_; |
| 112 scoped_ptr<OAuth2AccessTokenFetcher> oauth2_access_token_fetcher_; | 116 scoped_ptr<OAuth2AccessTokenFetcher> oauth2_access_token_fetcher_; |
| 113 content::NotificationRegistrar registrar_; | 117 content::NotificationRegistrar registrar_; |
| 114 string16 profile_full_name_; | 118 string16 profile_full_name_; |
| 115 SkBitmap profile_picture_; | 119 SkBitmap profile_picture_; |
| 116 PictureStatus picture_status_; | 120 PictureStatus picture_status_; |
| 117 std::string picture_url_; | 121 std::string picture_url_; |
| 118 | 122 |
| 119 DISALLOW_COPY_AND_ASSIGN(ProfileDownloader); | 123 DISALLOW_COPY_AND_ASSIGN(ProfileDownloader); |
| 120 }; | 124 }; |
| 121 | 125 |
| 122 #endif // CHROME_BROWSER_PROFILES_PROFILE_DOWNLOADER_H_ | 126 #endif // CHROME_BROWSER_PROFILES_PROFILE_DOWNLOADER_H_ |
| OLD | NEW |