From 7cda124956524c8c49f10f8088be76aee40a1105 Mon Sep 17 00:00:00 2001 From: blundell Date: Wed, 15 Jul 2015 02:58:20 -0700 Subject: [PATCH] Inject OmniboxClient instance into Omnibox core code Rather than having OmniboxEditModel construct a ChromeOmniboxClient, pass in the OmniboxClient to Omnibox component-level code from //chrome-level code. BUG=371536 Review URL: https://codereview.chromium.org/1230203002 Cr-Commit-Position: refs/heads/master@{#338835} --- chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.mm | 6 +++++- .../browser/ui/cocoa/omnibox/omnibox_view_mac_unittest.mm | 10 +++++++--- chrome/browser/ui/omnibox/omnibox_edit_model.cc | 5 +++-- chrome/browser/ui/omnibox/omnibox_edit_model.h | 1 + chrome/browser/ui/omnibox/omnibox_edit_unittest.cc | 13 ++++++++++--- chrome/browser/ui/omnibox/omnibox_view.cc | 8 +++++--- chrome/browser/ui/omnibox/omnibox_view.h | 2 ++ chrome/browser/ui/views/omnibox/omnibox_view_views.cc | 6 +++++- 8 files changed, 38 insertions(+), 13 deletions(-) diff --git a/chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.mm b/chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.mm index b2ec7e580b1e..e43c6cd007e3 100644 --- a/chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.mm +++ b/chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.mm @@ -17,6 +17,7 @@ #include "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell.h" #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.h" #include "chrome/browser/ui/cocoa/omnibox/omnibox_popup_view_mac.h" +#include "chrome/browser/ui/omnibox/chrome_omnibox_client.h" #include "chrome/browser/ui/omnibox/omnibox_edit_controller.h" #include "chrome/browser/ui/omnibox/omnibox_popup_model.h" #include "chrome/browser/ui/toolbar/toolbar_model.h" @@ -141,7 +142,10 @@ OmniboxViewMac::OmniboxViewMac(OmniboxEditController* controller, Profile* profile, CommandUpdater* command_updater, AutocompleteTextField* field) - : OmniboxView(profile, controller, command_updater), + : OmniboxView(profile, + controller, + make_scoped_ptr(new ChromeOmniboxClient(controller, profile)), + command_updater), popup_view_(new OmniboxPopupViewMac(this, model(), field)), field_(field), saved_temporary_selection_(NSMakeRange(0, 0)), diff --git a/chrome/browser/ui/cocoa/omnibox/omnibox_view_mac_unittest.mm b/chrome/browser/ui/cocoa/omnibox/omnibox_view_mac_unittest.mm index 27e2082bf783..d5007f42f0cd 100644 --- a/chrome/browser/ui/cocoa/omnibox/omnibox_view_mac_unittest.mm +++ b/chrome/browser/ui/cocoa/omnibox/omnibox_view_mac_unittest.mm @@ -5,6 +5,7 @@ #import "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h" #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" +#include "chrome/browser/ui/omnibox/chrome_omnibox_client.h" #include "chrome/browser/ui/omnibox/omnibox_edit_controller.h" #include "chrome/browser/ui/omnibox/omnibox_popup_model.h" #include "chrome/browser/ui/toolbar/toolbar_model_delegate.h" @@ -23,9 +24,12 @@ class MockOmniboxEditModel : public OmniboxEditModel { MockOmniboxEditModel(OmniboxView* view, OmniboxEditController* controller, Profile* profile) - : OmniboxEditModel(view, controller, profile), - up_or_down_count_(0) { - } + : OmniboxEditModel( + view, + controller, + make_scoped_ptr(new ChromeOmniboxClient(controller, profile)), + profile), + up_or_down_count_(0) {} void OnUpOrDownKeyPressed(int count) override { up_or_down_count_ = count; } diff --git a/chrome/browser/ui/omnibox/omnibox_edit_model.cc b/chrome/browser/ui/omnibox/omnibox_edit_model.cc index 35564201c6cb..8f3159bfce14 100644 --- a/chrome/browser/ui/omnibox/omnibox_edit_model.cc +++ b/chrome/browser/ui/omnibox/omnibox_edit_model.cc @@ -32,7 +32,7 @@ #include "chrome/browser/profiles/profile.h" #include "chrome/browser/search_engines/template_url_service_factory.h" #include "chrome/browser/search_engines/ui_thread_search_terms_data.h" -#include "chrome/browser/ui/omnibox/chrome_omnibox_client.h" +#include "chrome/browser/ui/omnibox/omnibox_client.h" #include "chrome/browser/ui/omnibox/omnibox_edit_controller.h" #include "chrome/browser/ui/omnibox/omnibox_navigation_observer.h" #include "chrome/browser/ui/omnibox/omnibox_popup_model.h" @@ -195,9 +195,11 @@ OmniboxEditModel::State::~State() { OmniboxEditModel::OmniboxEditModel(OmniboxView* view, OmniboxEditController* controller, + scoped_ptr client, Profile* profile) : view_(view), controller_(controller), + client_(client.Pass()), focus_state_(OMNIBOX_FOCUS_NONE), focus_source_(INVALID), user_input_in_progress_(false), @@ -211,7 +213,6 @@ OmniboxEditModel::OmniboxEditModel(OmniboxView* view, in_revert_(false), allow_exact_keyword_match_(false) { omnibox_controller_.reset(new OmniboxController(this, profile)); - client_.reset(new ChromeOmniboxClient(controller, profile)); } OmniboxEditModel::~OmniboxEditModel() { diff --git a/chrome/browser/ui/omnibox/omnibox_edit_model.h b/chrome/browser/ui/omnibox/omnibox_edit_model.h index c28da379dcab..a8cf82e597a7 100644 --- a/chrome/browser/ui/omnibox/omnibox_edit_model.h +++ b/chrome/browser/ui/omnibox/omnibox_edit_model.h @@ -78,6 +78,7 @@ class OmniboxEditModel { OmniboxEditModel(OmniboxView* view, OmniboxEditController* controller, + scoped_ptr client, Profile* profile); virtual ~OmniboxEditModel(); diff --git a/chrome/browser/ui/omnibox/omnibox_edit_unittest.cc b/chrome/browser/ui/omnibox/omnibox_edit_unittest.cc index 87c9738a2ddc..a7b0b60184fb 100644 --- a/chrome/browser/ui/omnibox/omnibox_edit_unittest.cc +++ b/chrome/browser/ui/omnibox/omnibox_edit_unittest.cc @@ -5,6 +5,7 @@ #include "base/strings/utf_string_conversions.h" #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" #include "chrome/browser/search_engines/template_url_service_factory.h" +#include "chrome/browser/ui/omnibox/chrome_omnibox_client.h" #include "chrome/browser/ui/omnibox/omnibox_edit_controller.h" #include "chrome/browser/ui/omnibox/omnibox_edit_model.h" #include "chrome/browser/ui/omnibox/omnibox_view.h" @@ -22,7 +23,7 @@ namespace { class TestingOmniboxView : public OmniboxView { public: explicit TestingOmniboxView(OmniboxEditController* controller) - : OmniboxView(NULL, controller, NULL) {} + : OmniboxView(nullptr, controller, nullptr, nullptr) {} // OmniboxView: void SaveStateToTab(WebContents* tab) override {} @@ -197,7 +198,10 @@ TEST_F(AutocompleteEditTest, AdjustTextForCopy) { &profile, &TemplateURLServiceFactory::BuildInstanceFor); AutocompleteClassifierFactory::GetInstance()->SetTestingFactory( &profile, &AutocompleteClassifierFactory::BuildInstanceFor); - OmniboxEditModel model(&view, &controller, &profile); + OmniboxEditModel model( + &view, &controller, + make_scoped_ptr(new ChromeOmniboxClient(&controller, &profile)), + &profile); for (size_t i = 0; i < arraysize(input); ++i) { toolbar_model()->set_text(ASCIIToUTF16(input[i].perm_text)); @@ -229,7 +233,10 @@ TEST_F(AutocompleteEditTest, InlineAutocompleteText) { &profile, &TemplateURLServiceFactory::BuildInstanceFor); AutocompleteClassifierFactory::GetInstance()->SetTestingFactory( &profile, &AutocompleteClassifierFactory::BuildInstanceFor); - OmniboxEditModel model(&view, &controller, &profile); + OmniboxEditModel model( + &view, &controller, + make_scoped_ptr(new ChromeOmniboxClient(&controller, &profile)), + &profile); // Test if the model updates the inline autocomplete text in the view. EXPECT_EQ(base::string16(), view.inline_autocomplete_text()); diff --git a/chrome/browser/ui/omnibox/omnibox_view.cc b/chrome/browser/ui/omnibox/omnibox_view.cc index e22d8608a1ea..a2f56e1d46ad 100644 --- a/chrome/browser/ui/omnibox/omnibox_view.cc +++ b/chrome/browser/ui/omnibox/omnibox_view.cc @@ -10,6 +10,7 @@ #include "base/strings/string16.h" #include "base/strings/string_util.h" #include "base/strings/utf_string_conversions.h" +#include "chrome/browser/ui/omnibox/omnibox_client.h" #include "chrome/browser/ui/omnibox/omnibox_edit_controller.h" #include "chrome/browser/ui/toolbar/toolbar_model.h" #include "chrome/grit/generated_resources.h" @@ -179,12 +180,13 @@ void OmniboxView::OnMatchOpened(const AutocompleteMatch& match, OmniboxView::OmniboxView(Profile* profile, OmniboxEditController* controller, + scoped_ptr client, CommandUpdater* command_updater) - : controller_(controller), - command_updater_(command_updater) { + : controller_(controller), command_updater_(command_updater) { // |profile| can be NULL in tests. if (profile) - model_.reset(new OmniboxEditModel(this, controller, profile)); + model_.reset( + new OmniboxEditModel(this, controller, client.Pass(), profile)); } void OmniboxView::TextChanged() { diff --git a/chrome/browser/ui/omnibox/omnibox_view.h b/chrome/browser/ui/omnibox/omnibox_view.h index 52ae95906bc2..26461781d6a3 100644 --- a/chrome/browser/ui/omnibox/omnibox_view.h +++ b/chrome/browser/ui/omnibox/omnibox_view.h @@ -23,6 +23,7 @@ class CommandUpdater; class GURL; +class OmniboxClient; class OmniboxEditController; class OmniboxViewMacTest; class Profile; @@ -254,6 +255,7 @@ class OmniboxView { protected: OmniboxView(Profile* profile, OmniboxEditController* controller, + scoped_ptr client, CommandUpdater* command_updater); // Internally invoked whenever the text changes in some way. diff --git a/chrome/browser/ui/views/omnibox/omnibox_view_views.cc b/chrome/browser/ui/views/omnibox/omnibox_view_views.cc index 2412748ab2fd..10a7f6d625d2 100644 --- a/chrome/browser/ui/views/omnibox/omnibox_view_views.cc +++ b/chrome/browser/ui/views/omnibox/omnibox_view_views.cc @@ -15,6 +15,7 @@ #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h" #include "chrome/browser/command_updater.h" #include "chrome/browser/search/search.h" +#include "chrome/browser/ui/omnibox/chrome_omnibox_client.h" #include "chrome/browser/ui/omnibox/omnibox_edit_controller.h" #include "chrome/browser/ui/omnibox/omnibox_edit_model.h" #include "chrome/browser/ui/omnibox/omnibox_popup_model.h" @@ -134,7 +135,10 @@ OmniboxViewViews::OmniboxViewViews(OmniboxEditController* controller, bool popup_window_mode, LocationBarView* location_bar, const gfx::FontList& font_list) - : OmniboxView(profile, controller, command_updater), + : OmniboxView(profile, + controller, + make_scoped_ptr(new ChromeOmniboxClient(controller, profile)), + command_updater), popup_window_mode_(popup_window_mode), security_level_(connection_security::NONE), saved_selection_for_focus_change_(gfx::Range::InvalidRange()), -- 2.11.4.GIT