Home | History | Annotate | Download | only in profiles
      1 // Copyright (c) 2012 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_PROFILES_PROFILE_DOWNLOADER_DELEGATE_H_
      6 #define CHROME_BROWSER_PROFILES_PROFILE_DOWNLOADER_DELEGATE_H_
      7 
      8 #include <string>
      9 
     10 #include "base/basictypes.h"
     11 #include "base/strings/string16.h"
     12 
     13 class Profile;
     14 class ProfileDownloader;
     15 
     16 // Reports on success or failure of Profile download. It is OK to delete the
     17 // |ProfileImageDownloader| instance in any of these handlers.
     18 class ProfileDownloaderDelegate {
     19  public:
     20   // Error codes passed to OnProfileDownloadFailure.
     21   enum FailureReason {
     22     TOKEN_ERROR,         // Cannot fetch OAuth2 token.
     23     NETWORK_ERROR,       // Network failure while downloading profile.
     24     SERVICE_ERROR,       // Service returned an error or malformed reply.
     25     IMAGE_DECODE_FAILED  // Cannot decode fetched image.
     26   };
     27 
     28   virtual ~ProfileDownloaderDelegate() {}
     29 
     30   // Whether the delegate need profile picture to be downloaded.
     31   virtual bool NeedsProfilePicture() const = 0;
     32 
     33   // Returns the desired side length of the profile image. If 0, returns image
     34   // of the originally uploaded size.
     35   virtual int GetDesiredImageSideLength() const = 0;
     36 
     37   // Returns the cached URL. If the cache URL matches the new image URL
     38   // the image will not be downloaded. Return an empty string when there is no
     39   // cached URL.
     40   virtual std::string GetCachedPictureURL() const = 0;
     41 
     42   // Returns the browser profile associated with this download request.
     43   virtual Profile* GetBrowserProfile() = 0;
     44 
     45   // Called when the profile download has completed successfully. Delegate can
     46   // query the downloader for the picture and full name.
     47   virtual void OnProfileDownloadSuccess(ProfileDownloader* downloader) = 0;
     48 
     49   // Called when the profile download has failed.
     50   virtual void OnProfileDownloadFailure(
     51       ProfileDownloader* downloader,
     52       ProfileDownloaderDelegate::FailureReason reason) = 0;
     53 };
     54 
     55 #endif  // CHROME_BROWSER_PROFILES_PROFILE_DOWNLOADER_DELEGATE_H_
     56