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_CHROMEOS_LOGIN_PROFILE_IMAGE_DOWNLOADER_H_ | 5 #ifndef CHROME_BROWSER_PROFILES_PROFILE_DOWNLOADER_H_ |
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_PROFILE_IMAGE_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 "chrome/browser/chromeos/login/image_decoder.h" | 13 #include "base/string16.h" |
14 #include "chrome/browser/image_decoder.h" | |
14 #include "content/public/browser/notification_observer.h" | 15 #include "content/public/browser/notification_observer.h" |
15 #include "content/public/browser/notification_registrar.h" | 16 #include "content/public/browser/notification_registrar.h" |
16 #include "content/public/common/url_fetcher_delegate.h" | 17 #include "content/public/common/url_fetcher_delegate.h" |
17 #include "googleurl/src/gurl.h" | 18 #include "googleurl/src/gurl.h" |
19 #include "third_party/skia/include/core/SkBitmap.h" | |
18 | 20 |
19 namespace chromeos { | 21 class ProfileDownloaderDelegate; |
20 | 22 |
21 // Downloads user profile image, decodes it in a sandboxed process. | 23 // Downloads user profile information. The profile picture is decoded in a |
22 class ProfileImageDownloader : public content::URLFetcherDelegate, | 24 // sandboxed process. |
23 public ImageDecoder::Delegate, | 25 class ProfileDownloader : public content::URLFetcherDelegate, |
24 public content::NotificationObserver { | 26 public ImageDecoder::Delegate, |
27 public content::NotificationObserver { | |
25 public: | 28 public: |
26 // Enum for reporting histograms about profile picture download. | 29 explicit ProfileDownloader(ProfileDownloaderDelegate* delegate); |
27 enum DownloadResult { | 30 virtual ~ProfileDownloader(); |
28 kDownloadSuccessChanged, | |
29 kDownloadSuccess, | |
30 kDownloadFailure, | |
31 kDownloadDefault, | |
32 | |
33 // Must be the last, convenient count. | |
34 kDownloadResultsCount | |
35 }; | |
36 | |
37 // Reports on success or failure of Profile image download. It is OK to | |
38 // delete the |ProfileImageDownloader| instance in any of these handlers. | |
39 class Delegate { | |
40 public: | |
41 virtual ~Delegate() {} | |
42 | |
43 // Called when image is successfully downloaded and decoded. | |
44 virtual void OnDownloadSuccess(const SkBitmap& image) = 0; | |
45 | |
46 // Called on download failure. | |
47 virtual void OnDownloadFailure() {} | |
48 | |
49 // Called when user has the default profile image and we won't download | |
50 // it. | |
51 virtual void OnDownloadDefaultImage() {} | |
52 }; | |
53 | |
54 explicit ProfileImageDownloader(Delegate* delegate); | |
55 virtual ~ProfileImageDownloader(); | |
56 | 31 |
57 // Starts downloading the picture if the necessary authorization token is | 32 // Starts downloading the picture if the necessary authorization token is |
Ivan Korotkov
2011/11/17 08:37:12
Starts downloading profile information... ?
sail
2011/11/21 22:01:00
Done.
| |
58 // ready. If not, subscribes to token service and starts fetching if the | 33 // ready. If not, subscribes to token service and starts fetching if the |
59 // token is available. Should not be called more than once. | 34 // token is available. Should not be called more than once. |
60 void Start(); | 35 void Start(); |
61 | 36 |
37 // On successful download this returns the full name of the user. For example | |
38 // "Pat Smith". | |
39 const string16& GetProfileFullName() const; | |
Ivan Korotkov
2011/11/17 08:37:12
These are simple getters. Unless you're planning t
sail
2011/11/21 22:01:00
Yea, this will have to be virtual eventually. I sh
| |
40 | |
41 // On successful download this returns the profile picture of the user. | |
42 // For users with no profile picture set (that is, they have the default | |
43 // profile picture) this will return an Null bitmap. | |
44 const SkBitmap& GetProfilePicture() const; | |
45 | |
62 private: | 46 private: |
63 // Overriden from content::URLFetcherDelegate: | 47 // Overriden from content::URLFetcherDelegate: |
64 virtual void OnURLFetchComplete(const content::URLFetcher* source) OVERRIDE; | 48 virtual void OnURLFetchComplete(const content::URLFetcher* source) OVERRIDE; |
65 | 49 |
66 // Overriden from ImageDecoder::Delegate: | 50 // Overriden from ImageDecoder::Delegate: |
67 virtual void OnImageDecoded(const ImageDecoder* decoder, | 51 virtual void OnImageDecoded(const ImageDecoder* decoder, |
68 const SkBitmap& decoded_image) OVERRIDE; | 52 const SkBitmap& decoded_image) OVERRIDE; |
69 virtual void OnDecodeImageFailed(const ImageDecoder* decoder) OVERRIDE; | 53 virtual void OnDecodeImageFailed(const ImageDecoder* decoder) OVERRIDE; |
70 | 54 |
71 // Overriden from content::NotificationObserver: | 55 // Overriden from content::NotificationObserver: |
72 virtual void Observe(int type, | 56 virtual void Observe(int type, |
73 const content::NotificationSource& source, | 57 const content::NotificationSource& source, |
74 const content::NotificationDetails& details) OVERRIDE; | 58 const content::NotificationDetails& details) OVERRIDE; |
75 | 59 |
76 // Searches for profile image URL in user entry response from Picasa. | 60 // Parses the entry response from Picasa and gets the nick name and |
77 // Returns an empty string on failure. | 61 // and profile image URL. Returns false to indicate a parsing error. |
78 std::string GetProfileImageURL(const std::string& data) const; | 62 bool GetProfileNickNameAndImageURL(const std::string& data, |
63 string16* nick_name, | |
64 std::string* url) const; | |
79 | 65 |
80 // Returns true if the image url is url of the default profile picture. | 66 // Returns true if the image url is url of the default profile picture. |
81 bool IsDefaultProfileImageURL(const std::string& url) const; | 67 bool IsDefaultProfileImageURL(const std::string& url) const; |
82 | 68 |
83 // Issues the first request to get user profile image. | 69 // Issues the first request to get user profile image. |
84 void StartFetchingImage(); | 70 void StartFetchingImage(); |
85 | 71 |
86 Delegate* delegate_; | 72 ProfileDownloaderDelegate* delegate_; |
87 std::string auth_token_; | 73 std::string auth_token_; |
88 scoped_ptr<content::URLFetcher> user_entry_fetcher_; | 74 scoped_ptr<content::URLFetcher> user_entry_fetcher_; |
89 scoped_ptr<content::URLFetcher> profile_image_fetcher_; | 75 scoped_ptr<content::URLFetcher> profile_image_fetcher_; |
90 content::NotificationRegistrar registrar_; | 76 content::NotificationRegistrar registrar_; |
77 string16 profile_full_name_; | |
78 SkBitmap profile_picture_; | |
91 | 79 |
92 DISALLOW_COPY_AND_ASSIGN(ProfileImageDownloader); | 80 DISALLOW_COPY_AND_ASSIGN(ProfileDownloader); |
93 }; | 81 }; |
94 | 82 |
95 } // namespace chromeos | 83 #endif // CHROME_BROWSER_PROFILES_PROFILE_DOWNLOADER_H_ |
96 | |
97 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_PROFILE_IMAGE_DOWNLOADER_H_ | |
OLD | NEW |