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 3// found in the LICENSE file. 4 5#ifndef CHROME_BROWSER_UI_SEARCH_SEARCH_DELEGATE_H_ 6#define CHROME_BROWSER_UI_SEARCH_SEARCH_DELEGATE_H_ 7 8#include "base/basictypes.h" 9#include "base/compiler_specific.h" 10#include "chrome/browser/ui/search/search_model_observer.h" 11 12namespace content { 13class WebContents; 14} 15 16class SearchModel; 17 18// The SearchDelegate class acts as a helper to the Browser class. 19// It is responsible for routing the changes from the active tab's 20// SearchModel through to the toolbar, tabstrip and other UI 21// observers. 22// Changes are propagated from the active tab's model via this class to the 23// Browser-level model. 24class SearchDelegate : public SearchModelObserver { 25 public: 26 explicit SearchDelegate(SearchModel* browser_search_model); 27 virtual ~SearchDelegate(); 28 29 // Overrides for SearchModelObserver: 30 virtual void ModelChanged(const SearchModel::State& old_state, 31 const SearchModel::State& new_state) OVERRIDE; 32 33 // When the active tab is changed, the model state of this new active tab is 34 // propagated to the browser. 35 void OnTabActivated(content::WebContents* web_contents); 36 37 // When a tab is deactivated, this class no longer observes changes to the 38 // tab's model. 39 void OnTabDeactivated(content::WebContents* web_contents); 40 41 // When a tab is detached, this class no longer observes changes to the 42 // tab's model. 43 void OnTabDetached(content::WebContents* web_contents); 44 45 private: 46 // Stop observing tab. 47 void StopObservingTab(content::WebContents* web_contents); 48 49 // Weak. The Browser class owns this. The active |tab_model_| state is 50 // propagated to the |browser_model_|. 51 SearchModel* browser_model_; 52 53 // Weak. The WebContents owns this. It is the model of the active 54 // tab. Changes to this model are propagated through to the |browser_model_|. 55 SearchModel* tab_model_; 56 57 DISALLOW_COPY_AND_ASSIGN(SearchDelegate); 58}; 59 60#endif // CHROME_BROWSER_UI_SEARCH_SEARCH_DELEGATE_H_ 61