#ifndef CHROME_BROWSER_PRERENDER_PRERENDER_LINK_MANAGER_H_
#define CHROME_BROWSER_PRERENDER_PRERENDER_LINK_MANAGER_H_
#include <list>
#include "base/basictypes.h"
#include "base/gtest_prod_util.h"
#include "base/time/time.h"
#include "chrome/browser/prerender/prerender_handle.h"
#include "components/keyed_service/core/keyed_service.h"
#include "url/gurl.h"
class Profile;
namespace content {
struct Referrer;
}
namespace gfx {
class Size;
}
FORWARD_DECLARE_TEST(WebViewTest, NoPrerenderer);
namespace prerender {
class PrerenderContents;
class PrerenderManager;
class PrerenderLinkManager : public KeyedService,
public PrerenderHandle::Observer {
public:
explicit PrerenderLinkManager(PrerenderManager* manager);
virtual ~PrerenderLinkManager();
void OnAddPrerender(int child_id,
int prerender_id,
const GURL& url,
uint32 rel_types,
const content::Referrer& referrer,
const gfx::Size& size,
int render_view_route_id);
void OnCancelPrerender(int child_id, int prerender_id);
void OnAbandonPrerender(int child_id, int prerender_id);
void OnChannelClosing(int child_id);
private:
friend class PrerenderBrowserTest;
friend class PrerenderTest;
FRIEND_TEST_ALL_PREFIXES(::WebViewTest, NoPrerenderer);
struct LinkPrerender {
LinkPrerender(int launcher_child_id,
int prerender_id,
const GURL& url,
uint32 rel_types,
const content::Referrer& referrer,
const gfx::Size& size,
int render_view_route_id,
base::TimeTicks creation_time,
PrerenderContents* deferred_launcher);
~LinkPrerender();
int launcher_child_id;
int prerender_id;
GURL url;
uint32 rel_types;
content::Referrer referrer;
gfx::Size size;
int render_view_route_id;
base::TimeTicks creation_time;
PrerenderContents* deferred_launcher;
PrerenderHandle* handle;
bool is_match_complete_replacement;
bool has_been_abandoned;
};
class PendingPrerenderManager;
bool IsEmpty() const;
size_t CountRunningPrerenders() const;
void StartPrerenders();
LinkPrerender* FindByLauncherChildIdAndPrerenderId(int child_id,
int prerender_id);
LinkPrerender* FindByPrerenderHandle(PrerenderHandle* prerender_handle);
void RemovePrerender(LinkPrerender* prerender);
void CancelPrerender(LinkPrerender* prerender);
void StartPendingPrerendersForLauncher(PrerenderContents* launcher);
void CancelPendingPrerendersForLauncher(PrerenderContents* launcher);
virtual void Shutdown() OVERRIDE;
virtual void OnPrerenderStart(PrerenderHandle* prerender_handle) OVERRIDE;
virtual void OnPrerenderStopLoading(PrerenderHandle* prerender_handle)
OVERRIDE;
virtual void OnPrerenderDomContentLoaded(PrerenderHandle* prerender_handle)
OVERRIDE;
virtual void OnPrerenderStop(PrerenderHandle* prerender_handle) OVERRIDE;
virtual void OnPrerenderCreatedMatchCompleteReplacement(
PrerenderHandle* handle) OVERRIDE;
bool has_shutdown_;
PrerenderManager* manager_;
std::list<LinkPrerender> prerenders_;
scoped_ptr<PendingPrerenderManager> pending_prerender_manager_;
DISALLOW_COPY_AND_ASSIGN(PrerenderLinkManager);
};
}
#endif