| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/instant/instant_controller.h" | 5 #include "chrome/browser/instant/instant_controller.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/rand_util.h" | 10 #include "base/rand_util.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 InstantController::InstantController(Profile* profile, | 38 InstantController::InstantController(Profile* profile, |
| 39 InstantDelegate* delegate) | 39 InstantDelegate* delegate) |
| 40 : delegate_(delegate), | 40 : delegate_(delegate), |
| 41 tab_contents_(NULL), | 41 tab_contents_(NULL), |
| 42 is_displayable_(false), | 42 is_displayable_(false), |
| 43 is_out_of_date_(true), | 43 is_out_of_date_(true), |
| 44 commit_on_mouse_up_(false), | 44 commit_on_mouse_up_(false), |
| 45 last_transition_type_(content::PAGE_TRANSITION_LINK), | 45 last_transition_type_(content::PAGE_TRANSITION_LINK), |
| 46 ALLOW_THIS_IN_INITIALIZER_LIST(destroy_factory_(this)) { | 46 ALLOW_THIS_IN_INITIALIZER_LIST(destroy_factory_(this)) { |
| 47 PrefService* service = profile->GetPrefs(); | 47 PrefService* service = profile->GetPrefs(); |
| 48 if (service && !InstantFieldTrial::IsExperimentGroup(profile)) { | 48 if (service && !InstantFieldTrial::IsInstantExperiment(profile)) { |
| 49 // kInstantEnabledOnce was added after instant, set it now to make sure it | 49 // kInstantEnabledOnce was added after instant, set it now to make sure it |
| 50 // is correctly set. | 50 // is correctly set. |
| 51 service->SetBoolean(prefs::kInstantEnabledOnce, true); | 51 service->SetBoolean(prefs::kInstantEnabledOnce, true); |
| 52 } | 52 } |
| 53 } | 53 } |
| 54 | 54 |
| 55 InstantController::~InstantController() { | 55 InstantController::~InstantController() { |
| 56 } | 56 } |
| 57 | 57 |
| 58 // static | 58 // static |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 UMA_HISTOGRAM_CUSTOM_COUNTS("Instant.EnabledTime.Predictive", | 90 UMA_HISTOGRAM_CUSTOM_COUNTS("Instant.EnabledTime.Predictive", |
| 91 delta.InHours(), 1, 30 * 24, 50); | 91 delta.InHours(), 1, 30 * 24, 50); |
| 92 } | 92 } |
| 93 } | 93 } |
| 94 } | 94 } |
| 95 | 95 |
| 96 // static | 96 // static |
| 97 bool InstantController::IsEnabled(Profile* profile) { | 97 bool InstantController::IsEnabled(Profile* profile) { |
| 98 PrefService* prefs = profile->GetPrefs(); | 98 PrefService* prefs = profile->GetPrefs(); |
| 99 return prefs->GetBoolean(prefs::kInstantEnabled) || | 99 return prefs->GetBoolean(prefs::kInstantEnabled) || |
| 100 InstantFieldTrial::IsExperimentGroup(profile); | 100 InstantFieldTrial::IsInstantExperiment(profile); |
| 101 } | 101 } |
| 102 | 102 |
| 103 // static | 103 // static |
| 104 void InstantController::Enable(Profile* profile) { | 104 void InstantController::Enable(Profile* profile) { |
| 105 PromoCounter* promo_counter = profile->GetInstantPromoCounter(); | 105 PromoCounter* promo_counter = profile->GetInstantPromoCounter(); |
| 106 if (promo_counter) | 106 if (promo_counter) |
| 107 promo_counter->Hide(); | 107 promo_counter->Hide(); |
| 108 | 108 |
| 109 PrefService* service = profile->GetPrefs(); | 109 PrefService* service = profile->GetPrefs(); |
| 110 if (!service) | 110 if (!service) |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 return true; | 193 return true; |
| 194 } | 194 } |
| 195 | 195 |
| 196 void InstantController::SetOmniboxBounds(const gfx::Rect& bounds) { | 196 void InstantController::SetOmniboxBounds(const gfx::Rect& bounds) { |
| 197 if (omnibox_bounds_ == bounds) | 197 if (omnibox_bounds_ == bounds) |
| 198 return; | 198 return; |
| 199 | 199 |
| 200 // Always track the omnibox bounds. That way if Update is later invoked the | 200 // Always track the omnibox bounds. That way if Update is later invoked the |
| 201 // bounds are in sync. | 201 // bounds are in sync. |
| 202 omnibox_bounds_ = bounds; | 202 omnibox_bounds_ = bounds; |
| 203 if (loader_.get()) | 203 |
| 204 if (loader_.get() && !is_out_of_date_ && |
| 205 !InstantFieldTrial::IsHiddenExperiment(tab_contents_->profile())) { |
| 204 loader_->SetOmniboxBounds(bounds); | 206 loader_->SetOmniboxBounds(bounds); |
| 207 } |
| 205 } | 208 } |
| 206 | 209 |
| 207 void InstantController::DestroyPreviewContents() { | 210 void InstantController::DestroyPreviewContents() { |
| 208 if (!loader_.get()) { | 211 if (!loader_.get()) { |
| 209 // We're not showing anything, nothing to do. | 212 // We're not showing anything, nothing to do. |
| 210 return; | 213 return; |
| 211 } | 214 } |
| 212 | 215 |
| 213 delegate_->HideInstant(); | 216 delegate_->HideInstant(); |
| 214 delete ReleasePreviewContents(INSTANT_COMMIT_DESTROY); | 217 delete ReleasePreviewContents(INSTANT_COMMIT_DESTROY); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 231 } | 234 } |
| 232 | 235 |
| 233 bool InstantController::PrepareForCommit() { | 236 bool InstantController::PrepareForCommit() { |
| 234 // Basic checks to prevent accessing a dangling |tab_contents_| pointer. | 237 // Basic checks to prevent accessing a dangling |tab_contents_| pointer. |
| 235 // http://crbug.com/100521. | 238 // http://crbug.com/100521. |
| 236 if (is_out_of_date_ || !loader_.get()) | 239 if (is_out_of_date_ || !loader_.get()) |
| 237 return false; | 240 return false; |
| 238 | 241 |
| 239 // If we are not in the HIDDEN or SILENT field trials, return the status of | 242 // If we are not in the HIDDEN or SILENT field trials, return the status of |
| 240 // the preview. | 243 // the preview. |
| 241 if (!InstantFieldTrial::IsHiddenExperiment(tab_contents_->profile()) && | 244 if (!InstantFieldTrial::IsHiddenExperiment(tab_contents_->profile())) |
| 242 !InstantFieldTrial::IsSilentExperiment(tab_contents_->profile())) { | |
| 243 return IsCurrent(); | 245 return IsCurrent(); |
| 244 } | |
| 245 | 246 |
| 246 TemplateURLService* model = TemplateURLServiceFactory::GetForProfile( | 247 TemplateURLService* model = TemplateURLServiceFactory::GetForProfile( |
| 247 tab_contents_->profile()); | 248 tab_contents_->profile()); |
| 248 if (!model) | 249 if (!model) |
| 249 return false; | 250 return false; |
| 250 | 251 |
| 251 const TemplateURL* template_url = model->GetDefaultSearchProvider(); | 252 const TemplateURL* template_url = model->GetDefaultSearchProvider(); |
| 252 if (!IsValidInstantTemplateURL(template_url) || | 253 if (!IsValidInstantTemplateURL(template_url) || |
| 253 loader_->template_url_id() != template_url->id() || | 254 loader_->template_url_id() != template_url->id() || |
| 254 loader_->IsNavigationPending() || | 255 loader_->IsNavigationPending() || |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 } | 364 } |
| 364 | 365 |
| 365 DestroyPreviewContents(); | 366 DestroyPreviewContents(); |
| 366 } | 367 } |
| 367 #endif | 368 #endif |
| 368 | 369 |
| 369 void InstantController::OnAutocompleteGotFocus( | 370 void InstantController::OnAutocompleteGotFocus( |
| 370 TabContentsWrapper* tab_contents) { | 371 TabContentsWrapper* tab_contents) { |
| 371 CommandLine* cl = CommandLine::ForCurrentProcess(); | 372 CommandLine* cl = CommandLine::ForCurrentProcess(); |
| 372 if (!cl->HasSwitch(switches::kPreloadInstantSearch) && | 373 if (!cl->HasSwitch(switches::kPreloadInstantSearch) && |
| 373 !InstantFieldTrial::IsExperimentGroup(tab_contents->profile())) { | 374 !InstantFieldTrial::IsInstantExperiment(tab_contents->profile())) { |
| 374 return; | 375 return; |
| 375 } | 376 } |
| 376 | 377 |
| 377 TemplateURLService* model = TemplateURLServiceFactory::GetForProfile( | 378 TemplateURLService* model = TemplateURLServiceFactory::GetForProfile( |
| 378 tab_contents->profile()); | 379 tab_contents->profile()); |
| 379 if (!model) | 380 if (!model) |
| 380 return; | 381 return; |
| 381 | 382 |
| 382 const TemplateURL* template_url = model->GetDefaultSearchProvider(); | 383 const TemplateURL* template_url = model->GetDefaultSearchProvider(); |
| 383 if (!IsValidInstantTemplateURL(template_url)) | 384 if (!IsValidInstantTemplateURL(template_url)) |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 489 } | 490 } |
| 490 } | 491 } |
| 491 | 492 |
| 492 void InstantController::UpdateLoader(const TemplateURL* template_url, | 493 void InstantController::UpdateLoader(const TemplateURL* template_url, |
| 493 const GURL& url, | 494 const GURL& url, |
| 494 content::PageTransition transition_type, | 495 content::PageTransition transition_type, |
| 495 const string16& user_text, | 496 const string16& user_text, |
| 496 bool verbatim, | 497 bool verbatim, |
| 497 string16* suggested_text) { | 498 string16* suggested_text) { |
| 498 is_out_of_date_ = false; | 499 is_out_of_date_ = false; |
| 499 loader_->SetOmniboxBounds(omnibox_bounds_); | 500 bool hidden = InstantFieldTrial::IsHiddenExperiment(tab_contents_->profile()); |
| 501 if (!hidden) |
| 502 loader_->SetOmniboxBounds(omnibox_bounds_); |
| 500 loader_->Update(tab_contents_, template_url, url, transition_type, user_text, | 503 loader_->Update(tab_contents_, template_url, url, transition_type, user_text, |
| 501 verbatim, suggested_text); | 504 verbatim, suggested_text); |
| 502 UpdateIsDisplayable(); | 505 UpdateIsDisplayable(); |
| 503 // For the HIDDEN field trial, don't send back suggestions to the omnibox. | 506 // For the HIDDEN and SILENT field trials, don't send back suggestions. |
| 504 if (InstantFieldTrial::IsHiddenExperiment(tab_contents_->profile())) | 507 if (hidden) |
| 505 suggested_text->clear(); | 508 suggested_text->clear(); |
| 506 } | 509 } |
| 507 | 510 |
| 508 bool InstantController::ShouldUseInstant(const AutocompleteMatch& match) { | 511 bool InstantController::ShouldUseInstant(const AutocompleteMatch& match) { |
| 509 TemplateURLService* model = TemplateURLServiceFactory::GetForProfile( | 512 TemplateURLService* model = TemplateURLServiceFactory::GetForProfile( |
| 510 tab_contents_->profile()); | 513 tab_contents_->profile()); |
| 511 if (!model) | 514 if (!model) |
| 512 return false; | 515 return false; |
| 513 | 516 |
| 514 const TemplateURL* default_t_url = model->GetDefaultSearchProvider(); | 517 const TemplateURL* default_t_url = model->GetDefaultSearchProvider(); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 551 if (destroy_factory_.empty()) { | 554 if (destroy_factory_.empty()) { |
| 552 MessageLoop::current()->PostTask( | 555 MessageLoop::current()->PostTask( |
| 553 FROM_HERE, destroy_factory_.NewRunnableMethod( | 556 FROM_HERE, destroy_factory_.NewRunnableMethod( |
| 554 &InstantController::DestroyLoaders)); | 557 &InstantController::DestroyLoaders)); |
| 555 } | 558 } |
| 556 } | 559 } |
| 557 | 560 |
| 558 void InstantController::DestroyLoaders() { | 561 void InstantController::DestroyLoaders() { |
| 559 loaders_to_destroy_.reset(); | 562 loaders_to_destroy_.reset(); |
| 560 } | 563 } |
| OLD | NEW |