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

Side by Side Diff: chrome/browser/instant/instant_controller.cc

Issue 8370020: Add a new field trial for Instant. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed @sky's comments Created 9 years, 2 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 (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
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 UpdateLoader(template_url, match.destination_url, match.transition, user_text, 186 UpdateLoader(template_url, match.destination_url, match.transition, user_text,
187 verbatim, suggested_text); 187 verbatim, suggested_text);
188 188
189 content::NotificationService::current()->Notify( 189 content::NotificationService::current()->Notify(
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 return is_displayable_ && !loader_->IsNavigationPending() && 229 return is_displayable_ && !loader_->IsNavigationPending() &&
230 !loader_->needs_reload(); 230 !loader_->needs_reload();
231 } 231 }
232 232
233 bool InstantController::PrepareForCommit() { 233 bool InstantController::PrepareForCommit() {
234 // Basic checks to prevent accessing a dangling |tab_contents_| pointer. 234 // Basic checks to prevent accessing a dangling |tab_contents_| pointer.
235 // http://crbug.com/100521. 235 // http://crbug.com/100521.
236 if (is_out_of_date_ || !loader_.get()) 236 if (is_out_of_date_ || !loader_.get())
237 return false; 237 return false;
238 238
239 // If we are not in the HIDDEN field trial, return the status of the preview. 239 // If we are not in the HIDDEN or SILENT field trials, return the status of
240 if (!InstantFieldTrial::IsHiddenExperiment(tab_contents_->profile())) 240 // the preview.
241 if (!InstantFieldTrial::IsHiddenExperiment(tab_contents_->profile()) &&
242 !InstantFieldTrial::IsSilentExperiment(tab_contents_->profile())) {
241 return IsCurrent(); 243 return IsCurrent();
244 }
242 245
243 TemplateURLService* model = TemplateURLServiceFactory::GetForProfile( 246 TemplateURLService* model = TemplateURLServiceFactory::GetForProfile(
244 tab_contents_->profile()); 247 tab_contents_->profile());
245 if (!model) 248 if (!model)
246 return false; 249 return false;
247 250
248 const TemplateURL* template_url = model->GetDefaultSearchProvider(); 251 const TemplateURL* template_url = model->GetDefaultSearchProvider();
249 if (!IsValidInstantTemplateURL(template_url) || 252 if (!IsValidInstantTemplateURL(template_url) ||
250 loader_->template_url_id() != template_url->id() || 253 loader_->template_url_id() != template_url->id() ||
251 loader_->IsNavigationPending() || 254 loader_->IsNavigationPending() ||
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 415
413 void InstantController::InstantStatusChanged(InstantLoader* loader) { 416 void InstantController::InstantStatusChanged(InstantLoader* loader) {
414 DCHECK(loader_.get()); 417 DCHECK(loader_.get());
415 UpdateIsDisplayable(); 418 UpdateIsDisplayable();
416 } 419 }
417 420
418 void InstantController::SetSuggestedTextFor( 421 void InstantController::SetSuggestedTextFor(
419 InstantLoader* loader, 422 InstantLoader* loader,
420 const string16& text, 423 const string16& text,
421 InstantCompleteBehavior behavior) { 424 InstantCompleteBehavior behavior) {
422 delegate_->SetSuggestedText(text, behavior); 425 if (!is_out_of_date_ &&
426 !InstantFieldTrial::IsHiddenExperiment(tab_contents_->profile())) {
427 delegate_->SetSuggestedText(text, behavior);
428 }
423 } 429 }
424 430
425 gfx::Rect InstantController::GetInstantBounds() { 431 gfx::Rect InstantController::GetInstantBounds() {
426 return delegate_->GetInstantBounds(); 432 return delegate_->GetInstantBounds();
427 } 433 }
428 434
429 bool InstantController::ShouldCommitInstantOnMouseUp() { 435 bool InstantController::ShouldCommitInstantOnMouseUp() {
430 return commit_on_mouse_up_; 436 return commit_on_mouse_up_;
431 } 437 }
432 438
(...skipping 20 matching lines...) Expand all
453 // Don't attempt to use instant for this search engine again. 459 // Don't attempt to use instant for this search engine again.
454 BlacklistFromInstant(); 460 BlacklistFromInstant();
455 } 461 }
456 462
457 void InstantController::SwappedTabContents(InstantLoader* loader) { 463 void InstantController::SwappedTabContents(InstantLoader* loader) {
458 if (is_displayable_) 464 if (is_displayable_)
459 delegate_->ShowInstant(loader->preview_contents()); 465 delegate_->ShowInstant(loader->preview_contents());
460 } 466 }
461 467
462 void InstantController::UpdateIsDisplayable() { 468 void InstantController::UpdateIsDisplayable() {
469 if (!is_out_of_date_ &&
470 InstantFieldTrial::IsHiddenExperiment(tab_contents_->profile())) {
471 return;
472 }
473
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_)
467 return; 478 return;
468 479
469 is_displayable_ = displayable; 480 is_displayable_ = displayable;
470 if (!is_displayable_) { 481 if (!is_displayable_) {
471 delegate_->HideInstant(); 482 delegate_->HideInstant();
472 } else { 483 } else {
473 delegate_->ShowInstant(loader_->preview_contents()); 484 delegate_->ShowInstant(loader_->preview_contents());
474 content::NotificationService::current()->Notify( 485 content::NotificationService::current()->Notify(
475 chrome::NOTIFICATION_INSTANT_CONTROLLER_SHOWN, 486 chrome::NOTIFICATION_INSTANT_CONTROLLER_SHOWN,
476 content::Source<InstantController>(this), 487 content::Source<InstantController>(this),
477 content::NotificationService::NoDetails()); 488 content::NotificationService::NoDetails());
478 } 489 }
479 } 490 }
480 491
481 void InstantController::UpdateLoader(const TemplateURL* template_url, 492 void InstantController::UpdateLoader(const TemplateURL* template_url,
482 const GURL& url, 493 const GURL& url,
483 content::PageTransition transition_type, 494 content::PageTransition transition_type,
484 const string16& user_text, 495 const string16& user_text,
485 bool verbatim, 496 bool verbatim,
486 string16* suggested_text) { 497 string16* suggested_text) {
487 is_out_of_date_ = false; 498 is_out_of_date_ = false;
488 loader_->SetOmniboxBounds(omnibox_bounds_); 499 loader_->SetOmniboxBounds(omnibox_bounds_);
489 loader_->Update(tab_contents_, template_url, url, transition_type, user_text, 500 loader_->Update(tab_contents_, template_url, url, transition_type, user_text,
490 verbatim, suggested_text); 501 verbatim, suggested_text);
491 UpdateIsDisplayable(); 502 UpdateIsDisplayable();
503 // For the HIDDEN field trial, don't send back suggestions to the omnibox.
504 if (InstantFieldTrial::IsHiddenExperiment(tab_contents_->profile()))
505 suggested_text->clear();
492 } 506 }
493 507
494 bool InstantController::ShouldUseInstant(const AutocompleteMatch& match) { 508 bool InstantController::ShouldUseInstant(const AutocompleteMatch& match) {
495 TemplateURLService* model = TemplateURLServiceFactory::GetForProfile( 509 TemplateURLService* model = TemplateURLServiceFactory::GetForProfile(
496 tab_contents_->profile()); 510 tab_contents_->profile());
497 if (!model) 511 if (!model)
498 return false; 512 return false;
499 513
500 const TemplateURL* default_t_url = model->GetDefaultSearchProvider(); 514 const TemplateURL* default_t_url = model->GetDefaultSearchProvider();
501 const TemplateURL* match_t_url = match.template_url; 515 const TemplateURL* match_t_url = match.template_url;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 }
OLDNEW
« no previous file with comments | « chrome/browser/instant/instant_controller.h ('k') | chrome/browser/instant/instant_field_trial.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698