OLD | NEW |
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 #include "chrome/browser/ui/search/instant_controller.h" | 5 #include "chrome/browser/ui/search/instant_controller.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/location.h" | 10 #include "base/location.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 #include "content/public/browser/notification_service.h" | 24 #include "content/public/browser/notification_service.h" |
25 #include "content/public/browser/web_contents.h" | 25 #include "content/public/browser/web_contents.h" |
26 #include "url/gurl.h" | 26 #include "url/gurl.h" |
27 | 27 |
28 // Macro used for logging debug events. |message| should be a std::string. | 28 // Macro used for logging debug events. |message| should be a std::string. |
29 #define LOG_INSTANT_DEBUG_EVENT(controller, message) \ | 29 #define LOG_INSTANT_DEBUG_EVENT(controller, message) \ |
30 controller->LogDebugEvent(message) | 30 controller->LogDebugEvent(message) |
31 | 31 |
32 namespace { | 32 namespace { |
33 | 33 |
34 bool IsContentsFrom(const InstantPage* page, | 34 bool IsContentsFrom(const InstantTab* page, |
35 const content::WebContents* contents) { | 35 const content::WebContents* contents) { |
36 return page && (page->web_contents() == contents); | 36 return page && (page->web_contents() == contents); |
37 } | 37 } |
38 | 38 |
39 // Adds a transient NavigationEntry to the supplied |contents|'s | 39 // Adds a transient NavigationEntry to the supplied |contents|'s |
40 // NavigationController if the page's URL has not already been updated with the | 40 // NavigationController if the page's URL has not already been updated with the |
41 // supplied |search_terms|. Sets the |search_terms| on the transient entry for | 41 // supplied |search_terms|. Sets the |search_terms| on the transient entry for |
42 // search terms extraction to work correctly. | 42 // search terms extraction to work correctly. |
43 void EnsureSearchTermsAreSet(content::WebContents* contents, | 43 void EnsureSearchTermsAreSet(content::WebContents* contents, |
44 const base::string16& search_terms) { | 44 const base::string16& search_terms) { |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 Profile* InstantController::profile() const { | 117 Profile* InstantController::profile() const { |
118 return browser_->profile(); | 118 return browser_->profile(); |
119 } | 119 } |
120 | 120 |
121 InstantTab* InstantController::instant_tab() const { | 121 InstantTab* InstantController::instant_tab() const { |
122 return instant_tab_.get(); | 122 return instant_tab_.get(); |
123 } | 123 } |
124 | 124 |
125 void InstantController::InstantSupportChanged( | 125 void InstantController::InstantSupportChanged( |
126 InstantSupportState instant_support) { | 126 InstantSupportState instant_support) { |
127 // Handle INSTANT_SUPPORT_YES here because InstantPage is not hooked up to the | 127 // Handle INSTANT_SUPPORT_YES here because InstantTab is not hooked up to the |
128 // active tab. Search model changed listener in InstantPage will handle other | 128 // active tab. Search model changed listener in InstantTab will handle other |
129 // cases. | 129 // cases. |
130 if (instant_support != INSTANT_SUPPORT_YES) | 130 if (instant_support != INSTANT_SUPPORT_YES) |
131 return; | 131 return; |
132 | 132 |
133 ResetInstantTab(); | 133 ResetInstantTab(); |
134 } | 134 } |
135 | 135 |
136 void InstantController::InstantSupportDetermined( | 136 void InstantController::InstantSupportDetermined( |
137 const content::WebContents* contents, | 137 const content::WebContents* contents, |
138 bool supports_instant) { | 138 bool supports_instant) { |
139 DCHECK(IsContentsFrom(instant_tab(), contents)); | 139 DCHECK(IsContentsFrom(instant_tab(), contents)); |
140 | 140 |
141 if (!supports_instant) | 141 if (!supports_instant) |
142 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, | 142 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, |
143 instant_tab_.release()); | 143 instant_tab_.release()); |
144 | 144 |
145 content::NotificationService::current()->Notify( | 145 content::NotificationService::current()->Notify( |
146 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED, | 146 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED, |
147 content::Source<InstantController>(this), | 147 content::Source<InstantController>(this), |
148 content::NotificationService::NoDetails()); | 148 content::NotificationService::NoDetails()); |
149 } | 149 } |
150 | 150 |
151 void InstantController::InstantPageAboutToNavigateMainFrame( | 151 void InstantController::InstantTabAboutToNavigateMainFrame( |
152 const content::WebContents* contents, | 152 const content::WebContents* contents, |
153 const GURL& url) { | 153 const GURL& url) { |
154 DCHECK(IsContentsFrom(instant_tab(), contents)); | 154 DCHECK(IsContentsFrom(instant_tab(), contents)); |
155 | 155 |
156 // The Instant tab navigated. Send it the data it needs to display | 156 // The Instant tab navigated. Send it the data it needs to display |
157 // properly. | 157 // properly. |
158 UpdateInfoForInstantTab(); | 158 UpdateInfoForInstantTab(); |
159 } | 159 } |
160 | 160 |
161 void InstantController::ResetInstantTab() { | 161 void InstantController::ResetInstantTab() { |
(...skipping 16 matching lines...) Expand all Loading... |
178 if (instant_service) { | 178 if (instant_service) { |
179 instant_service->UpdateThemeInfo(); | 179 instant_service->UpdateThemeInfo(); |
180 instant_service->UpdateMostVisitedItemsInfo(); | 180 instant_service->UpdateMostVisitedItemsInfo(); |
181 } | 181 } |
182 } | 182 } |
183 } | 183 } |
184 | 184 |
185 InstantService* InstantController::GetInstantService() const { | 185 InstantService* InstantController::GetInstantService() const { |
186 return InstantServiceFactory::GetForProfile(profile()); | 186 return InstantServiceFactory::GetForProfile(profile()); |
187 } | 187 } |
OLD | NEW |