#ifndef CHROME_BROWSER_EXTENSIONS_API_WEBSTORE_WEBSTORE_API_H_
#define CHROME_BROWSER_EXTENSIONS_API_WEBSTORE_WEBSTORE_API_H_
#include <list>
#include <string>
#include "base/memory/scoped_ptr.h"
#include "base/scoped_observer.h"
#include "chrome/browser/extensions/install_observer.h"
#include "chrome/common/extensions/api/webstore/webstore_api_constants.h"
#include "extensions/browser/browser_context_keyed_api_factory.h"
#include "extensions/browser/event_router.h"
namespace base {
class ListValue;
}
namespace content {
class BrowserContext;
}
namespace ipc {
class Sender;
}
namespace extensions {
class InstallTracker;
class WebstoreAPI : public BrowserContextKeyedAPI,
public InstallObserver {
public:
explicit WebstoreAPI(content::BrowserContext* browser_context);
virtual ~WebstoreAPI();
static WebstoreAPI* Get(content::BrowserContext* browser_context);
void OnInlineInstallStart(int routing_id,
IPC::Sender* ipc_sender,
const std::string& extension_id,
int listener_mask);
void OnInlineInstallFinished(int routing_id, const std::string& extension_id);
static BrowserContextKeyedAPIFactory<WebstoreAPI>* GetFactoryInstance();
private:
friend class BrowserContextKeyedAPIFactory<WebstoreAPI>;
struct ObservedInstallInfo;
typedef std::list<ObservedInstallInfo> ObservedInstallInfoList;
void SendInstallMessageIfObserved(const std::string& extension_id,
api::webstore::InstallStage install_stage);
void RemoveListeners(int routing_id,
const std::string& extension_id,
ObservedInstallInfoList* listeners);
virtual void OnBeginExtensionDownload(const std::string& extension_id)
OVERRIDE;
virtual void OnDownloadProgress(const std::string& extension_id,
int percent_downloaded) OVERRIDE;
virtual void OnBeginCrxInstall(const std::string& extension_id) OVERRIDE;
virtual void OnShutdown() OVERRIDE;
virtual void Shutdown() OVERRIDE;
static const char* service_name() { return "WebstoreAPI"; }
static const bool kServiceIsNULLWhileTesting = true;
ObservedInstallInfoList download_progress_listeners_;
ObservedInstallInfoList install_stage_listeners_;
content::BrowserContext* browser_context_;
scoped_ptr<ScopedObserver<InstallTracker, InstallObserver> >
install_observer_;
DISALLOW_COPY_AND_ASSIGN(WebstoreAPI);
};
}
#endif