Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(418)

Side by Side Diff: chrome/browser/gaia_userinfo/profile_downloader.h

Issue 8510069: Make ProfileImageDownloader available to non-chromeos code (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix build Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_GAIA_USERINFO_PROFILE_DOWNLOADER_H_
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_PROFILE_IMAGE_DOWNLOADER_H_ 6 #define CHROME_BROWSER_GAIA_USERINFO_PROFILE_DOWNLOADER_H_
7 #pragma once 7 #pragma once
8 8
9 #include <string>
whywhat 2011/11/15 12:19:21 I think this header belongs here.
sail 2011/11/15 20:17:22 Done.
10
11 #include "base/basictypes.h" 9 #include "base/basictypes.h"
12 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
13 #include "chrome/browser/chromeos/login/image_decoder.h" 11 #include "chrome/browser/gaia_userinfo/image_decoder.h"
14 #include "content/public/browser/notification_observer.h" 12 #include "content/public/browser/notification_observer.h"
15 #include "content/public/browser/notification_registrar.h" 13 #include "content/public/browser/notification_registrar.h"
16 #include "content/public/common/url_fetcher_delegate.h" 14 #include "content/public/common/url_fetcher_delegate.h"
17 #include "googleurl/src/gurl.h" 15 #include "googleurl/src/gurl.h"
18 16
19 namespace chromeos { 17 class ProfileDownloaderDelegate;
20 18
21 // Downloads user profile image, decodes it in a sandboxed process. 19 // Downloads user profile information. The profile picture is decoded in a
22 class ProfileImageDownloader : public content::URLFetcherDelegate, 20 // sandboxed process.
23 public ImageDecoder::Delegate, 21 class ProfileDownloader : public content::URLFetcherDelegate,
24 public content::NotificationObserver { 22 public ImageDecoder::Delegate,
23 public content::NotificationObserver {
25 public: 24 public:
26 // Enum for reporting histograms about profile picture download. 25 // Enum for reporting histograms about profile picture download.
27 enum DownloadResult { 26 enum DownloadResult {
28 kDownloadSuccessChanged, 27 kDownloadSuccessChanged,
29 kDownloadSuccess, 28 kDownloadSuccess,
30 kDownloadFailure, 29 kDownloadFailure,
31 kDownloadDefault, 30 kDownloadDefault,
32 31
33 // Must be the last, convenient count. 32 // Must be the last, convenient count.
34 kDownloadResultsCount 33 kDownloadResultsCount
35 }; 34 };
36 35
37 // Reports on success or failure of Profile image download. It is OK to 36 explicit ProfileDownloader(Delegate* delegate);
38 // delete the |ProfileImageDownloader| instance in any of these handlers. 37 virtual ~ProfileDownloader();
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 38
57 // Starts downloading the picture if the necessary authorization token is 39 // Starts downloading the picture if the necessary authorization token is
58 // ready. If not, subscribes to token service and starts fetching if the 40 // ready. If not, subscribes to token service and starts fetching if the
59 // token is available. Should not be called more than once. 41 // token is available. Should not be called more than once.
60 void Start(); 42 void Start();
61 43
62 private: 44 private:
63 // Overriden from content::URLFetcherDelegate: 45 // Overriden from content::URLFetcherDelegate:
64 virtual void OnURLFetchComplete(const content::URLFetcher* source) OVERRIDE; 46 virtual void OnURLFetchComplete(const content::URLFetcher* source) OVERRIDE;
65 47
66 // Overriden from ImageDecoder::Delegate: 48 // Overriden from ImageDecoder::Delegate:
67 virtual void OnImageDecoded(const ImageDecoder* decoder, 49 virtual void OnImageDecoded(const ImageDecoder* decoder,
68 const SkBitmap& decoded_image) OVERRIDE; 50 const SkBitmap& decoded_image) OVERRIDE;
69 virtual void OnDecodeImageFailed(const ImageDecoder* decoder) OVERRIDE; 51 virtual void OnDecodeImageFailed(const ImageDecoder* decoder) OVERRIDE;
70 52
71 // Overriden from content::NotificationObserver: 53 // Overriden from content::NotificationObserver:
72 virtual void Observe(int type, 54 virtual void Observe(int type,
73 const content::NotificationSource& source, 55 const content::NotificationSource& source,
74 const content::NotificationDetails& details) OVERRIDE; 56 const content::NotificationDetails& details) OVERRIDE;
75 57
76 // Searches for profile image URL in user entry response from Picasa. 58 // Parses the entry response from Picasa and gets the nick name and
77 // Returns an empty string on failure. 59 // and profile image URL. Return value is set to empty on failure.
78 std::string GetProfileImageURL(const std::string& data) const; 60 void GetProfileNickNameAndImageURL(const std::string& data,
Ivan Korotkov 2011/11/15 11:05:08 What about returning bool to indicate parsing erro
sail 2011/11/15 20:17:22 Done.
61 string16* nick_name,
62 std::string* url);
79 63
80 // Returns true if the image url is url of the default profile picture. 64 // Returns true if the image url is url of the default profile picture.
81 bool IsDefaultProfileImageURL(const std::string& url) const; 65 bool IsDefaultProfileImageURL(const std::string& url) const;
82 66
83 // Issues the first request to get user profile image. 67 // Issues the first request to get user profile image.
84 void StartFetchingImage(); 68 void StartFetchingImage();
85 69
86 Delegate* delegate_; 70 Delegate* delegate_;
87 std::string auth_token_; 71 std::string auth_token_;
88 scoped_ptr<content::URLFetcher> user_entry_fetcher_; 72 scoped_ptr<content::URLFetcher> user_entry_fetcher_;
89 scoped_ptr<content::URLFetcher> profile_image_fetcher_; 73 scoped_ptr<content::URLFetcher> profile_image_fetcher_;
90 content::NotificationRegistrar registrar_; 74 content::NotificationRegistrar registrar_;
75 string16 full_name_;
whywhat 2011/11/15 12:19:21 nit: you should include "base/string16.h" for this
sail 2011/11/15 20:17:22 Done.
91 76
92 DISALLOW_COPY_AND_ASSIGN(ProfileImageDownloader); 77 DISALLOW_COPY_AND_ASSIGN(ProfileDownloader);
93 }; 78 };
94 79
95 } // namespace chromeos 80 #endif // CHROME_BROWSER_GAIA_USERINFO_PROFILE_DOWNLOADER_H_
96
97 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_PROFILE_IMAGE_DOWNLOADER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698