#ifndef CHROME_BROWSER_EXTENSIONS_BLACKLIST_H_
#define CHROME_BROWSER_EXTENSIONS_BLACKLIST_H_
#include <list>
#include <map>
#include <set>
#include <string>
#include <vector>
#include "base/callback.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/observer_list.h"
#include "chrome/browser/safe_browsing/database_manager.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "extensions/browser/blacklist_state.h"
namespace extensions {
class BlacklistStateFetcher;
class Extension;
class ExtensionPrefs;
class Blacklist : public content::NotificationObserver,
public base::SupportsWeakPtr<Blacklist> {
public:
class Observer {
public:
explicit Observer(Blacklist* blacklist);
virtual void OnBlacklistUpdated() = 0;
protected:
virtual ~Observer();
private:
Blacklist* blacklist_;
};
class ScopedDatabaseManagerForTest {
public:
explicit ScopedDatabaseManagerForTest(
scoped_refptr<SafeBrowsingDatabaseManager> database_manager);
~ScopedDatabaseManagerForTest();
private:
scoped_refptr<SafeBrowsingDatabaseManager> original_;
DISALLOW_COPY_AND_ASSIGN(ScopedDatabaseManagerForTest);
};
typedef std::map<std::string, BlacklistState> BlacklistStateMap;
typedef base::Callback<void(const BlacklistStateMap&)>
GetBlacklistedIDsCallback;
typedef base::Callback<void(const std::set<std::string>&)>
GetMalwareIDsCallback;
typedef base::Callback<void(BlacklistState)> IsBlacklistedCallback;
explicit Blacklist(ExtensionPrefs* prefs);
virtual ~Blacklist();
void GetBlacklistedIDs(const std::set<std::string>& ids,
const GetBlacklistedIDsCallback& callback);
void GetMalwareIDs(const std::set<std::string>& ids,
const GetMalwareIDsCallback& callback);
void IsBlacklisted(const std::string& extension_id,
const IsBlacklistedCallback& callback);
void SetBlacklistStateFetcherForTest(BlacklistStateFetcher* fetcher);
BlacklistStateFetcher* ResetBlacklistStateFetcherForTest();
void AddObserver(Observer* observer);
void RemoveObserver(Observer* observer);
private:
static void SetDatabaseManager(
scoped_refptr<SafeBrowsingDatabaseManager> database_manager);
static scoped_refptr<SafeBrowsingDatabaseManager> GetDatabaseManager();
virtual void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
void GetBlacklistStateForIDs(const GetBlacklistedIDsCallback& callback,
const std::set<std::string>& blacklisted_ids);
void RequestExtensionsBlacklistState(const std::set<std::string>& ids,
const base::Callback<void()>& callback);
void OnBlacklistStateReceived(const std::string& id, BlacklistState state);
void ReturnBlacklistStateMap(const GetBlacklistedIDsCallback& callback,
const std::set<std::string>& blacklisted_ids);
ObserverList<Observer> observers_;
content::NotificationRegistrar registrar_;
BlacklistStateMap blacklist_state_cache_;
scoped_ptr<BlacklistStateFetcher> state_fetcher_;
typedef std::list<std::pair<std::vector<std::string>,
base::Callback<void()> > >
StateRequestsList;
StateRequestsList state_requests_;
DISALLOW_COPY_AND_ASSIGN(Blacklist);
};
}
#endif