#ifndef CHROME_BROWSER_MEDIA_GALLERIES_MEDIA_SCAN_MANAGER_H_
#define CHROME_BROWSER_MEDIA_GALLERIES_MEDIA_SCAN_MANAGER_H_
#include <map>
#include <set>
#include <string>
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/time/time.h"
#include "chrome/browser/media_galleries/media_folder_finder.h"
#include "chrome/browser/media_galleries/media_scan_types.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
class Profile;
class MediaScanManagerObserver;
namespace extensions {
class Extension;
}
class MediaScanManager : public content::NotificationObserver {
public:
MediaScanManager();
virtual ~MediaScanManager();
void AddObserver(Profile* profile, MediaScanManagerObserver* observer);
void RemoveObserver(Profile* profile);
void CancelScansForProfile(Profile* profile);
void StartScan(Profile* profile, const extensions::Extension* extension,
bool user_gesture);
void CancelScan(Profile* profile, const extensions::Extension* extension);
protected:
friend class MediaGalleriesPlatformAppBrowserTest;
typedef base::Callback<MediaFolderFinder*(
const MediaFolderFinder::MediaFolderFinderResultsCallback&)>
MediaFolderFinderFactory;
void SetMediaFolderFinderFactory(const MediaFolderFinderFactory& factory);
private:
struct ScanObservers {
ScanObservers();
~ScanObservers();
MediaScanManagerObserver* observer;
std::set<std::string > scanning_extensions;
};
typedef std::map<Profile*, ScanObservers> ScanObserverMap;
virtual void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
bool ScanInProgress() const;
void OnScanCompleted(
bool success,
const MediaFolderFinder::MediaFolderFinderResults& found_folders);
void OnFoundContainerDirectories(
const MediaFolderFinder::MediaFolderFinderResults& found_folders,
const MediaFolderFinder::MediaFolderFinderResults& container_folders);
scoped_ptr<MediaFolderFinder> folder_finder_;
base::Time scan_start_time_;
MediaFolderFinderFactory testing_folder_finder_factory_;
ScanObserverMap observers_;
content::NotificationRegistrar registrar_;
base::WeakPtrFactory<MediaScanManager> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(MediaScanManager);
};
#endif