#ifndef CHROME_BROWSER_SEARCH_INSTANT_SERVICE_H_
#define CHROME_BROWSER_SEARCH_INSTANT_SERVICE_H_
#include <map>
#include <set>
#include <string>
#include <vector>
#include "base/basictypes.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/observer_list.h"
#include "base/prefs/pref_change_registrar.h"
#include "chrome/browser/google/google_url_tracker.h"
#include "chrome/browser/history/history_types.h"
#include "chrome/browser/ui/search/instant_search_prerenderer.h"
#include "chrome/common/instant_types.h"
#include "components/keyed_service/core/keyed_service.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
class GURL;
class InstantIOContext;
class InstantServiceObserver;
class InstantTestBase;
class InstantServiceTest;
class Profile;
class ThemeService;
namespace content {
class RenderProcessHost;
}
namespace net {
class URLRequest;
}
class InstantService : public KeyedService,
public content::NotificationObserver {
public:
explicit InstantService(Profile* profile);
virtual ~InstantService();
void AddInstantProcess(int process_id);
bool IsInstantProcess(int process_id) const;
void AddObserver(InstantServiceObserver* observer);
void RemoveObserver(InstantServiceObserver* observer);
#if defined(UNIT_TEST)
int GetInstantProcessCount() const {
return process_ids_.size();
}
#endif
void DeleteMostVisitedItem(const GURL& url);
void UndoMostVisitedDeletion(const GURL& url);
void UndoAllMostVisitedDeletions();
void UpdateThemeInfo();
void UpdateMostVisitedItemsInfo();
void SendSearchURLsToRenderer(content::RenderProcessHost* rph);
void OnOmniboxStartMarginChanged(int start_margin);
InstantSearchPrerenderer* instant_search_prerenderer() {
return instant_prerenderer_.get();
}
int omnibox_start_margin() const { return omnibox_start_margin_; }
private:
friend class InstantExtendedTest;
friend class InstantServiceTest;
friend class InstantTestBase;
friend class InstantUnitTestBase;
FRIEND_TEST_ALL_PREFIXES(InstantExtendedManualTest,
MANUAL_SearchesFromFakebox);
FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, ProcessIsolation);
FRIEND_TEST_ALL_PREFIXES(InstantServiceTest, SendsSearchURLsToRenderer);
virtual void Shutdown() OVERRIDE;
virtual void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
void OnRendererProcessTerminated(int process_id);
void OnMostVisitedItemsReceived(const history::MostVisitedURLList& data);
void NotifyAboutMostVisitedItems();
void OnThemeChanged(ThemeService* theme_service);
void OnGoogleURLUpdated(Profile* profile,
GoogleURLTracker::UpdatedDetails* details);
void OnDefaultSearchProviderChanged(const std::string& pref_name);
void ResetInstantSearchPrerenderer();
Profile* const profile_;
std::set<int> process_ids_;
std::vector<InstantMostVisitedItem> most_visited_items_;
scoped_ptr<ThemeBackgroundInfo> theme_info_;
int omnibox_start_margin_;
ObserverList<InstantServiceObserver> observers_;
content::NotificationRegistrar registrar_;
PrefChangeRegistrar profile_pref_registrar_;
scoped_refptr<InstantIOContext> instant_io_context_;
scoped_ptr<InstantSearchPrerenderer> instant_prerenderer_;
base::WeakPtrFactory<InstantService> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(InstantService);
};
#endif