diff options
author | sail@chromium.org <sail@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-22 03:56:09 +0000 |
---|---|---|
committer | sail@chromium.org <sail@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-22 03:56:09 +0000 |
commit | 6d33da172efea858a707202dc89eb3b04c7d0638 (patch) | |
tree | 0e0c6b7f9ba8e7a2a4c22f570eb961dca89126ed /chrome/browser/profiles/profile_downloader.h | |
parent | 0de5d8609abf9961228c2a12031fc5354688345a (diff) | |
download | chromium_src-6d33da172efea858a707202dc89eb3b04c7d0638.zip chromium_src-6d33da172efea858a707202dc89eb3b04c7d0638.tar.gz chromium_src-6d33da172efea858a707202dc89eb3b04c7d0638.tar.bz2 |
Make ProfileImageDownloader available to non-chromeos code
BUG=91241
TEST=
Review URL: http://codereview.chromium.org/8510069
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@111098 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/profiles/profile_downloader.h')
-rw-r--r-- | chrome/browser/profiles/profile_downloader.h | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/chrome/browser/profiles/profile_downloader.h b/chrome/browser/profiles/profile_downloader.h new file mode 100644 index 0000000..2b9733e --- /dev/null +++ b/chrome/browser/profiles/profile_downloader.h @@ -0,0 +1,83 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_PROFILES_PROFILE_DOWNLOADER_H_ +#define CHROME_BROWSER_PROFILES_PROFILE_DOWNLOADER_H_ +#pragma once + +#include <string> + +#include "base/basictypes.h" +#include "base/memory/scoped_ptr.h" +#include "base/string16.h" +#include "chrome/browser/image_decoder.h" +#include "content/public/browser/notification_observer.h" +#include "content/public/browser/notification_registrar.h" +#include "content/public/common/url_fetcher_delegate.h" +#include "googleurl/src/gurl.h" +#include "third_party/skia/include/core/SkBitmap.h" + +class ProfileDownloaderDelegate; + +// Downloads user profile information. The profile picture is decoded in a +// sandboxed process. +class ProfileDownloader : public content::URLFetcherDelegate, + public ImageDecoder::Delegate, + public content::NotificationObserver { + public: + explicit ProfileDownloader(ProfileDownloaderDelegate* delegate); + virtual ~ProfileDownloader(); + + // Starts downloading profile information if the necessary authorization token + // is ready. If not, subscribes to token service and starts fetching if the + // token is available. Should not be called more than once. + void Start(); + + // On successful download this returns the full name of the user. For example + // "Pat Smith". + const string16& GetProfileFullName() const; + + // On successful download this returns the profile picture of the user. + // For users with no profile picture set (that is, they have the default + // profile picture) this will return an Null bitmap. + const SkBitmap& GetProfilePicture() const; + + private: + // Overriden from content::URLFetcherDelegate: + virtual void OnURLFetchComplete(const content::URLFetcher* source) OVERRIDE; + + // Overriden from ImageDecoder::Delegate: + virtual void OnImageDecoded(const ImageDecoder* decoder, + const SkBitmap& decoded_image) OVERRIDE; + virtual void OnDecodeImageFailed(const ImageDecoder* decoder) OVERRIDE; + + // Overriden from content::NotificationObserver: + virtual void Observe(int type, + const content::NotificationSource& source, + const content::NotificationDetails& details) OVERRIDE; + + // Parses the entry response from Picasa and gets the nick name and + // and profile image URL. Returns false to indicate a parsing error. + bool GetProfileNickNameAndImageURL(const std::string& data, + string16* nick_name, + std::string* url) const; + + // Returns true if the image url is url of the default profile picture. + bool IsDefaultProfileImageURL(const std::string& url) const; + + // Issues the first request to get user profile image. + void StartFetchingImage(); + + ProfileDownloaderDelegate* delegate_; + std::string auth_token_; + scoped_ptr<content::URLFetcher> user_entry_fetcher_; + scoped_ptr<content::URLFetcher> profile_image_fetcher_; + content::NotificationRegistrar registrar_; + string16 profile_full_name_; + SkBitmap profile_picture_; + + DISALLOW_COPY_AND_ASSIGN(ProfileDownloader); +}; + +#endif // CHROME_BROWSER_PROFILES_PROFILE_DOWNLOADER_H_ |