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

Side by Side Diff: components/omnibox/browser/autocomplete_classifier.cc

Issue 2721993002: Omnibox - Make Clipboard Provider Enabled via an Experimental Feature (Closed)
Patch Set: fix ios Created 3 years, 9 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
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 "components/omnibox/browser/autocomplete_classifier.h" 5 #include "components/omnibox/browser/autocomplete_classifier.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/auto_reset.h" 9 #include "base/auto_reset.h"
10 #include "base/feature_list.h"
10 #include "build/build_config.h" 11 #include "build/build_config.h"
11 #include "components/metrics/proto/omnibox_event.pb.h" 12 #include "components/metrics/proto/omnibox_event.pb.h"
12 #include "components/omnibox/browser/autocomplete_controller.h" 13 #include "components/omnibox/browser/autocomplete_controller.h"
13 #include "components/omnibox/browser/autocomplete_input.h" 14 #include "components/omnibox/browser/autocomplete_input.h"
14 #include "components/omnibox/browser/autocomplete_match.h" 15 #include "components/omnibox/browser/autocomplete_match.h"
15 #include "components/omnibox/browser/autocomplete_provider.h" 16 #include "components/omnibox/browser/autocomplete_provider.h"
17 #include "components/omnibox/browser/omnibox_field_trial.h"
16 #include "url/gurl.h" 18 #include "url/gurl.h"
17 19
18 // static
19 const int AutocompleteClassifier::kDefaultOmniboxProviders =
20 #if defined(OS_ANDROID) || defined(OS_IOS)
21 // The Physical Web currently is only implemented on mobile devices.
22 AutocompleteProvider::TYPE_PHYSICAL_WEB |
23 #else
24 // Custom search engines cannot be used on mobile.
25 AutocompleteProvider::TYPE_KEYWORD |
26 #endif
27 #if !defined(OS_IOS)
28 // "Builtin", "Shortcuts" and "Zero Suggest" are not supported on iOS.
29 AutocompleteProvider::TYPE_BUILTIN |
30 AutocompleteProvider::TYPE_SHORTCUTS |
31 AutocompleteProvider::TYPE_ZERO_SUGGEST |
32 #else
33 // "URL from clipboard" can only be used on iOS.
34 AutocompleteProvider::TYPE_CLIPBOARD_URL |
35 #endif
36 AutocompleteProvider::TYPE_BOOKMARK |
37 AutocompleteProvider::TYPE_HISTORY_QUICK |
38 AutocompleteProvider::TYPE_HISTORY_URL |
39 AutocompleteProvider::TYPE_SEARCH;
40
41 AutocompleteClassifier::AutocompleteClassifier( 20 AutocompleteClassifier::AutocompleteClassifier(
42 std::unique_ptr<AutocompleteController> controller, 21 std::unique_ptr<AutocompleteController> controller,
43 std::unique_ptr<AutocompleteSchemeClassifier> scheme_classifier) 22 std::unique_ptr<AutocompleteSchemeClassifier> scheme_classifier)
44 : controller_(std::move(controller)), 23 : controller_(std::move(controller)),
45 scheme_classifier_(std::move(scheme_classifier)), 24 scheme_classifier_(std::move(scheme_classifier)),
46 inside_classify_(false) {} 25 inside_classify_(false) {}
47 26
48 AutocompleteClassifier::~AutocompleteClassifier() { 27 AutocompleteClassifier::~AutocompleteClassifier() {
49 // We should only reach here after Shutdown() has been called. 28 // We should only reach here after Shutdown() has been called.
50 DCHECK(!controller_.get()); 29 DCHECK(!controller_.get());
51 } 30 }
52 31
53 void AutocompleteClassifier::Shutdown() { 32 void AutocompleteClassifier::Shutdown() {
54 controller_.reset(); 33 controller_.reset();
55 } 34 }
56 35
36 // static
37 int AutocompleteClassifier::DefaultOmniboxProviders() {
38 return
39 #if defined(OS_ANDROID) || defined(OS_IOS)
40 // The Physical Web currently is only implemented on mobile devices.
41 AutocompleteProvider::TYPE_PHYSICAL_WEB |
42 #else
43 // Custom search engines cannot be used on mobile.
44 AutocompleteProvider::TYPE_KEYWORD |
45 #endif
46 #if !defined(OS_IOS)
47 // "Builtin", "Shortcuts" and "Zero Suggest" are not supported on iOS.
48 AutocompleteProvider::TYPE_BUILTIN |
49 AutocompleteProvider::TYPE_SHORTCUTS |
50 AutocompleteProvider::TYPE_ZERO_SUGGEST |
51 #endif
52 (base::FeatureList::IsEnabled(omnibox::kEnableClipboardProvider)
Justin Donnelly 2017/03/01 14:51:36 Shouldn't this still be default enabled on iOS?
Mark P 2017/03/01 18:20:31 Yes, it is. See components/omnibox/browser/omnibo
53 ? AutocompleteProvider::TYPE_CLIPBOARD_URL
54 : 0) |
55 AutocompleteProvider::TYPE_BOOKMARK |
56 AutocompleteProvider::TYPE_HISTORY_QUICK |
57 AutocompleteProvider::TYPE_HISTORY_URL |
58 AutocompleteProvider::TYPE_SEARCH;
59 }
60
57 void AutocompleteClassifier::Classify( 61 void AutocompleteClassifier::Classify(
58 const base::string16& text, 62 const base::string16& text,
59 bool prefer_keyword, 63 bool prefer_keyword,
60 bool allow_exact_keyword_match, 64 bool allow_exact_keyword_match,
61 metrics::OmniboxEventProto::PageClassification page_classification, 65 metrics::OmniboxEventProto::PageClassification page_classification,
62 AutocompleteMatch* match, 66 AutocompleteMatch* match,
63 GURL* alternate_nav_url) { 67 GURL* alternate_nav_url) {
64 DCHECK(!inside_classify_); 68 DCHECK(!inside_classify_);
65 base::AutoReset<bool> reset(&inside_classify_, true); 69 base::AutoReset<bool> reset(&inside_classify_, true);
66 controller_->Start(AutocompleteInput( 70 controller_->Start(AutocompleteInput(
67 text, base::string16::npos, std::string(), GURL(), page_classification, 71 text, base::string16::npos, std::string(), GURL(), page_classification,
68 true, prefer_keyword, allow_exact_keyword_match, false, false, 72 true, prefer_keyword, allow_exact_keyword_match, false, false,
69 *scheme_classifier_)); 73 *scheme_classifier_));
70 DCHECK(controller_->done()); 74 DCHECK(controller_->done());
71 const AutocompleteResult& result = controller_->result(); 75 const AutocompleteResult& result = controller_->result();
72 if (result.empty()) { 76 if (result.empty()) {
73 if (alternate_nav_url) 77 if (alternate_nav_url)
74 *alternate_nav_url = GURL(); 78 *alternate_nav_url = GURL();
75 return; 79 return;
76 } 80 }
77 81
78 DCHECK(result.default_match() != result.end()); 82 DCHECK(result.default_match() != result.end());
79 *match = *result.default_match(); 83 *match = *result.default_match();
80 if (alternate_nav_url) 84 if (alternate_nav_url)
81 *alternate_nav_url = result.alternate_nav_url(); 85 *alternate_nav_url = result.alternate_nav_url();
82 } 86 }
OLDNEW
« no previous file with comments | « components/omnibox/browser/autocomplete_classifier.h ('k') | components/omnibox/browser/omnibox_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698