OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_INSTANT_INSTANT_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_INSTANT_INSTANT_SERVICE_H_ |
6 #define CHROME_BROWSER_INSTANT_INSTANT_SERVICE_H_ | 6 #define CHROME_BROWSER_INSTANT_INSTANT_SERVICE_H_ |
7 | 7 |
8 #include <list> | |
8 #include <set> | 9 #include <set> |
10 #include <string> | |
11 #include <utility> | |
12 #include <vector> | |
9 | 13 |
10 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
11 #include "base/compiler_specific.h" | 15 #include "base/compiler_specific.h" |
12 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
17 #include "base/memory/scoped_ptr.h" | |
18 #include "base/observer_list.h" | |
19 #include "base/prefs/public/pref_change_registrar.h" | |
20 #include "base/string16.h" | |
21 #include "chrome/browser/history/history_types.h" | |
13 #include "chrome/browser/profiles/profile_keyed_service.h" | 22 #include "chrome/browser/profiles/profile_keyed_service.h" |
23 #include "chrome/common/instant_types.h" | |
14 #include "content/public/browser/notification_observer.h" | 24 #include "content/public/browser/notification_observer.h" |
15 #include "content/public/browser/notification_registrar.h" | 25 #include "content/public/browser/notification_registrar.h" |
16 | 26 |
17 class InstantIOContext; | 27 class InstantIOContext; |
28 class InstantPreloader; | |
29 class InstantServiceObserver; | |
18 class Profile; | 30 class Profile; |
31 class ThemeService; | |
19 | 32 |
20 // Tracks render process host IDs that are associated with Instant. | 33 namespace history { |
34 class TopSites; | |
35 } | |
36 | |
37 // 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
| |
38 // chrome://settings preferences, omnibox size, theme background, etc. | |
21 class InstantService : public ProfileKeyedService, | 39 class InstantService : public ProfileKeyedService, |
22 public content::NotificationObserver { | 40 public content::NotificationObserver { |
23 public: | 41 public: |
24 explicit InstantService(Profile* profile); | 42 explicit InstantService(Profile* profile); |
25 virtual ~InstantService(); | 43 virtual ~InstantService(); |
26 | 44 |
27 // Add, remove, and query RenderProcessHost IDs that are associated with | 45 Profile* profile() const { return profile_; } |
28 // Instant processes. | 46 InstantPreloader* preloader() const { return preloader_.get(); } |
47 | |
48 typedef std::list<std::pair<int64, std::string> > DebugEventsList; | |
49 const DebugEventsList& debug_events() const { | |
50 return debug_events_; | |
51 } | |
52 void LogDebugEvent(const std::string& message); | |
53 void ClearDebugEvents(); | |
54 | |
55 void AddObserver(InstantServiceObserver* observer); | |
56 void RemoveObserver(InstantServiceObserver* observer); | |
57 | |
58 // Query and modify RenderProcessHost IDs associated with Instant processes. | |
59 bool IsInstantProcess(int process_id) const; | |
29 void AddInstantProcess(int process_id); | 60 void AddInstantProcess(int process_id); |
30 bool IsInstantProcess(int process_id) const; | 61 void RemoveInstantProcess(int process_id); |
31 | 62 |
32 #if defined(UNIT_TEST) | 63 #if defined(UNIT_TEST) |
33 int GetInstantProcessCount() const { | 64 int GetInstantProcessCount() const { return process_ids_.size(); } |
34 return process_ids_.size(); | |
35 } | |
36 #endif | 65 #endif |
37 | 66 |
67 const string16& omnibox_font_name() const { return omnibox_font_name_; } | |
68 size_t omnibox_font_size() const { return omnibox_font_size_; } | |
69 | |
70 // The omnibox start margin is the same in all browser windows in a profile, | |
71 // so it can be considered a per-profile setting. It is used in contexts | |
72 // where there are no browser windows available, such as in InstantPreloader. | |
73 // However, since InstantService has no knowledge of browser windows, this | |
74 // information must be passed to us by say, an InstantController. If there | |
75 // are multiple windows open, and the margin changes, each instance of | |
76 // InstantController will call us with this info, but it shouldn't be a | |
77 // problem since, as above, the info will be the same in all calls. | |
78 int omnibox_start_margin() const { return omnibox_start_margin_; } | |
79 void set_omnibox_start_margin(int omnibox_start_margin) { | |
80 omnibox_start_margin_ = omnibox_start_margin; | |
81 } | |
82 | |
83 const ThemeBackgroundInfo& theme_info() const { return theme_info_; } | |
84 | |
85 const std::vector<MostVisitedItem>& most_visited_items() const { | |
86 return most_visited_items_; | |
87 } | |
88 | |
89 void InstantSupportDetermined(); | |
90 | |
38 private: | 91 private: |
39 // Overridden from ProfileKeyedService: | |
40 virtual void Shutdown() OVERRIDE; | |
41 | |
42 // Overridden from content::NotificationObserver: | 92 // Overridden from content::NotificationObserver: |
43 virtual void Observe(int type, | 93 virtual void Observe(int type, |
44 const content::NotificationSource& source, | 94 const content::NotificationSource& source, |
45 const content::NotificationDetails& details) OVERRIDE; | 95 const content::NotificationDetails& details) OVERRIDE; |
46 | 96 |
97 // Called whenever one of the prefs we are monitoring changes. If the | |
98 // effective status of Instant or the Instant pref changes as a result, causes | |
99 // InstantStatusChanged() to be called on |observers_|. | |
100 void PrefChanged(const std::string& pref_name); | |
101 | |
102 // Called whenever theme information changes. Causes ThemeInfoChanged() to be | |
103 // called on |observers_|. | |
104 void ParseTheme(ThemeService* theme_service); | |
105 | |
106 // Called whenever the Most Visited Items in history changed. This kicks off | |
107 // a request to fetch the actual items. | |
108 void RequestMostVisitedItems(history::TopSites* top_sites); | |
109 | |
110 // Called when the actual Most Visited Items are available. Causes | |
111 // MostVisitedItemsChanged() to be called on |observers_|. | |
112 void MostVisitedItemsReceived(const history::MostVisitedURLList& data); | |
113 | |
47 Profile* const profile_; | 114 Profile* const profile_; |
115 scoped_ptr<InstantPreloader> preloader_; | |
116 scoped_refptr<InstantIOContext> io_context_; | |
48 | 117 |
49 // The process ids associated with Instant processes. | 118 DebugEventsList debug_events_; |
119 | |
120 ObserverList<InstantServiceObserver> observers_; | |
121 content::NotificationRegistrar notification_registrar_; | |
122 PrefChangeRegistrar pref_change_registrar_; | |
123 | |
124 // The process IDs associated with Instant processes. | |
50 std::set<int> process_ids_; | 125 std::set<int> process_ids_; |
51 | 126 |
52 content::NotificationRegistrar registrar_; | 127 // Omnibox font name and size. Initialized at startup. These never change. |
128 string16 omnibox_font_name_; | |
129 size_t omnibox_font_size_; | |
53 | 130 |
54 scoped_refptr<InstantIOContext> instant_io_context_; | 131 int omnibox_start_margin_; |
132 | |
133 bool instant_pref_enabled_; | |
134 bool instant_enabled_; | |
135 | |
136 ThemeBackgroundInfo theme_info_; | |
137 | |
138 std::vector<MostVisitedItem> most_visited_items_; | |
55 | 139 |
56 DISALLOW_COPY_AND_ASSIGN(InstantService); | 140 DISALLOW_COPY_AND_ASSIGN(InstantService); |
57 }; | 141 }; |
58 | 142 |
59 #endif // CHROME_BROWSER_INSTANT_INSTANT_SERVICE_H_ | 143 #endif // CHROME_BROWSER_INSTANT_INSTANT_SERVICE_H_ |
OLD | NEW |