| OLD | NEW |
| 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/ui/search/search_delegate.h" | 5 #include "chrome/browser/ui/search/search_delegate.h" |
| 6 | 6 |
| 7 #include "chrome/browser/ui/search/search_model.h" | 7 #include "chrome/browser/ui/search/search_model.h" |
| 8 #include "chrome/browser/ui/search/search_tab_helper.h" | 8 #include "chrome/browser/ui/search/search_tab_helper.h" |
| 9 | 9 |
| 10 SearchDelegate::SearchDelegate(SearchModel* browser_search_model) | 10 SearchDelegate::SearchDelegate(SearchModel* browser_search_model) |
| 11 : browser_model_(browser_search_model), | 11 : browser_model_(browser_search_model), tab_model_(nullptr) {} |
| 12 tab_model_() { | |
| 13 } | |
| 14 | 12 |
| 15 SearchDelegate::~SearchDelegate() { | 13 SearchDelegate::~SearchDelegate() { |
| 16 DCHECK(!tab_model_) << "All tabs should have been deactivated or closed."; | 14 DCHECK(!tab_model_) << "All tabs should have been deactivated or closed."; |
| 17 } | 15 } |
| 18 | 16 |
| 19 void SearchDelegate::ModelChanged(const SearchModel::State& old_state, | 17 void SearchDelegate::ModelChanged(const SearchMode& old_mode, |
| 20 const SearchModel::State& new_state) { | 18 const SearchMode& new_mode) { |
| 21 browser_model_->SetState(new_state); | 19 browser_model_->SetMode(new_mode); |
| 22 } | 20 } |
| 23 | 21 |
| 24 void SearchDelegate::OnTabActivated(content::WebContents* web_contents) { | 22 void SearchDelegate::OnTabActivated(content::WebContents* web_contents) { |
| 25 if (tab_model_) | 23 if (tab_model_) |
| 26 tab_model_->RemoveObserver(this); | 24 tab_model_->RemoveObserver(this); |
| 27 tab_model_ = SearchTabHelper::FromWebContents(web_contents)->model(); | 25 tab_model_ = SearchTabHelper::FromWebContents(web_contents)->model(); |
| 28 browser_model_->SetState(tab_model_->state()); | 26 browser_model_->SetMode(tab_model_->mode()); |
| 29 tab_model_->AddObserver(this); | 27 tab_model_->AddObserver(this); |
| 30 } | 28 } |
| 31 | 29 |
| 32 void SearchDelegate::OnTabDeactivated(content::WebContents* web_contents) { | 30 void SearchDelegate::OnTabDeactivated(content::WebContents* web_contents) { |
| 33 StopObservingTab(web_contents); | 31 StopObservingTab(web_contents); |
| 34 } | 32 } |
| 35 | 33 |
| 36 void SearchDelegate::OnTabDetached(content::WebContents* web_contents) { | 34 void SearchDelegate::OnTabDetached(content::WebContents* web_contents) { |
| 37 StopObservingTab(web_contents); | 35 StopObservingTab(web_contents); |
| 38 } | 36 } |
| 39 | 37 |
| 40 void SearchDelegate::StopObservingTab(content::WebContents* web_contents) { | 38 void SearchDelegate::StopObservingTab(content::WebContents* web_contents) { |
| 41 SearchTabHelper* search_tab_helper = | 39 SearchTabHelper* search_tab_helper = |
| 42 SearchTabHelper::FromWebContents(web_contents); | 40 SearchTabHelper::FromWebContents(web_contents); |
| 43 if (search_tab_helper->model() == tab_model_) { | 41 if (search_tab_helper->model() == tab_model_) { |
| 44 tab_model_->RemoveObserver(this); | 42 tab_model_->RemoveObserver(this); |
| 45 tab_model_ = NULL; | 43 tab_model_ = NULL; |
| 46 } | 44 } |
| 47 } | 45 } |
| OLD | NEW |