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

Side by Side Diff: chrome/browser/history/scored_history_match.cc

Issue 10532149: Omnibox: Create HistoryQuickProvider new scoring field trial. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Ilya's comments. Created 8 years, 6 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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/history/scored_history_match.h" 5 #include "chrome/browser/history/scored_history_match.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <functional> 8 #include <functional>
9 #include <iterator> 9 #include <iterator>
10 #include <numeric> 10 #include <numeric>
11 #include <set> 11 #include <set>
12 12
13 #include <math.h> 13 #include <math.h>
14 14
15 #include "base/command_line.h" 15 #include "base/command_line.h"
16 #include "base/i18n/case_conversion.h" 16 #include "base/i18n/case_conversion.h"
17 #include "base/metrics/histogram.h"
17 #include "base/string_util.h" 18 #include "base/string_util.h"
18 #include "base/utf_string_conversions.h" 19 #include "base/utf_string_conversions.h"
20 #include "chrome/browser/autocomplete/autocomplete_field_trial.h"
19 #include "chrome/browser/autocomplete/url_prefix.h" 21 #include "chrome/browser/autocomplete/url_prefix.h"
20 #include "chrome/common/chrome_switches.h" 22 #include "chrome/common/chrome_switches.h"
21 #include "content/public/browser/browser_thread.h" 23 #include "content/public/browser/browser_thread.h"
22 24
23 namespace history { 25 namespace history {
24 26
25 // The maximum score any candidate result can achieve. 27 // The maximum score any candidate result can achieve.
26 const int kMaxTotalScore = 1425; 28 const int kMaxTotalScore = 1425;
27 29
28 // Score ranges used to get a 'base' score for each of the scoring factors 30 // Score ranges used to get a 'base' score for each of the scoring factors
29 // (such as recency of last visit, times visited, times the URL was typed, 31 // (such as recency of last visit, times visited, times the URL was typed,
30 // and the quality of the string match). There is a matching value range for 32 // and the quality of the string match). There is a matching value range for
31 // each of these scores for each factor. Note that the top score is greater 33 // each of these scores for each factor. Note that the top score is greater
32 // than |kMaxTotalScore|. The score for each candidate will be capped in the 34 // than |kMaxTotalScore|. The score for each candidate will be capped in the
33 // final calculation. 35 // final calculation.
34 const int kScoreRank[] = { 1450, 1200, 900, 400 }; 36 const int kScoreRank[] = { 1450, 1200, 900, 400 };
35 37
36 // ScoredHistoryMatch ---------------------------------------------------------- 38 // ScoredHistoryMatch ----------------------------------------------------------
37 39
38 bool ScoredHistoryMatch::initialized = false; 40 bool ScoredHistoryMatch::initialized = false;
39 bool ScoredHistoryMatch::use_new_scoring = false; 41 bool ScoredHistoryMatch::use_new_scoring = false;
40 42
41 ScoredHistoryMatch::ScoredHistoryMatch() 43 ScoredHistoryMatch::ScoredHistoryMatch()
42 : raw_score(0), 44 : raw_score(0),
43 can_inline(false) { 45 can_inline(false) {
44 if (!initialized) { 46 if (!initialized) {
45 const std::string switch_value = CommandLine::ForCurrentProcess()-> 47 InitializeNewScoringField();
46 GetSwitchValueASCII(switches::kOmniboxHistoryQuickProviderNewScoring);
47 if (switch_value == switches::kOmniboxHistoryQuickProviderNewScoringEnabled)
48 use_new_scoring = true;
49 initialized = true; 48 initialized = true;
50 } 49 }
51 } 50 }
52 51
53 ScoredHistoryMatch::ScoredHistoryMatch(const URLRow& row, 52 ScoredHistoryMatch::ScoredHistoryMatch(const URLRow& row,
54 const string16& lower_string, 53 const string16& lower_string,
55 const String16Vector& terms, 54 const String16Vector& terms,
56 const RowWordStarts& word_starts, 55 const RowWordStarts& word_starts,
57 const base::Time now) 56 const base::Time now)
58 : HistoryMatch(row, 0, false, false), 57 : HistoryMatch(row, 0, false, false),
59 raw_score(0), 58 raw_score(0),
60 can_inline(false) { 59 can_inline(false) {
61 if (!initialized) { 60 if (!initialized) {
62 const std::string switch_value = CommandLine::ForCurrentProcess()-> 61 InitializeNewScoringField();
63 GetSwitchValueASCII(switches::kOmniboxHistoryQuickProviderNewScoring);
64 if (switch_value == switches::kOmniboxHistoryQuickProviderNewScoringEnabled)
65 use_new_scoring = true;
66 initialized = true; 62 initialized = true;
67 } 63 }
68 64
69 GURL gurl = row.url(); 65 GURL gurl = row.url();
70 if (!gurl.is_valid()) 66 if (!gurl.is_valid())
71 return; 67 return;
72 68
73 // Figure out where each search term appears in the URL and/or page title 69 // Figure out where each search term appears in the URL and/or page title
74 // so that we can score as well as provide autocomplete highlighting. 70 // so that we can score as well as provide autocomplete highlighting.
75 string16 url = base::i18n::ToLower(UTF8ToUTF16(gurl.spec())); 71 string16 url = base::i18n::ToLower(UTF8ToUTF16(gurl.spec()));
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 } 465 }
470 466
471 // static 467 // static
472 float ScoredHistoryMatch::GetPopularityScore(int typed_count, 468 float ScoredHistoryMatch::GetPopularityScore(int typed_count,
473 int visit_count) { 469 int visit_count) {
474 // The max()s are to guard against database corruption. 470 // The max()s are to guard against database corruption.
475 return (std::max(typed_count, 0) * 5.0 + std::max(visit_count, 0) * 3.0) / 471 return (std::max(typed_count, 0) * 5.0 + std::max(visit_count, 0) * 3.0) /
476 (5.0 + 3.0); 472 (5.0 + 3.0);
477 } 473 }
478 474
475 void ScoredHistoryMatch::InitializeNewScoringField() {
476 enum NewScoringOption {
477 OLD_SCORING = 0,
478 NEW_SCORING = 1,
479 NEW_SCORING_AUTO_BUT_NOT_IN_FIELD_TRIAL = 2,
480 NEW_SCORING_FIELD_TRIAL_DEFAULT_GROUP = 3,
481 NEW_SCORING_FIELD_TRIAL_EXPERIMENT_GROUP = 4,
482 NUM_OPTIONS = 5
483 };
484 // should always be overwritten
485 NewScoringOption new_scoring_option = NUM_OPTIONS;
486
487 const std::string switch_value = CommandLine::ForCurrentProcess()->
488 GetSwitchValueASCII(switches::kOmniboxHistoryQuickProviderNewScoring);
489 if (switch_value == switches::kOmniboxHistoryQuickProviderNewScoringEnabled) {
490 new_scoring_option = NEW_SCORING;
491 use_new_scoring = true;
492 } else if (switch_value ==
493 switches::kOmniboxHistoryQuickProviderNewScoringDisabled) {
494 new_scoring_option = OLD_SCORING;
495 use_new_scoring = false;
496 } else {
497 // We'll assume any other flag means automatic.
498 // Automatic means eligible for the field trial.
499
500 // For the field trial stuff to work correctly, we must be running
501 // on the same thread as the thread that created the field trial,
502 // which happens via a call to AutocompleteFieldTrial::Active in
503 // chrome_browser_main.cc on the main thread. Let's check this to
504 // be sure. We check "if we've heard of the UI thread then we'd better
505 // be on it." The first part is necessary so unit tests pass. (Many
506 // unit tests don't set up the threading naming system; hence
507 // CurrentlyOn(UI thread) will fail.)
508 DCHECK(!content::BrowserThread::IsWellKnownThread(
509 content::BrowserThread::UI) ||
510 content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
511 if (AutocompleteFieldTrial::InHQPNewScoringFieldTrial()) {
512 if (AutocompleteFieldTrial::
513 InHQPNewScoringFieldTrialExperimentGroup()) {
514 new_scoring_option = NEW_SCORING_FIELD_TRIAL_EXPERIMENT_GROUP;
515 use_new_scoring = true;
516 } else {
517 new_scoring_option = NEW_SCORING_FIELD_TRIAL_DEFAULT_GROUP;
518 use_new_scoring = false;
519 }
520 } else {
521 new_scoring_option = NEW_SCORING_AUTO_BUT_NOT_IN_FIELD_TRIAL;
522 use_new_scoring = false;
523 }
524 }
525
526 // Add a beacon to the logs that'll allow us to identify later what
527 // new scoring state a user is in. Do this by incrementing a bucket in
528 // a histogram, where the bucket represents the user's new scoring state.
529 UMA_HISTOGRAM_ENUMERATION(
530 "Omnibox.HistoryQuickProviderNewScoringFieldTrialBeacon",
531 new_scoring_option, NUM_OPTIONS);
532
533 }
534
479 } // namespace history 535 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698