Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / search / instant_service.h
blob6da171dff99bf8b97a57eb864f1fc16e7e4564f9
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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_SEARCH_INSTANT_SERVICE_H_
6 #define CHROME_BROWSER_SEARCH_INSTANT_SERVICE_H_
8 #include <map>
9 #include <set>
10 #include <string>
11 #include <vector>
13 #include "base/basictypes.h"
14 #include "base/memory/ref_counted.h"
15 #include "base/memory/scoped_ptr.h"
16 #include "base/memory/weak_ptr.h"
17 #include "base/observer_list.h"
18 #include "base/prefs/pref_change_registrar.h"
19 #include "chrome/browser/google/google_url_tracker.h"
20 #include "chrome/browser/history/history_types.h"
21 #include "chrome/browser/ui/search/instant_search_prerenderer.h"
22 #include "chrome/common/instant_types.h"
23 #include "components/browser_context_keyed_service/browser_context_keyed_service.h"
24 #include "content/public/browser/notification_observer.h"
25 #include "content/public/browser/notification_registrar.h"
27 class GURL;
28 class InstantIOContext;
29 class InstantServiceObserver;
30 class InstantTestBase;
31 class InstantServiceTest;
32 class Profile;
33 class ThemeService;
35 namespace content {
36 class RenderProcessHost;
39 namespace net {
40 class URLRequest;
43 // Tracks render process host IDs that are associated with Instant.
44 class InstantService : public BrowserContextKeyedService,
45 public content::NotificationObserver {
46 public:
47 explicit InstantService(Profile* profile);
48 virtual ~InstantService();
50 // Add, remove, and query RenderProcessHost IDs that are associated with
51 // Instant processes.
52 void AddInstantProcess(int process_id);
53 bool IsInstantProcess(int process_id) const;
55 // Adds/Removes InstantService observers.
56 void AddObserver(InstantServiceObserver* observer);
57 void RemoveObserver(InstantServiceObserver* observer);
59 #if defined(UNIT_TEST)
60 int GetInstantProcessCount() const {
61 return process_ids_.size();
63 #endif
65 // Most visited item API.
67 // Invoked by the InstantController when the Instant page wants to delete a
68 // Most Visited item.
69 void DeleteMostVisitedItem(const GURL& url);
71 // Invoked by the InstantController when the Instant page wants to undo the
72 // blacklist action.
73 void UndoMostVisitedDeletion(const GURL& url);
75 // Invoked by the InstantController when the Instant page wants to undo all
76 // Most Visited deletions.
77 void UndoAllMostVisitedDeletions();
79 // Invoked by the InstantController to update theme information for NTP.
81 // TODO(kmadhusu): Invoking this from InstantController shouldn't be
82 // necessary. Investigate more and remove this from here.
83 void UpdateThemeInfo();
85 // Invoked by the InstantController to update most visited items details for
86 // NTP.
87 void UpdateMostVisitedItemsInfo();
89 // Sends the current set of search URLs to a renderer process.
90 void SendSearchURLsToRenderer(content::RenderProcessHost* rph);
92 InstantSearchPrerenderer* instant_search_prerenderer() {
93 return instant_prerenderer_.get();
96 private:
97 friend class InstantExtendedTest;
98 friend class InstantServiceTest;
99 friend class InstantTestBase;
100 friend class InstantUnitTestBase;
102 FRIEND_TEST_ALL_PREFIXES(InstantExtendedManualTest,
103 MANUAL_SearchesFromFakebox);
104 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, ProcessIsolation);
105 FRIEND_TEST_ALL_PREFIXES(InstantServiceTest, SendsSearchURLsToRenderer);
107 // Overridden from BrowserContextKeyedService:
108 virtual void Shutdown() OVERRIDE;
110 // Overridden from content::NotificationObserver:
111 virtual void Observe(int type,
112 const content::NotificationSource& source,
113 const content::NotificationDetails& details) OVERRIDE;
115 // Called when a renderer process is terminated.
116 void OnRendererProcessTerminated(int process_id);
118 // Called when we get new most visited items from TopSites, registered as an
119 // async callback. Parses them and sends them to the renderer via
120 // SendMostVisitedItems.
121 void OnMostVisitedItemsReceived(const history::MostVisitedURLList& data);
123 // Notifies the observer about the last known most visited items.
124 void NotifyAboutMostVisitedItems();
126 // Theme changed notification handler.
127 void OnThemeChanged(ThemeService* theme_service);
129 void OnGoogleURLUpdated(Profile* profile,
130 GoogleURLTracker::UpdatedDetails* details);
132 void OnDefaultSearchProviderChanged(const std::string& pref_name);
134 void ResetInstantSearchPrerenderer();
136 Profile* const profile_;
138 // The process ids associated with Instant processes.
139 std::set<int> process_ids_;
141 // InstantMostVisitedItems sent to the Instant Pages.
142 std::vector<InstantMostVisitedItem> most_visited_items_;
144 // Theme-related data for NTP overlay to adopt themes.
145 scoped_ptr<ThemeBackgroundInfo> theme_info_;
147 ObserverList<InstantServiceObserver> observers_;
149 content::NotificationRegistrar registrar_;
151 PrefChangeRegistrar profile_pref_registrar_;
153 scoped_refptr<InstantIOContext> instant_io_context_;
155 // Set to NULL if the default search provider does not support Instant.
156 scoped_ptr<InstantSearchPrerenderer> instant_prerenderer_;
158 // Used for Top Sites async retrieval.
159 base::WeakPtrFactory<InstantService> weak_ptr_factory_;
161 DISALLOW_COPY_AND_ASSIGN(InstantService);
164 #endif // CHROME_BROWSER_SEARCH_INSTANT_SERVICE_H_