Logo Search packages:      
Sourcecode: chromium-browser version File versions  Download package


// Copyright (c) 2010 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.


#include <string>

#include "base/basictypes.h"
#include "base/ref_counted.h"

class MessageLoop;
class SkBitmap;

namespace chromeos {

// A facility to read a file containing user image asynchronously in the IO
// thread. Returns the image in the form of an SkBitmap.
class UserImageLoader : public base::RefCountedThreadSafe<UserImageLoader> {
  class Delegate {
    // Invoked when user image has been read.
    virtual void OnImageLoaded(const std::string& username,
                               const SkBitmap& image) = 0;

    virtual ~Delegate() {}

  explicit UserImageLoader(Delegate* delegate);

  // Start reading the image for |username| from |filepath| on the file thread.
  void Start(const std::string& username, const std::string& filepath);

  void set_delegate(Delegate* delegate) { delegate_ = delegate; }

  friend class base::RefCountedThreadSafe<UserImageLoader>;

  virtual ~UserImageLoader();

  // Method that reads the file and decodes the image on the file thread.
  void LoadImage(const std::string& username, const std::string& filepath);

  // Notifies the delegate that image was loaded, on delegate's thread.
  void NotifyDelegate(const std::string& username, const SkBitmap& image);

  // The message loop object of the thread in which we notify the delegate.
  MessageLoop* target_message_loop_;

  // Delegate to notify about finishing the load of the image.
  Delegate* delegate_;


}  // namespace chromeos


Generated by  Doxygen 1.6.0   Back to index