#ifndef CHROME_BROWSER_MEDIA_GALLERIES_MEDIA_GALLERIES_SCAN_RESULT_DIALOG_CONTROLLER_H_
#define CHROME_BROWSER_MEDIA_GALLERIES_MEDIA_GALLERIES_SCAN_RESULT_DIALOG_CONTROLLER_H_
#include <map>
#include <set>
#include <string>
#include "base/callback.h"
#include "base/memory/scoped_ptr.h"
#include "base/strings/string16.h"
#include "chrome/browser/media_galleries/media_galleries_preferences.h"
#include "components/storage_monitor/removable_storage_observer.h"
namespace content {
class WebContents;
}
namespace extensions {
class Extension;
}
namespace ui {
class MenuModel;
}
class MediaGalleriesScanResultDialogController;
class MediaGalleryContextMenu;
class Profile;
class MediaGalleriesScanResultDialog {
 public:
  virtual ~MediaGalleriesScanResultDialog();
  
  virtual void UpdateResults() = 0;
  
  static MediaGalleriesScanResultDialog* Create(
      MediaGalleriesScanResultDialogController* controller);
 private:
  friend class TestMediaGalleriesAddScanResultsFunction;
  virtual void AcceptDialogForTesting() = 0;
};
class MediaGalleriesScanResultDialogController
    : public storage_monitor::RemovableStorageObserver,
      public MediaGalleriesPreferences::GalleryChangeObserver {
 public:
  struct ScanResult {
    ScanResult(const MediaGalleryPrefInfo& pref_info, bool selected)
        : pref_info(pref_info),
          selected(selected) {
    }
    ScanResult() : selected(false) {}
    MediaGalleryPrefInfo pref_info;
    bool selected;
  };
  typedef std::vector<ScanResult> OrderedScanResults;
  
  static size_t ScanResultCountForExtension(
      MediaGalleriesPreferences* preferences,
      const extensions::Extension* extension);
  
  MediaGalleriesScanResultDialogController(
      content::WebContents* web_contents,
      const extensions::Extension& extension,
      const base::Closure& on_finish);
  
  base::string16 GetHeader() const;
  
  base::string16 GetSubtext() const;
  
  virtual OrderedScanResults GetGalleryList() const;
  
  virtual void DidToggleGalleryId(MediaGalleryPrefId pref_id, bool selected);
  
  virtual void DidClickOpenFolderViewer(MediaGalleryPrefId pref_id) const;
  
  virtual void DidForgetGallery(MediaGalleryPrefId pref_id);
  
  virtual void DialogFinished(bool accepted);
  virtual content::WebContents* web_contents();
  ui::MenuModel* GetContextMenu(MediaGalleryPrefId id);
 protected:
  typedef base::Callback<MediaGalleriesScanResultDialog* (
      MediaGalleriesScanResultDialogController*)> CreateDialogCallback;
  typedef std::map<MediaGalleryPrefId, ScanResult> ScanResults;
  
  
  static void UpdateScanResultsFromPreferences(
      MediaGalleriesPreferences* preferences,
      const extensions::Extension* extension,
      MediaGalleryPrefIdSet ignore_list,
      ScanResults* scan_results);
  
  MediaGalleriesScanResultDialogController(
      const extensions::Extension& extension,
      MediaGalleriesPreferences* preferences_,
      const CreateDialogCallback& create_dialog_callback,
      const base::Closure& on_finish);
  virtual ~MediaGalleriesScanResultDialogController();
 private:
  friend class MediaGalleriesScanResultDialogControllerTest;
  friend class MediaGalleriesScanResultDialogCocoaTest;
  friend class TestMediaGalleriesAddScanResultsFunction;
  
  void OnPreferencesInitialized();
  
  void OnPreferenceUpdate(const std::string& extension_id);
  
  void OnRemovableDeviceUpdate(const std::string device_id);
  Profile* GetProfile() const;
  
  
  virtual void OnRemovableStorageAttached(
      const storage_monitor::StorageInfo& info) OVERRIDE;
  virtual void OnRemovableStorageDetached(
      const storage_monitor::StorageInfo& info) OVERRIDE;
  
  
  virtual void OnPermissionAdded(MediaGalleriesPreferences* pref,
                                 const std::string& extension_id,
                                 MediaGalleryPrefId pref_id) OVERRIDE;
  virtual void OnPermissionRemoved(MediaGalleriesPreferences* pref,
                                   const std::string& extension_id,
                                   MediaGalleryPrefId pref_id) OVERRIDE;
  virtual void OnGalleryAdded(MediaGalleriesPreferences* pref,
                              MediaGalleryPrefId pref_id) OVERRIDE;
  virtual void OnGalleryRemoved(MediaGalleriesPreferences* pref,
                                MediaGalleryPrefId pref_id) OVERRIDE;
  virtual void OnGalleryInfoUpdated(MediaGalleriesPreferences* pref,
                                    MediaGalleryPrefId pref_id) OVERRIDE;
  
  content::WebContents* web_contents_;
  
  
  const extensions::Extension* extension_;
  
  
  ScanResults scan_results_;
  
  
  MediaGalleryPrefIdSet results_to_remove_;
  
  base::Closure on_finish_;
  
  
  MediaGalleriesPreferences* preferences_;
  
  CreateDialogCallback create_dialog_callback_;
  
  scoped_ptr<MediaGalleriesScanResultDialog> dialog_;
  scoped_ptr<MediaGalleryContextMenu> context_menu_;
  DISALLOW_COPY_AND_ASSIGN(MediaGalleriesScanResultDialogController);
};
#endif