OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_PROFILE_IMAGE_DOWNLOADER_H_ | |
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_PROFILE_IMAGE_DOWNLOADER_H_ | |
7 #pragma once | |
8 | |
9 #include <string> | |
10 | |
11 #include "base/basictypes.h" | |
12 #include "base/memory/scoped_ptr.h" | |
13 #include "chrome/browser/chromeos/login/image_decoder.h" | |
14 #include "content/public/browser/notification_observer.h" | |
15 #include "content/public/browser/notification_registrar.h" | |
16 #include "content/public/common/url_fetcher_delegate.h" | |
17 #include "googleurl/src/gurl.h" | |
18 | |
19 namespace chromeos { | |
20 | |
21 // Downloads user profile image, decodes it in a sandboxed process. | |
22 class ProfileImageDownloader : public content::URLFetcherDelegate, | |
23 public ImageDecoder::Delegate, | |
24 public content::NotificationObserver { | |
25 public: | |
26 // Enum for reporting histograms about profile picture download. | |
27 enum DownloadResult { | |
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 | |
57 // Starts downloading the picture if the necessary authorization token is | |
58 // ready. If not, subscribes to token service and starts fetching if the | |
59 // token is available. Should not be called more than once. | |
60 void Start(); | |
61 | |
62 private: | |
63 // Overriden from content::URLFetcherDelegate: | |
64 virtual void OnURLFetchComplete(const content::URLFetcher* source) OVERRIDE; | |
65 | |
66 // Overriden from ImageDecoder::Delegate: | |
67 virtual void OnImageDecoded(const ImageDecoder* decoder, | |
68 const SkBitmap& decoded_image) OVERRIDE; | |
69 virtual void OnDecodeImageFailed(const ImageDecoder* decoder) OVERRIDE; | |
70 | |
71 // Overriden from content::NotificationObserver: | |
72 virtual void Observe(int type, | |
73 const content::NotificationSource& source, | |
74 const content::NotificationDetails& details) OVERRIDE; | |
75 | |
76 // Searches for profile image URL in user entry response from Picasa. | |
77 // Returns an empty string on failure. | |
78 std::string GetProfileImageURL(const std::string& data) const; | |
79 | |
80 // Returns true if the image url is url of the default profile picture. | |
81 bool IsDefaultProfileImageURL(const std::string& url) const; | |
82 | |
83 // Issues the first request to get user profile image. | |
84 void StartFetchingImage(); | |
85 | |
86 Delegate* delegate_; | |
87 std::string auth_token_; | |
88 scoped_ptr<content::URLFetcher> user_entry_fetcher_; | |
89 scoped_ptr<content::URLFetcher> profile_image_fetcher_; | |
90 content::NotificationRegistrar registrar_; | |
91 | |
92 DISALLOW_COPY_AND_ASSIGN(ProfileImageDownloader); | |
93 }; | |
94 | |
95 } // namespace chromeos | |
96 | |
97 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_PROFILE_IMAGE_DOWNLOADER_H_ | |
OLD | NEW |