Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(323)

Side by Side Diff: chrome/browser/ui/search/instant_controller.h

Issue 14660022: Move most visited item state info from InstantController to InstantService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase + Addressed comments Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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_UI_SEARCH_INSTANT_CONTROLLER_H_ 5 #ifndef CHROME_BROWSER_UI_SEARCH_INSTANT_CONTROLLER_H_
6 #define CHROME_BROWSER_UI_SEARCH_INSTANT_CONTROLLER_H_ 6 #define CHROME_BROWSER_UI_SEARCH_INSTANT_CONTROLLER_H_
7 7
8 #include <list> 8 #include <list>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/basictypes.h" 13 #include "base/basictypes.h"
14 #include "base/gtest_prod_util.h" 14 #include "base/gtest_prod_util.h"
15 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/scoped_ptr.h"
16 #include "base/string16.h" 16 #include "base/string16.h"
17 #include "base/time.h" 17 #include "base/time.h"
18 #include "base/timer.h" 18 #include "base/timer.h"
19 #include "chrome/browser/history/history_types.h"
20 #include "chrome/browser/ui/omnibox/omnibox_edit_model.h" 19 #include "chrome/browser/ui/omnibox/omnibox_edit_model.h"
21 #include "chrome/browser/ui/search/instant_commit_type.h" 20 #include "chrome/browser/ui/search/instant_commit_type.h"
22 #include "chrome/browser/ui/search/instant_overlay_model.h" 21 #include "chrome/browser/ui/search/instant_overlay_model.h"
23 #include "chrome/browser/ui/search/instant_page.h" 22 #include "chrome/browser/ui/search/instant_page.h"
24 #include "chrome/common/instant_types.h" 23 #include "chrome/common/instant_types.h"
25 #include "chrome/common/omnibox_focus_state.h" 24 #include "chrome/common/omnibox_focus_state.h"
26 #include "chrome/common/search_types.h" 25 #include "chrome/common/search_types.h"
27 #include "content/public/browser/notification_observer.h"
28 #include "content/public/browser/notification_registrar.h"
29 #include "content/public/common/page_transition_types.h" 26 #include "content/public/common/page_transition_types.h"
30 #include "googleurl/src/gurl.h" 27 #include "googleurl/src/gurl.h"
31 #include "ui/base/window_open_disposition.h" 28 #include "ui/base/window_open_disposition.h"
32 #include "ui/gfx/native_widget_types.h" 29 #include "ui/gfx/native_widget_types.h"
33 #include "ui/gfx/rect.h" 30 #include "ui/gfx/rect.h"
34 31
35 struct AutocompleteMatch; 32 struct AutocompleteMatch;
36 struct InstantAutocompleteResult; 33 struct InstantAutocompleteResult;
37 34
38 class AutocompleteProvider; 35 class AutocompleteProvider;
(...skipping 23 matching lines...) Expand all
62 // swapped-in the next time the user navigates to the New Tab Page. It is 59 // swapped-in the next time the user navigates to the New Tab Page. It is
63 // never shown to the user in an uncommitted state. 60 // never shown to the user in an uncommitted state.
64 // (3) An InstantTab instance which points to the currently active tab, if it 61 // (3) An InstantTab instance which points to the currently active tab, if it
65 // supports the Embedded Search API. 62 // supports the Embedded Search API.
66 // 63 //
67 // All three are backed by a WebContents. InstantOverlay and InstantNTP own 64 // All three are backed by a WebContents. InstantOverlay and InstantNTP own
68 // their corresponding WebContents; InstantTab does not. In non-extended mode, 65 // their corresponding WebContents; InstantTab does not. In non-extended mode,
69 // only an InstantOverlay instance is kept. 66 // only an InstantOverlay instance is kept.
70 // 67 //
71 // InstantController is owned by Browser via BrowserInstantController. 68 // InstantController is owned by Browser via BrowserInstantController.
72 class InstantController : public InstantPage::Delegate, 69 class InstantController : public InstantPage::Delegate {
73 public content::NotificationObserver {
74 public: 70 public:
75 InstantController(BrowserInstantController* browser, 71 InstantController(BrowserInstantController* browser,
76 bool extended_enabled); 72 bool extended_enabled);
77 virtual ~InstantController(); 73 virtual ~InstantController();
78 74
79 // Called when the Autocomplete flow is about to start. Sets up the 75 // Called when the Autocomplete flow is about to start. Sets up the
80 // appropriate page to send user updates to. May reset |instant_tab_| or 76 // appropriate page to send user updates to. May reset |instant_tab_| or
81 // switch to a local fallback |overlay_| as necessary. 77 // switch to a local fallback |overlay_| as necessary.
82 void OnAutocompleteStart(); 78 void OnAutocompleteStart();
83 79
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 202
207 // Returns the transition type of the last AutocompleteMatch passed to Update. 203 // Returns the transition type of the last AutocompleteMatch passed to Update.
208 content::PageTransition last_transition_type() const { 204 content::PageTransition last_transition_type() const {
209 return last_transition_type_; 205 return last_transition_type_;
210 } 206 }
211 207
212 // Non-const for Add/RemoveObserver only. Other model changes should only 208 // Non-const for Add/RemoveObserver only. Other model changes should only
213 // happen through the InstantController interface. 209 // happen through the InstantController interface.
214 InstantOverlayModel* model() { return &model_; } 210 InstantOverlayModel* model() { return &model_; }
215 211
212 // Gets the Most Visited items info from InstantService and forwards them to
213 // the Instant page renderer via the appropriate InstantPage subclass.
214 void UpdateMostVisitedItems();
215
216 private: 216 private:
217 friend class InstantTestBase; 217 friend class InstantTestBase;
218 FRIEND_TEST_ALL_PREFIXES(InstantTest, OmniboxFocusLoadsInstant); 218 FRIEND_TEST_ALL_PREFIXES(InstantTest, OmniboxFocusLoadsInstant);
219 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, UsesOverlayIfTabNotReady); 219 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, UsesOverlayIfTabNotReady);
220 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, 220 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest,
221 SearchQueryNotDisplayedForNavsuggest); 221 SearchQueryNotDisplayedForNavsuggest);
222 FRIEND_TEST_ALL_PREFIXES(InstantTest, SetWithTemplateURL); 222 FRIEND_TEST_ALL_PREFIXES(InstantTest, SetWithTemplateURL);
223 FRIEND_TEST_ALL_PREFIXES(InstantTest, NonInstantSearchProvider); 223 FRIEND_TEST_ALL_PREFIXES(InstantTest, NonInstantSearchProvider);
224 FRIEND_TEST_ALL_PREFIXES(InstantTest, InstantOverlayRefresh); 224 FRIEND_TEST_ALL_PREFIXES(InstantTest, InstantOverlayRefresh);
225 FRIEND_TEST_ALL_PREFIXES(InstantTest, InstantOverlayRefreshDifferentOrder); 225 FRIEND_TEST_ALL_PREFIXES(InstantTest, InstantOverlayRefreshDifferentOrder);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 ReloadSearchAfterBackReloadsCorrectQuery); 266 ReloadSearchAfterBackReloadsCorrectQuery);
267 FRIEND_TEST_ALL_PREFIXES( 267 FRIEND_TEST_ALL_PREFIXES(
268 InstantExtendedFirstTabTest, RedirectToLocalOnLoadFailure); 268 InstantExtendedFirstTabTest, RedirectToLocalOnLoadFailure);
269 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, LogDropdownShown); 269 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, LogDropdownShown);
270 270
271 Profile* profile() const; 271 Profile* profile() const;
272 InstantOverlay* overlay() const; 272 InstantOverlay* overlay() const;
273 InstantTab* instant_tab() const; 273 InstantTab* instant_tab() const;
274 InstantNTP* ntp() const; 274 InstantNTP* ntp() const;
275 275
276 // Overridden from content::NotificationObserver:
277 virtual void Observe(int type,
278 const content::NotificationSource& source,
279 const content::NotificationDetails& details) OVERRIDE;
280
281 // Overridden from InstantPage::Delegate: 276 // Overridden from InstantPage::Delegate:
282 // TODO(shishir): We assume that the WebContent's current RenderViewHost is 277 // TODO(shishir): We assume that the WebContent's current RenderViewHost is
283 // the RenderViewHost being created which is not always true. Fix this. 278 // the RenderViewHost being created which is not always true. Fix this.
284 virtual void InstantPageRenderViewCreated( 279 virtual void InstantPageRenderViewCreated(
285 const content::WebContents* contents) OVERRIDE; 280 const content::WebContents* contents) OVERRIDE;
286 virtual void InstantSupportDetermined( 281 virtual void InstantSupportDetermined(
287 const content::WebContents* contents, 282 const content::WebContents* contents,
288 bool supports_instant) OVERRIDE; 283 bool supports_instant) OVERRIDE;
289 virtual void InstantPageRenderViewGone( 284 virtual void InstantPageRenderViewGone(
290 const content::WebContents* contents) OVERRIDE; 285 const content::WebContents* contents) OVERRIDE;
(...skipping 13 matching lines...) Expand all
304 virtual void NavigateToURL( 299 virtual void NavigateToURL(
305 const content::WebContents* contents, 300 const content::WebContents* contents,
306 const GURL& url, 301 const GURL& url,
307 content::PageTransition transition, 302 content::PageTransition transition,
308 WindowOpenDisposition disposition, 303 WindowOpenDisposition disposition,
309 bool is_search_type) OVERRIDE; 304 bool is_search_type) OVERRIDE;
310 virtual void InstantPageLoadFailed(content::WebContents* contents) OVERRIDE; 305 virtual void InstantPageLoadFailed(content::WebContents* contents) OVERRIDE;
311 306
312 // Invoked by the InstantLoader when the Instant page wants to delete a 307 // Invoked by the InstantLoader when the Instant page wants to delete a
313 // Most Visited item. 308 // Most Visited item.
314 virtual void DeleteMostVisitedItem(InstantRestrictedID most_visited_item_id) 309 virtual void DeleteMostVisitedItem(const GURL& url) OVERRIDE;
315 OVERRIDE;
316 310
317 // Invoked by the InstantLoader when the Instant page wants to undo a 311 // Invoked by the InstantLoader when the Instant page wants to undo a
318 // Most Visited deletion. 312 // Most Visited deletion.
319 virtual void UndoMostVisitedDeletion(InstantRestrictedID most_visited_item_id) 313 virtual void UndoMostVisitedDeletion(const GURL& url) OVERRIDE;
320 OVERRIDE;
321 314
322 // Invoked by the InstantLoader when the Instant page wants to undo all 315 // Invoked by the InstantLoader when the Instant page wants to undo all
323 // Most Visited deletions. 316 // Most Visited deletions.
324 virtual void UndoAllMostVisitedDeletions() OVERRIDE; 317 virtual void UndoAllMostVisitedDeletions() OVERRIDE;
325 318
326 // Helper function to navigate the given contents to the local fallback 319 // Helper function to navigate the given contents to the local fallback
327 // Instant URL and trim the history correctly. 320 // Instant URL and trim the history correctly.
328 void RedirectToLocalNTP(content::WebContents* contents); 321 void RedirectToLocalNTP(content::WebContents* contents);
329 322
330 // Helper for OmniboxFocusChanged. Commit or discard the overlay. 323 // Helper for OmniboxFocusChanged. Commit or discard the overlay.
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 // unless you are going to call overlay_.reset() yourself subsequently. 370 // unless you are going to call overlay_.reset() yourself subsequently.
378 void HideInternal(); 371 void HideInternal();
379 372
380 // Counterpart to HideOverlay(). Asks the |browser_| to display the overlay 373 // Counterpart to HideOverlay(). Asks the |browser_| to display the overlay
381 // with the given |height| in |units|. 374 // with the given |height| in |units|.
382 void ShowOverlay(int height, InstantSizeUnits units); 375 void ShowOverlay(int height, InstantSizeUnits units);
383 376
384 // Send the omnibox popup bounds to the page. 377 // Send the omnibox popup bounds to the page.
385 void SendPopupBoundsToPage(); 378 void SendPopupBoundsToPage();
386 379
387 // Begin listening to change notifications from TopSites and fire off an
388 // initial request for most visited items.
389 void StartListeningToMostVisitedChanges();
390 380
391 // Fire off an async request for most visited items to the TopNav code.
392 void RequestMostVisitedItems();
393
394 // Called when we get new most visited items from the TopNav code,
395 // registered as an async callback. Parses them and sends them to the
396 // renderer via SendMostVisitedItems.
397 void OnMostVisitedItemsReceived(const history::MostVisitedURLList& data);
398
399 // Sends a collection of MostVisitedItems to the renderer process via
400 // the appropriate InstantPage subclass.
401 void SendMostVisitedItems(
402 const std::vector<InstantMostVisitedItemIDPair>& items);
403 381
404 // If possible, tries to mutate |suggestion| to a valid suggestion. Returns 382 // If possible, tries to mutate |suggestion| to a valid suggestion. Returns
405 // true if successful. (Note that |suggestion| may be modified even if this 383 // true if successful. (Note that |suggestion| may be modified even if this
406 // returns false.) 384 // returns false.)
407 bool FixSuggestion(InstantSuggestion* suggestion) const; 385 bool FixSuggestion(InstantSuggestion* suggestion) const;
408 386
409 // Returns true if the local page is being used. 387 // Returns true if the local page is being used.
410 bool UsingLocalPage() const; 388 bool UsingLocalPage() const;
411 389
412 // Returns true iff |use_tab_for_suggestions_| is true and |instant_tab_| 390 // Returns true iff |use_tab_for_suggestions_| is true and |instant_tab_|
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 bool first_interaction_time_recorded_; 494 bool first_interaction_time_recorded_;
517 495
518 // Whether to allow the overlay to show search suggestions. In general, the 496 // Whether to allow the overlay to show search suggestions. In general, the
519 // overlay is allowed to show search suggestions whenever |search_mode_| is 497 // overlay is allowed to show search suggestions whenever |search_mode_| is
520 // MODE_SEARCH_SUGGESTIONS, except in those cases where this is false. 498 // MODE_SEARCH_SUGGESTIONS, except in those cases where this is false.
521 bool allow_overlay_to_show_search_suggestions_; 499 bool allow_overlay_to_show_search_suggestions_;
522 500
523 // List of events and their timestamps, useful in debugging Instant behaviour. 501 // List of events and their timestamps, useful in debugging Instant behaviour.
524 mutable std::list<std::pair<int64, std::string> > debug_events_; 502 mutable std::list<std::pair<int64, std::string> > debug_events_;
525 503
526 // Used for Top Sites async retrieval.
527 base::WeakPtrFactory<InstantController> weak_ptr_factory_;
528
529 // Used to get notifications about Most Visted changes.
530 content::NotificationRegistrar registrar_;
531
532 DISALLOW_COPY_AND_ASSIGN(InstantController); 504 DISALLOW_COPY_AND_ASSIGN(InstantController);
533 }; 505 };
534 506
535 #endif // CHROME_BROWSER_UI_SEARCH_INSTANT_CONTROLLER_H_ 507 #endif // CHROME_BROWSER_UI_SEARCH_INSTANT_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698