Chromium Code Reviews| Index: chrome/browser/ui/search/search_delegate.cc |
| diff --git a/chrome/browser/ui/search/search_delegate.cc b/chrome/browser/ui/search/search_delegate.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..6a6dd973e12d840bc5cf1a01adab1664082c4f12 |
| --- /dev/null |
| +++ b/chrome/browser/ui/search/search_delegate.cc |
| @@ -0,0 +1,59 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/ui/search/search_delegate.h" |
| + |
| +#include "chrome/browser/ui/search/search_model.h" |
| +#include "chrome/browser/ui/search/search_tab_helper.h" |
| +#include "chrome/browser/ui/tab_contents/tab_contents.h" |
| + |
| +namespace chrome { |
| +namespace search { |
| + |
| +SearchDelegate::SearchDelegate(SearchModel* browser_model) |
| + : browser_model_(browser_model), |
| + tab_model_(NULL) { |
| +} |
| + |
| +SearchDelegate::~SearchDelegate() { |
| + DCHECK(!tab_model_) << "All tabs should have been deactivated or closed."; |
| +} |
| + |
| +void SearchDelegate::ModeChanged(const Mode& mode) { |
| + browser_model_->SetMode(mode); |
| +} |
| + |
| +void SearchDelegate::OnTabActivated(TabContents* contents) { |
| + if (tab_model_) |
| + tab_model_->RemoveObserver(this); |
| + tab_model_ = contents->search_tab_helper()->model(); |
| + DCHECK(tab_model_->tab_contents() == contents); |
|
sky
2012/06/21 18:26:49
DCHECK_EQ
dhollowa
2012/06/21 22:16:43
Done.
|
| + browser_model_->set_tab_contents(contents); |
| + browser_model_->SetMode(tab_model_->mode()); |
| + tab_model_->AddObserver(this); |
| +} |
| + |
| +void SearchDelegate::OnTabClosing(TabContents* contents) { |
| + StopObserveringTab(contents); |
| +} |
| + |
| +void SearchDelegate::OnTabDeactivated(TabContents* contents) { |
| + StopObserveringTab(contents); |
| +} |
| + |
| +void SearchDelegate::OnTabDettached(TabContents* contents) { |
| + StopObserveringTab(contents); |
| +} |
| + |
| +void SearchDelegate::StopObserveringTab( |
| + TabContents* contents) { |
| + if (contents->search_tab_helper()->model() == tab_model_) { |
| + tab_model_->RemoveObserver(this); |
| + browser_model_->set_tab_contents(NULL); |
| + tab_model_ = NULL; |
| + } |
| +} |
| + |
| +} // namespace search |
| +} // namespace chrome |