Chromium Code Reviews| Index: chrome/browser/instant/instant_service.h |
| diff --git a/chrome/browser/instant/instant_service.h b/chrome/browser/instant/instant_service.h |
| index 4e08d89e10c693e60eb5767f4f4fe81f108d4ef1..036acdccb88eb931ebe5714c69db81e0f4298a89 100644 |
| --- a/chrome/browser/instant/instant_service.h |
| +++ b/chrome/browser/instant/instant_service.h |
| @@ -5,53 +5,137 @@ |
| #ifndef CHROME_BROWSER_INSTANT_INSTANT_SERVICE_H_ |
| #define CHROME_BROWSER_INSTANT_INSTANT_SERVICE_H_ |
| +#include <list> |
| #include <set> |
| +#include <string> |
| +#include <utility> |
| +#include <vector> |
| #include "base/basictypes.h" |
| #include "base/compiler_specific.h" |
| #include "base/memory/ref_counted.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "base/observer_list.h" |
| +#include "base/prefs/public/pref_change_registrar.h" |
| +#include "base/string16.h" |
| +#include "chrome/browser/history/history_types.h" |
| #include "chrome/browser/profiles/profile_keyed_service.h" |
| +#include "chrome/common/instant_types.h" |
| #include "content/public/browser/notification_observer.h" |
| #include "content/public/browser/notification_registrar.h" |
| class InstantIOContext; |
| +class InstantPreloader; |
| +class InstantServiceObserver; |
| class Profile; |
| +class ThemeService; |
| -// Tracks render process host IDs that are associated with Instant. |
| +namespace history { |
| +class TopSites; |
| +} |
| + |
| +// Tracks Instant-related per-profile things, such as render process host IDs, |
|
samarth
2013/03/11 19:03:24
nit: Tracks per-profile Instant-related things
|
| +// chrome://settings preferences, omnibox size, theme background, etc. |
| class InstantService : public ProfileKeyedService, |
| public content::NotificationObserver { |
| public: |
| explicit InstantService(Profile* profile); |
| virtual ~InstantService(); |
| - // Add, remove, and query RenderProcessHost IDs that are associated with |
| - // Instant processes. |
| - void AddInstantProcess(int process_id); |
| + Profile* profile() const { return profile_; } |
| + InstantPreloader* preloader() const { return preloader_.get(); } |
| + |
| + typedef std::list<std::pair<int64, std::string> > DebugEventsList; |
| + const DebugEventsList& debug_events() const { |
| + return debug_events_; |
| + } |
| + void LogDebugEvent(const std::string& message); |
| + void ClearDebugEvents(); |
| + |
| + void AddObserver(InstantServiceObserver* observer); |
| + void RemoveObserver(InstantServiceObserver* observer); |
| + |
| + // Query and modify RenderProcessHost IDs associated with Instant processes. |
| bool IsInstantProcess(int process_id) const; |
| + void AddInstantProcess(int process_id); |
| + void RemoveInstantProcess(int process_id); |
| #if defined(UNIT_TEST) |
| - int GetInstantProcessCount() const { |
| - return process_ids_.size(); |
| - } |
| + int GetInstantProcessCount() const { return process_ids_.size(); } |
| #endif |
| - private: |
| - // Overridden from ProfileKeyedService: |
| - virtual void Shutdown() OVERRIDE; |
| + const string16& omnibox_font_name() const { return omnibox_font_name_; } |
| + size_t omnibox_font_size() const { return omnibox_font_size_; } |
| + |
| + // The omnibox start margin is the same in all browser windows in a profile, |
| + // so it can be considered a per-profile setting. It is used in contexts |
| + // where there are no browser windows available, such as in InstantPreloader. |
| + // However, since InstantService has no knowledge of browser windows, this |
| + // information must be passed to us by say, an InstantController. If there |
| + // are multiple windows open, and the margin changes, each instance of |
| + // InstantController will call us with this info, but it shouldn't be a |
| + // problem since, as above, the info will be the same in all calls. |
| + int omnibox_start_margin() const { return omnibox_start_margin_; } |
| + void set_omnibox_start_margin(int omnibox_start_margin) { |
| + omnibox_start_margin_ = omnibox_start_margin; |
| + } |
| + |
| + const ThemeBackgroundInfo& theme_info() const { return theme_info_; } |
| + const std::vector<MostVisitedItem>& most_visited_items() const { |
| + return most_visited_items_; |
| + } |
| + |
| + void InstantSupportDetermined(); |
| + |
| + private: |
| // Overridden from content::NotificationObserver: |
| virtual void Observe(int type, |
| const content::NotificationSource& source, |
| const content::NotificationDetails& details) OVERRIDE; |
| + // Called whenever one of the prefs we are monitoring changes. If the |
| + // effective status of Instant or the Instant pref changes as a result, causes |
| + // InstantStatusChanged() to be called on |observers_|. |
| + void PrefChanged(const std::string& pref_name); |
| + |
| + // Called whenever theme information changes. Causes ThemeInfoChanged() to be |
| + // called on |observers_|. |
| + void ParseTheme(ThemeService* theme_service); |
| + |
| + // Called whenever the Most Visited Items in history changed. This kicks off |
| + // a request to fetch the actual items. |
| + void RequestMostVisitedItems(history::TopSites* top_sites); |
| + |
| + // Called when the actual Most Visited Items are available. Causes |
| + // MostVisitedItemsChanged() to be called on |observers_|. |
| + void MostVisitedItemsReceived(const history::MostVisitedURLList& data); |
| + |
| Profile* const profile_; |
| + scoped_ptr<InstantPreloader> preloader_; |
| + scoped_refptr<InstantIOContext> io_context_; |
| + |
| + DebugEventsList debug_events_; |
| + |
| + ObserverList<InstantServiceObserver> observers_; |
| + content::NotificationRegistrar notification_registrar_; |
| + PrefChangeRegistrar pref_change_registrar_; |
| - // The process ids associated with Instant processes. |
| + // The process IDs associated with Instant processes. |
| std::set<int> process_ids_; |
| - content::NotificationRegistrar registrar_; |
| + // Omnibox font name and size. Initialized at startup. These never change. |
| + string16 omnibox_font_name_; |
| + size_t omnibox_font_size_; |
| + |
| + int omnibox_start_margin_; |
| + |
| + bool instant_pref_enabled_; |
| + bool instant_enabled_; |
| + |
| + ThemeBackgroundInfo theme_info_; |
| - scoped_refptr<InstantIOContext> instant_io_context_; |
| + std::vector<MostVisitedItem> most_visited_items_; |
| DISALLOW_COPY_AND_ASSIGN(InstantService); |
| }; |