Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(271)

Side by Side Diff: chrome/browser/ui/ash/launcher/browser_status_monitor.h

Issue 23708028: Reduce calling count of UpdateAppState() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 #ifndef CHROME_BROWSER_UI_ASH_LAUNCHER_BROWSER_STATUS_MONITOR_H_ 5 #ifndef CHROME_BROWSER_UI_ASH_LAUNCHER_BROWSER_STATUS_MONITOR_H_
6 #define CHROME_BROWSER_UI_ASH_LAUNCHER_BROWSER_STATUS_MONITOR_H_ 6 #define CHROME_BROWSER_UI_ASH_LAUNCHER_BROWSER_STATUS_MONITOR_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 10
11 #include "ash/shelf/scoped_observer_with_duplicated_sources.h" 11 #include "ash/shelf/scoped_observer_with_duplicated_sources.h"
12 #include "base/basictypes.h" 12 #include "base/basictypes.h"
13 #include "base/compiler_specific.h" 13 #include "base/compiler_specific.h"
14 #include "base/scoped_observer.h" 14 #include "base/scoped_observer.h"
15 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
15 #include "chrome/browser/ui/browser_list_observer.h" 16 #include "chrome/browser/ui/browser_list_observer.h"
16 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h" 17 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h"
18 #include "content/public/browser/web_contents_observer.h"
17 #include "ui/aura/client/activation_change_observer.h" 19 #include "ui/aura/client/activation_change_observer.h"
18 #include "ui/aura/window_observer.h" 20 #include "ui/aura/window_observer.h"
19 #include "ui/gfx/display_observer.h" 21 #include "ui/gfx/display_observer.h"
20 22
21 namespace aura { 23 namespace aura {
22 class Window; 24 class Window;
23 25
24 namespace client { 26 namespace client {
25 class ActivationClient; 27 class ActivationClient;
26 } 28 }
27 } // namespace aura 29 } // namespace aura
28 30
29 class Browser; 31 class Browser;
30 class ChromeLauncherController;
31 32
32 // BrowserStatusMonitor monitors creation/deletion of Browser and its 33 // BrowserStatusMonitor monitors creation/deletion of Browser and its
33 // TabStripModel to keep the launcher representation up to date as the 34 // TabStripModel to keep the launcher representation up to date as the
34 // active tab changes. 35 // active tab changes.
35 class BrowserStatusMonitor : public aura::client::ActivationChangeObserver, 36 class BrowserStatusMonitor : public aura::client::ActivationChangeObserver,
36 public aura::WindowObserver, 37 public aura::WindowObserver,
37 public chrome::BrowserListObserver, 38 public chrome::BrowserListObserver,
38 public gfx::DisplayObserver, 39 public gfx::DisplayObserver,
39 public TabStripModelObserver { 40 public TabStripModelObserver {
40 public: 41 public:
41 explicit BrowserStatusMonitor(ChromeLauncherController* launcher_controller); 42 explicit BrowserStatusMonitor(ChromeLauncherController* launcher_controller);
42 virtual ~BrowserStatusMonitor(); 43 virtual ~BrowserStatusMonitor();
43 44
45 // A shortcut to call the ChromeLauncherController's UpdateAppState().
46 void UpdateAppItemState(content::WebContents* contents,
47 ChromeLauncherController::AppState app_state);
48
49 // A shortcut to call the BrowserShortcutLauncherItemController's
50 // UpdateBrowserItemState().
51 void UpdateBrowserItemState();
52
44 // aura::client::ActivationChangeObserver overrides: 53 // aura::client::ActivationChangeObserver overrides:
45 virtual void OnWindowActivated(aura::Window* gained_active, 54 virtual void OnWindowActivated(aura::Window* gained_active,
46 aura::Window* lost_active) OVERRIDE; 55 aura::Window* lost_active) OVERRIDE;
47 56
48 // aura::WindowObserver overrides: 57 // aura::WindowObserver overrides:
49 virtual void OnWindowDestroyed(aura::Window* window) OVERRIDE; 58 virtual void OnWindowDestroyed(aura::Window* window) OVERRIDE;
50 59
51 // chrome::BrowserListObserver overrides: 60 // chrome::BrowserListObserver overrides:
52 virtual void OnBrowserAdded(Browser* browser) OVERRIDE; 61 virtual void OnBrowserAdded(Browser* browser) OVERRIDE;
53 virtual void OnBrowserRemoved(Browser* browser) OVERRIDE; 62 virtual void OnBrowserRemoved(Browser* browser) OVERRIDE;
54 63
55 // gfx::DisplayObserver overrides: 64 // gfx::DisplayObserver overrides:
56 virtual void OnDisplayBoundsChanged(const gfx::Display& display) OVERRIDE; 65 virtual void OnDisplayBoundsChanged(const gfx::Display& display) OVERRIDE;
57 virtual void OnDisplayAdded(const gfx::Display& new_display) OVERRIDE; 66 virtual void OnDisplayAdded(const gfx::Display& new_display) OVERRIDE;
58 virtual void OnDisplayRemoved(const gfx::Display& old_display) OVERRIDE; 67 virtual void OnDisplayRemoved(const gfx::Display& old_display) OVERRIDE;
59 68
60 // TabStripModelObserver overrides: 69 // TabStripModelObserver overrides:
61 virtual void ActiveTabChanged(content::WebContents* old_contents, 70 virtual void ActiveTabChanged(content::WebContents* old_contents,
62 content::WebContents* new_contents, 71 content::WebContents* new_contents,
63 int index, 72 int index,
64 int reason) OVERRIDE; 73 int reason) OVERRIDE;
65 virtual void TabInsertedAt(content::WebContents* contents, 74 virtual void TabInsertedAt(content::WebContents* contents,
66 int index, 75 int index,
67 bool foreground) OVERRIDE; 76 bool foreground) OVERRIDE;
68 virtual void TabDetachedAt(content::WebContents* contents, 77 virtual void TabClosingAt(TabStripModel* tab_strip_mode,
69 int index) OVERRIDE; 78 content::WebContents* contents,
70 virtual void TabChangedAt( 79 int index) OVERRIDE;
71 content::WebContents* contents,
72 int index,
73 TabStripModelObserver::TabChangeType change_type) OVERRIDE;
74 virtual void TabReplacedAt(TabStripModel* tab_strip_model,
75 content::WebContents* old_contents,
76 content::WebContents* new_contents,
77 int index) OVERRIDE;
78 80
79 private: 81 private:
82 // This class monitors the WebContent of the all tab and notifies a navigation
83 // to the BrowserStatusMonitor.
84 class LocalWebContentsObserver : public content::WebContentsObserver {
85 public:
86 LocalWebContentsObserver(content::WebContents* contents,
87 BrowserStatusMonitor* monitor);
88 virtual ~LocalWebContentsObserver();
89
90 // content::WebContentsObserver overrides:
91 virtual void DidNavigateMainFrame(
92 const content::LoadCommittedDetails& details,
93 const content::FrameNavigateParams& params) OVERRIDE;
94
95 private:
96 BrowserStatusMonitor* monitor_;
97
98 DISALLOW_COPY_AND_ASSIGN(LocalWebContentsObserver);
99 };
100
80 typedef std::map<Browser*, std::string> BrowserToAppIDMap; 101 typedef std::map<Browser*, std::string> BrowserToAppIDMap;
81 102 typedef std::map<content::WebContents*, LocalWebContentsObserver*>
82 // Update app state for |contents| and browser state. 103 WebContentsToObserverMap;
83 void UpdateAppAndBrowserState(content::WebContents* contents);
84
85 // A shortcut to call the BrowserShortcutLauncherItemController's
86 // UpdateBrowserItemState().
87 void UpdateBrowserItemState();
88 104
89 ChromeLauncherController* launcher_controller_; 105 ChromeLauncherController* launcher_controller_;
90 106
91 // Hold all observed activation clients. 107 // Hold all observed activation clients.
92 ScopedObserverWithDuplicatedSources<aura::client::ActivationClient, 108 ScopedObserverWithDuplicatedSources<aura::client::ActivationClient,
93 aura::client::ActivationChangeObserver> observed_activation_clients_; 109 aura::client::ActivationChangeObserver> observed_activation_clients_;
94 110
95 // Hold all observed root windows. 111 // Hold all observed root windows.
96 ScopedObserver<aura::Window, aura::WindowObserver> observed_root_windows_; 112 ScopedObserver<aura::Window, aura::WindowObserver> observed_root_windows_;
97 113
98 BrowserToAppIDMap browser_to_app_id_map_; 114 BrowserToAppIDMap browser_to_app_id_map_;
99 115
116 WebContentsToObserverMap webcontents_to_observer_map_;
117
100 DISALLOW_COPY_AND_ASSIGN(BrowserStatusMonitor); 118 DISALLOW_COPY_AND_ASSIGN(BrowserStatusMonitor);
101 }; 119 };
102 120
103 #endif // CHROME_BROWSER_UI_ASH_LAUNCHER_BROWSER_STATUS_MONITOR_H_ 121 #endif // CHROME_BROWSER_UI_ASH_LAUNCHER_BROWSER_STATUS_MONITOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698