Chromium Code Reviews| 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 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 168 | 168 |
| 169 const TemplateURL* template_url = match.template_url; | 169 const TemplateURL* template_url = match.template_url; |
| 170 DCHECK(template_url); // ShouldUseInstant returns false if no turl. | 170 DCHECK(template_url); // ShouldUseInstant returns false if no turl. |
| 171 if (!loader_.get()) | 171 if (!loader_.get()) |
| 172 loader_.reset(new InstantLoader(this, template_url->id())); | 172 loader_.reset(new InstantLoader(this, template_url->id())); |
| 173 | 173 |
| 174 // In some rare cases (involving group policy), Instant can go from the field | 174 // In some rare cases (involving group policy), Instant can go from the field |
| 175 // trial to normal mode, with no intervening call to DestroyPreviewContents(). | 175 // trial to normal mode, with no intervening call to DestroyPreviewContents(). |
| 176 // This would leave the loader in a weird state, which would manifest if the | 176 // This would leave the loader in a weird state, which would manifest if the |
| 177 // user pressed <Enter> without calling Update(). TODO(sreeram): Handle it. | 177 // user pressed <Enter> without calling Update(). TODO(sreeram): Handle it. |
| 178 if (InstantFieldTrial::IsHiddenExperiment(tab_contents->profile())) { | 178 if (InstantFieldTrial::IsSilentExperiment(tab_contents->profile())) { |
| 179 // For the HIDDEN field trial we process |user_text| at commit time, which | 179 // For the SILENT field trial we process |user_text| at commit time, which |
| 180 // means we're never really out of date. | 180 // means we're never really out of date. |
| 181 is_out_of_date_ = false; | 181 is_out_of_date_ = false; |
| 182 loader_->MaybeLoadInstantURL(tab_contents, template_url); | 182 loader_->MaybeLoadInstantURL(tab_contents, template_url); |
| 183 return true; | 183 return true; |
| 184 } | 184 } |
| 185 | 185 |
| 186 // For the HIDDEN field trial, never send back suggestions to the omnibox. | |
|
sky
2011/10/24 15:03:31
This is a bit obscure. How about moving this after
sreeram
2011/10/24 17:14:50
Done.
| |
| 187 string16 ignore_suggested_text; | |
| 188 if (InstantFieldTrial::IsHiddenExperiment(tab_contents->profile())) | |
| 189 suggested_text = &ignore_suggested_text; | |
| 190 | |
| 186 UpdateLoader(template_url, match.destination_url, match.transition, user_text, | 191 UpdateLoader(template_url, match.destination_url, match.transition, user_text, |
| 187 verbatim, suggested_text); | 192 verbatim, suggested_text); |
| 188 | 193 |
| 189 content::NotificationService::current()->Notify( | 194 content::NotificationService::current()->Notify( |
| 190 chrome::NOTIFICATION_INSTANT_CONTROLLER_UPDATED, | 195 chrome::NOTIFICATION_INSTANT_CONTROLLER_UPDATED, |
| 191 content::Source<InstantController>(this), | 196 content::Source<InstantController>(this), |
| 192 content::NotificationService::NoDetails()); | 197 content::NotificationService::NoDetails()); |
| 193 return true; | 198 return true; |
| 194 } | 199 } |
| 195 | 200 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 229 return is_displayable_ && !loader_->IsNavigationPending() && | 234 return is_displayable_ && !loader_->IsNavigationPending() && |
| 230 !loader_->needs_reload(); | 235 !loader_->needs_reload(); |
| 231 } | 236 } |
| 232 | 237 |
| 233 bool InstantController::PrepareForCommit() { | 238 bool InstantController::PrepareForCommit() { |
| 234 // Basic checks to prevent accessing a dangling |tab_contents_| pointer. | 239 // Basic checks to prevent accessing a dangling |tab_contents_| pointer. |
| 235 // http://crbug.com/100521. | 240 // http://crbug.com/100521. |
| 236 if (is_out_of_date_ || !loader_.get()) | 241 if (is_out_of_date_ || !loader_.get()) |
| 237 return false; | 242 return false; |
| 238 | 243 |
| 239 // If we are not in the HIDDEN field trial, return the status of the preview. | 244 // If we are not in the HIDDEN or SILENT field trials, return the status of |
| 240 if (!InstantFieldTrial::IsHiddenExperiment(tab_contents_->profile())) | 245 // the preview. |
| 246 if (!InstantFieldTrial::IsHiddenExperiment(tab_contents_->profile()) && | |
| 247 !InstantFieldTrial::IsSilentExperiment(tab_contents_->profile())) { | |
| 241 return IsCurrent(); | 248 return IsCurrent(); |
| 249 } | |
| 242 | 250 |
| 243 TemplateURLService* model = TemplateURLServiceFactory::GetForProfile( | 251 TemplateURLService* model = TemplateURLServiceFactory::GetForProfile( |
| 244 tab_contents_->profile()); | 252 tab_contents_->profile()); |
| 245 if (!model) | 253 if (!model) |
| 246 return false; | 254 return false; |
| 247 | 255 |
| 248 const TemplateURL* template_url = model->GetDefaultSearchProvider(); | 256 const TemplateURL* template_url = model->GetDefaultSearchProvider(); |
| 249 if (!IsValidInstantTemplateURL(template_url) || | 257 if (!IsValidInstantTemplateURL(template_url) || |
| 250 loader_->template_url_id() != template_url->id() || | 258 loader_->template_url_id() != template_url->id() || |
| 251 loader_->IsNavigationPending() || | 259 loader_->IsNavigationPending() || |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 412 | 420 |
| 413 void InstantController::InstantStatusChanged(InstantLoader* loader) { | 421 void InstantController::InstantStatusChanged(InstantLoader* loader) { |
| 414 DCHECK(loader_.get()); | 422 DCHECK(loader_.get()); |
| 415 UpdateIsDisplayable(); | 423 UpdateIsDisplayable(); |
| 416 } | 424 } |
| 417 | 425 |
| 418 void InstantController::SetSuggestedTextFor( | 426 void InstantController::SetSuggestedTextFor( |
| 419 InstantLoader* loader, | 427 InstantLoader* loader, |
| 420 const string16& text, | 428 const string16& text, |
| 421 InstantCompleteBehavior behavior) { | 429 InstantCompleteBehavior behavior) { |
| 422 delegate_->SetSuggestedText(text, behavior); | 430 if (!is_out_of_date_ && |
| 431 !InstantFieldTrial::IsHiddenExperiment(tab_contents_->profile())) { | |
| 432 delegate_->SetSuggestedText(text, behavior); | |
| 433 } | |
| 423 } | 434 } |
| 424 | 435 |
| 425 gfx::Rect InstantController::GetInstantBounds() { | 436 gfx::Rect InstantController::GetInstantBounds() { |
| 426 return delegate_->GetInstantBounds(); | 437 return delegate_->GetInstantBounds(); |
| 427 } | 438 } |
| 428 | 439 |
| 429 bool InstantController::ShouldCommitInstantOnMouseUp() { | 440 bool InstantController::ShouldCommitInstantOnMouseUp() { |
| 430 return commit_on_mouse_up_; | 441 return commit_on_mouse_up_; |
| 431 } | 442 } |
| 432 | 443 |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 456 | 467 |
| 457 void InstantController::SwappedTabContents(InstantLoader* loader) { | 468 void InstantController::SwappedTabContents(InstantLoader* loader) { |
| 458 if (is_displayable_) | 469 if (is_displayable_) |
| 459 delegate_->ShowInstant(loader->preview_contents()); | 470 delegate_->ShowInstant(loader->preview_contents()); |
| 460 } | 471 } |
| 461 | 472 |
| 462 void InstantController::UpdateIsDisplayable() { | 473 void InstantController::UpdateIsDisplayable() { |
| 463 bool displayable = | 474 bool displayable = |
| 464 (!is_out_of_date_ && loader_.get() && loader_->ready() && | 475 (!is_out_of_date_ && loader_.get() && loader_->ready() && |
| 465 loader_->http_status_ok()); | 476 loader_->http_status_ok()); |
| 466 if (displayable == is_displayable_) | 477 if (displayable == is_displayable_ || |
| 478 (displayable && | |
| 479 InstantFieldTrial::IsHiddenExperiment(tab_contents_->profile()))) { | |
|
sky
2011/10/24 15:03:31
Make this part of setting displayable.
sreeram
2011/10/24 17:14:50
Done.
| |
| 467 return; | 480 return; |
| 481 } | |
| 468 | 482 |
| 469 is_displayable_ = displayable; | 483 is_displayable_ = displayable; |
| 470 if (!is_displayable_) { | 484 if (!is_displayable_) { |
| 471 delegate_->HideInstant(); | 485 delegate_->HideInstant(); |
| 472 } else { | 486 } else { |
| 473 delegate_->ShowInstant(loader_->preview_contents()); | 487 delegate_->ShowInstant(loader_->preview_contents()); |
| 474 content::NotificationService::current()->Notify( | 488 content::NotificationService::current()->Notify( |
| 475 chrome::NOTIFICATION_INSTANT_CONTROLLER_SHOWN, | 489 chrome::NOTIFICATION_INSTANT_CONTROLLER_SHOWN, |
| 476 content::Source<InstantController>(this), | 490 content::Source<InstantController>(this), |
| 477 content::NotificationService::NoDetails()); | 491 content::NotificationService::NoDetails()); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 537 if (destroy_factory_.empty()) { | 551 if (destroy_factory_.empty()) { |
| 538 MessageLoop::current()->PostTask( | 552 MessageLoop::current()->PostTask( |
| 539 FROM_HERE, destroy_factory_.NewRunnableMethod( | 553 FROM_HERE, destroy_factory_.NewRunnableMethod( |
| 540 &InstantController::DestroyLoaders)); | 554 &InstantController::DestroyLoaders)); |
| 541 } | 555 } |
| 542 } | 556 } |
| 543 | 557 |
| 544 void InstantController::DestroyLoaders() { | 558 void InstantController::DestroyLoaders() { |
| 545 loaders_to_destroy_.reset(); | 559 loaders_to_destroy_.reset(); |
| 546 } | 560 } |
| OLD | NEW |