Switch global error menu icon to vectorized MD asset
[chromium-blink-merge.git] / chrome / browser / ui / search / instant_search_prerenderer.h
blob4ab8320e412705c1c7112ba505a8ca1b2de9f160
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_UI_SEARCH_INSTANT_SEARCH_PRERENDERER_H_
6 #define CHROME_BROWSER_UI_SEARCH_INSTANT_SEARCH_PRERENDERER_H_
8 #include "base/basictypes.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/strings/string16.h"
11 #include "chrome/common/instant_types.h"
12 #include "content/public/browser/navigation_controller.h"
14 class GURL;
15 class Profile;
16 struct AutocompleteMatch;
18 namespace chrome {
19 struct NavigateParams;
22 namespace content {
23 class SessionStorageNamespace;
24 class WebContents;
27 namespace gfx {
28 class Size;
31 namespace prerender {
32 class PrerenderHandle;
35 // InstantSearchPrerenderer is responsible for prerendering the default search
36 // provider Instant search base page URL to prefetch high-confidence search
37 // suggestions. InstantSearchPrerenderer manages the prerender handle associated
38 // with the prerendered contents.
39 class InstantSearchPrerenderer {
40 public:
41 InstantSearchPrerenderer(Profile* profile, const GURL& url);
42 ~InstantSearchPrerenderer();
44 // Returns the InstantSearchPrerenderer instance for the given |profile|.
45 static InstantSearchPrerenderer* GetForProfile(Profile* profile);
47 // Prerender the |prerender_url_| contents. |session_storage_namespace| is
48 // used to identify the namespace of the active tab at the time the prerender
49 // is generated. The |size| gives the initial size for the target
50 // prerender. InstantSearchPrerenderer will run at most one prerender at a
51 // time, so launching a prerender will cancel the previous prerenders (if
52 // any).
53 void Init(content::SessionStorageNamespace* session_storage_namespace,
54 const gfx::Size& size);
56 // Cancels the current request.
57 void Cancel();
59 // Tells the Instant search base page to prerender |suggestion|.
60 void Prerender(const InstantSuggestion& suggestion);
62 // Tells the Instant search base page to render the search results for the
63 // given |query|.
64 void Commit(const base::string16& query,
65 const EmbeddedSearchRequestParams& params);
67 // Returns true if the prerendered page can be used to process the search for
68 // the given |source|.
69 bool CanCommitQuery(content::WebContents* source,
70 const base::string16& query) const;
72 // Returns true and updates |params->target_contents| if a prerendered page
73 // exists for |url| and is swapped in.
74 bool UsePrerenderedPage(const GURL& url, chrome::NavigateParams* params);
76 // Returns the last prefetched search query.
77 const base::string16& get_last_query() const {
78 return last_instant_suggestion_.text;
81 // Returns true when prerendering is allowed for the given |source| and
82 // |match|.
83 bool IsAllowed(const AutocompleteMatch& match,
84 content::WebContents* source) const;
86 private:
87 friend class InstantSearchPrerendererTest;
89 content::WebContents* prerender_contents() const;
91 // Returns true if the |query| matches the last prefetched search query or if
92 // the 'reuse_instant_search_base_page' flag is enabled in the field trials.
93 bool QueryMatchesPrefetch(const base::string16& query) const;
95 Profile* const profile_;
97 // Instant search base page URL.
98 const GURL prerender_url_;
100 scoped_ptr<prerender::PrerenderHandle> prerender_handle_;
102 InstantSuggestion last_instant_suggestion_;
104 DISALLOW_COPY_AND_ASSIGN(InstantSearchPrerenderer);
107 #endif // CHROME_BROWSER_UI_SEARCH_INSTANT_SEARCH_PRERENDERER_H_