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