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/gtest_prod_util.h" |
12 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
13 #include "base/string16.h" | 14 #include "base/string16.h" |
14 #include "chrome/browser/image_decoder.h" | 15 #include "chrome/browser/image_decoder.h" |
15 #include "content/public/browser/notification_observer.h" | 16 #include "content/public/browser/notification_observer.h" |
16 #include "content/public/browser/notification_registrar.h" | 17 #include "content/public/browser/notification_registrar.h" |
17 #include "content/public/common/url_fetcher_delegate.h" | 18 #include "content/public/common/url_fetcher_delegate.h" |
18 #include "googleurl/src/gurl.h" | 19 #include "googleurl/src/gurl.h" |
19 #include "third_party/skia/include/core/SkBitmap.h" | 20 #include "third_party/skia/include/core/SkBitmap.h" |
20 #include "chrome/common/net/gaia/oauth2_access_token_consumer.h" | 21 #include "chrome/common/net/gaia/oauth2_access_token_consumer.h" |
21 | 22 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 | 56 |
56 // Gets the profile picture status. | 57 // Gets the profile picture status. |
57 virtual PictureStatus GetProfilePictureStatus() const; | 58 virtual PictureStatus GetProfilePictureStatus() const; |
58 | 59 |
59 // Gets the URL for the profile picture. This can be cached so that the same | 60 // 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 // picture is not downloaded multiple times. This value should only be used |
61 // when the picture status is PICTURE_SUCCESS. | 62 // when the picture status is PICTURE_SUCCESS. |
62 virtual std::string GetProfilePictureURL() const; | 63 virtual std::string GetProfilePictureURL() const; |
63 | 64 |
64 private: | 65 private: |
| 66 friend class ProfileDownloaderTest; |
| 67 FRIEND_TEST_ALL_PREFIXES(ProfileDownloaderTest, ParseData); |
| 68 FRIEND_TEST_ALL_PREFIXES(ProfileDownloaderTest, DefaultURL); |
| 69 |
65 // Overriden from content::URLFetcherDelegate: | 70 // Overriden from content::URLFetcherDelegate: |
66 virtual void OnURLFetchComplete(const content::URLFetcher* source) OVERRIDE; | 71 virtual void OnURLFetchComplete(const content::URLFetcher* source) OVERRIDE; |
67 | 72 |
68 // Overriden from ImageDecoder::Delegate: | 73 // Overriden from ImageDecoder::Delegate: |
69 virtual void OnImageDecoded(const ImageDecoder* decoder, | 74 virtual void OnImageDecoded(const ImageDecoder* decoder, |
70 const SkBitmap& decoded_image) OVERRIDE; | 75 const SkBitmap& decoded_image) OVERRIDE; |
71 virtual void OnDecodeImageFailed(const ImageDecoder* decoder) OVERRIDE; | 76 virtual void OnDecodeImageFailed(const ImageDecoder* decoder) OVERRIDE; |
72 | 77 |
73 // Overriden from content::NotificationObserver: | 78 // Overriden from content::NotificationObserver: |
74 virtual void Observe(int type, | 79 virtual void Observe(int type, |
75 const content::NotificationSource& source, | 80 const content::NotificationSource& source, |
76 const content::NotificationDetails& details) OVERRIDE; | 81 const content::NotificationDetails& details) OVERRIDE; |
77 | 82 |
78 // Overriden from OAuth2AccessTokenConsumer: | 83 // Overriden from OAuth2AccessTokenConsumer: |
79 virtual void OnGetTokenSuccess(const std::string& access_token) OVERRIDE; | 84 virtual void OnGetTokenSuccess(const std::string& access_token) OVERRIDE; |
80 virtual void OnGetTokenFailure(const GoogleServiceAuthError& error) OVERRIDE; | 85 virtual void OnGetTokenFailure(const GoogleServiceAuthError& error) OVERRIDE; |
81 | 86 |
82 // Parses the entry response from Picasa and gets the nick name and | 87 // Parses the entry response and gets the name and and profile image URL. |
83 // and profile image URL. Returns false to indicate a parsing error. | 88 // |data| should be the JSON formatted data return by the response. |
84 bool GetProfileNickNameAndImageURL(const std::string& data, | 89 // Returns false to indicate a parsing error. |
85 string16* nick_name, | 90 static bool GetProfileNameAndImageURL(const std::string& data, |
86 std::string* url) const; | 91 string16* nick_name, |
| 92 std::string* url, |
| 93 int image_size); |
87 | 94 |
88 // Returns true if the image url is url of the default profile picture. | 95 // Returns true if the image url is url of the default profile picture. |
89 bool IsDefaultProfileImageURL(const std::string& url) const; | 96 static bool IsDefaultProfileImageURL(const std::string& url); |
90 | 97 |
91 // Issues the first request to get user profile image. | 98 // Issues the first request to get user profile image. |
92 void StartFetchingImage(); | 99 void StartFetchingImage(); |
93 | 100 |
94 // Gets the authorization header. | 101 // Gets the authorization header. |
95 const char* GetAuthorizationHeader() const; | 102 const char* GetAuthorizationHeader() const; |
96 | 103 |
97 // Starts fetching OAuth2 access token. This is needed before the GAIA info | 104 // Starts fetching OAuth2 access token. This is needed before the GAIA info |
98 // can be downloaded. | 105 // can be downloaded. |
99 void StartFetchingOAuth2AccessToken(); | 106 void StartFetchingOAuth2AccessToken(); |
100 | 107 |
101 ProfileDownloaderDelegate* delegate_; | 108 ProfileDownloaderDelegate* delegate_; |
102 std::string auth_token_; | 109 std::string auth_token_; |
103 scoped_ptr<content::URLFetcher> user_entry_fetcher_; | 110 scoped_ptr<content::URLFetcher> user_entry_fetcher_; |
104 scoped_ptr<content::URLFetcher> profile_image_fetcher_; | 111 scoped_ptr<content::URLFetcher> profile_image_fetcher_; |
105 scoped_ptr<OAuth2AccessTokenFetcher> oauth2_access_token_fetcher_; | 112 scoped_ptr<OAuth2AccessTokenFetcher> oauth2_access_token_fetcher_; |
106 content::NotificationRegistrar registrar_; | 113 content::NotificationRegistrar registrar_; |
107 string16 profile_full_name_; | 114 string16 profile_full_name_; |
108 SkBitmap profile_picture_; | 115 SkBitmap profile_picture_; |
109 PictureStatus picture_status_; | 116 PictureStatus picture_status_; |
110 std::string picture_url_; | 117 std::string picture_url_; |
111 | 118 |
112 DISALLOW_COPY_AND_ASSIGN(ProfileDownloader); | 119 DISALLOW_COPY_AND_ASSIGN(ProfileDownloader); |
113 }; | 120 }; |
114 | 121 |
115 #endif // CHROME_BROWSER_PROFILES_PROFILE_DOWNLOADER_H_ | 122 #endif // CHROME_BROWSER_PROFILES_PROFILE_DOWNLOADER_H_ |
OLD | NEW |