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 #ifndef CHROME_BROWSER_UI_ASH_LAUNCHER_CHROME_LAUNCHER_CONTROLLER_H_ | 5 #ifndef CHROME_BROWSER_UI_ASH_LAUNCHER_CHROME_LAUNCHER_CONTROLLER_H_ |
6 #define CHROME_BROWSER_UI_ASH_LAUNCHER_CHROME_LAUNCHER_CONTROLLER_H_ | 6 #define CHROME_BROWSER_UI_ASH_LAUNCHER_CHROME_LAUNCHER_CONTROLLER_H_ |
7 | 7 |
8 #include <list> | 8 #include <list> |
9 #include <map> | 9 #include <map> |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "ash/launcher/launcher_delegate.h" | 12 #include "ash/launcher/launcher_delegate.h" |
13 #include "ash/launcher/launcher_model_observer.h" | 13 #include "ash/launcher/launcher_model_observer.h" |
14 #include "ash/launcher/launcher_types.h" | 14 #include "ash/launcher/launcher_types.h" |
15 #include "ash/shell_observer.h" | 15 #include "ash/shell_observer.h" |
16 #include "ash/wm/shelf_types.h" | 16 #include "ash/wm/shelf_types.h" |
17 #include "base/basictypes.h" | 17 #include "base/basictypes.h" |
18 #include "base/compiler_specific.h" | 18 #include "base/compiler_specific.h" |
19 #include "base/memory/scoped_ptr.h" | 19 #include "base/memory/scoped_ptr.h" |
20 #include "base/timer.h" | |
21 #include "chrome/browser/extensions/extension_prefs.h" | 20 #include "chrome/browser/extensions/extension_prefs.h" |
22 #include "chrome/browser/extensions/shell_window_registry.h" | 21 #include "chrome/browser/extensions/shell_window_registry.h" |
23 #include "chrome/browser/prefs/pref_change_registrar.h" | 22 #include "chrome/browser/prefs/pref_change_registrar.h" |
24 #include "chrome/browser/sync/profile_sync_service_observer.h" | |
25 #include "content/public/browser/notification_observer.h" | 23 #include "content/public/browser/notification_observer.h" |
26 #include "content/public/browser/notification_registrar.h" | 24 #include "content/public/browser/notification_registrar.h" |
27 #include "ui/aura/client/activation_change_observer.h" | 25 #include "ui/aura/client/activation_change_observer.h" |
28 #include "ui/aura/window_observer.h" | 26 #include "ui/aura/window_observer.h" |
29 | 27 |
30 namespace ash { | 28 namespace ash { |
31 class LauncherModel; | 29 class LauncherModel; |
32 } | 30 } |
33 | 31 |
34 namespace aura { | 32 namespace aura { |
35 class Window; | 33 class Window; |
36 | 34 |
37 namespace client { | 35 namespace client { |
38 class ActivationClient; | 36 class ActivationClient; |
39 } | 37 } |
40 | 38 |
41 } | 39 } |
42 | 40 |
43 class BrowserLauncherItemController; | 41 class BrowserLauncherItemController; |
44 class BrowserLauncherItemControllerTest; | 42 class BrowserLauncherItemControllerTest; |
45 class PrefService; | 43 class PrefService; |
46 class Profile; | 44 class Profile; |
47 class ProfileSyncService; | |
48 class TabContents; | 45 class TabContents; |
49 | 46 |
50 // ChromeLauncherController manages the launcher items needed for tabbed | 47 // ChromeLauncherController manages the launcher items needed for tabbed |
51 // browsers (BrowserLauncherItemController) and browser shortcuts. | 48 // browsers (BrowserLauncherItemController) and browser shortcuts. |
52 class ChromeLauncherController | 49 class ChromeLauncherController |
53 : public ash::LauncherDelegate, | 50 : public ash::LauncherDelegate, |
54 public ash::LauncherModelObserver, | 51 public ash::LauncherModelObserver, |
55 public ash::ShellObserver, | 52 public ash::ShellObserver, |
56 public content::NotificationObserver, | 53 public content::NotificationObserver, |
57 public extensions::ShellWindowRegistry::Observer, | 54 public extensions::ShellWindowRegistry::Observer, |
58 public aura::client::ActivationChangeObserver, | 55 public aura::client::ActivationChangeObserver, |
59 public aura::WindowObserver, | 56 public aura::WindowObserver { |
60 public ProfileSyncServiceObserver { | |
61 public: | 57 public: |
62 // Indicates if a launcher item is incognito or not. | 58 // Indicates if a launcher item is incognito or not. |
63 enum IncognitoState { | 59 enum IncognitoState { |
64 STATE_INCOGNITO, | 60 STATE_INCOGNITO, |
65 STATE_NOT_INCOGNITO, | 61 STATE_NOT_INCOGNITO, |
66 }; | 62 }; |
67 | 63 |
68 // Used to update the state of non plaform apps, as tab contents change. | 64 // Used to update the state of non plaform apps, as tab contents change. |
69 enum AppState { | 65 enum AppState { |
70 APP_STATE_ACTIVE, | 66 APP_STATE_ACTIVE, |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 virtual ui::MenuModel* CreateContextMenuForLauncher() OVERRIDE; | 219 virtual ui::MenuModel* CreateContextMenuForLauncher() OVERRIDE; |
224 virtual ash::LauncherID GetIDByWindow(aura::Window* window) OVERRIDE; | 220 virtual ash::LauncherID GetIDByWindow(aura::Window* window) OVERRIDE; |
225 virtual bool IsDraggable(const ash::LauncherItem& item) OVERRIDE; | 221 virtual bool IsDraggable(const ash::LauncherItem& item) OVERRIDE; |
226 | 222 |
227 // ash::LauncherModelObserver overrides: | 223 // ash::LauncherModelObserver overrides: |
228 virtual void LauncherItemAdded(int index) OVERRIDE; | 224 virtual void LauncherItemAdded(int index) OVERRIDE; |
229 virtual void LauncherItemRemoved(int index, ash::LauncherID id) OVERRIDE; | 225 virtual void LauncherItemRemoved(int index, ash::LauncherID id) OVERRIDE; |
230 virtual void LauncherItemMoved(int start_index, int target_index) OVERRIDE; | 226 virtual void LauncherItemMoved(int start_index, int target_index) OVERRIDE; |
231 virtual void LauncherItemChanged(int index, | 227 virtual void LauncherItemChanged(int index, |
232 const ash::LauncherItem& old_item) OVERRIDE; | 228 const ash::LauncherItem& old_item) OVERRIDE; |
233 virtual void LauncherStatusChanged() OVERRIDE; | |
234 | 229 |
235 // Overridden from content::NotificationObserver: | 230 // Overridden from content::NotificationObserver: |
236 virtual void Observe(int type, | 231 virtual void Observe(int type, |
237 const content::NotificationSource& source, | 232 const content::NotificationSource& source, |
238 const content::NotificationDetails& details) OVERRIDE; | 233 const content::NotificationDetails& details) OVERRIDE; |
239 | 234 |
240 // Overridden from ShellWindowRegistry::Observer: | 235 // Overridden from ShellWindowRegistry::Observer: |
241 virtual void OnShellWindowAdded(ShellWindow* shell_window) OVERRIDE; | 236 virtual void OnShellWindowAdded(ShellWindow* shell_window) OVERRIDE; |
242 virtual void OnShellWindowRemoved(ShellWindow* shell_window) OVERRIDE; | 237 virtual void OnShellWindowRemoved(ShellWindow* shell_window) OVERRIDE; |
243 | 238 |
244 // Overridden from client::ActivationChangeObserver: | 239 // Overriden from client::ActivationChangeObserver: |
245 virtual void OnWindowActivated( | 240 virtual void OnWindowActivated( |
246 aura::Window* active, | 241 aura::Window* active, |
247 aura::Window* old_active) OVERRIDE; | 242 aura::Window* old_active) OVERRIDE; |
248 | 243 |
249 // Overridden from aura::WindowObserver: | 244 // Overriden from aura::WindowObserver: |
250 virtual void OnWindowRemovingFromRootWindow(aura::Window* window) OVERRIDE; | 245 virtual void OnWindowRemovingFromRootWindow(aura::Window* window) OVERRIDE; |
251 | 246 |
252 // Overridden from ash::ShellObserver: | 247 // Overriden from ash::ShellObserver: |
253 virtual void OnShelfAlignmentChanged() OVERRIDE; | 248 virtual void OnShelfAlignmentChanged() OVERRIDE; |
254 | 249 |
255 // Overridden from ProfileSyncServiceObserver: | |
256 virtual void OnStateChanged() OVERRIDE; | |
257 | |
258 private: | 250 private: |
259 friend class BrowserLauncherItemControllerTest; | 251 friend class BrowserLauncherItemControllerTest; |
260 friend class ChromeLauncherControllerTest; | 252 friend class ChromeLauncherControllerTest; |
261 | 253 |
262 enum ItemType { | 254 enum ItemType { |
263 TYPE_APP, | 255 TYPE_APP, |
264 TYPE_TABBED_BROWSER | 256 TYPE_TABBED_BROWSER |
265 }; | 257 }; |
266 | 258 |
267 // Used to identity an item on the launcher. | 259 // Used to identity an item on the launcher. |
(...skipping 23 matching lines...) Expand all Loading... |
291 // These are intended for testing. | 283 // These are intended for testing. |
292 void SetAppTabHelperForTest(AppTabHelper* helper); | 284 void SetAppTabHelperForTest(AppTabHelper* helper); |
293 void SetAppIconLoaderForTest(AppIconLoader* loader); | 285 void SetAppIconLoaderForTest(AppIconLoader* loader); |
294 | 286 |
295 // Returns the profile used for new windows. | 287 // Returns the profile used for new windows. |
296 Profile* GetProfileForNewWindows(); | 288 Profile* GetProfileForNewWindows(); |
297 | 289 |
298 // Returns item status for given |id|. | 290 // Returns item status for given |id|. |
299 ash::LauncherItemStatus GetItemStatus(ash::LauncherID id) const; | 291 ash::LauncherItemStatus GetItemStatus(ash::LauncherID id) const; |
300 | 292 |
| 293 // Finds the launcher item that represents given |app_id| and updates the |
| 294 // pending state. |
| 295 void MarkAppPending(const std::string& app_id); |
| 296 |
301 // Internal helpers for pinning and unpinning that handle both | 297 // Internal helpers for pinning and unpinning that handle both |
302 // client-triggered and internal pinning operations. | 298 // client-triggered and internal pinning operations. |
303 void DoPinAppWithID(const std::string& app_id); | 299 void DoPinAppWithID(const std::string& app_id); |
304 void DoUnpinAppsWithID(const std::string& app_id); | 300 void DoUnpinAppsWithID(const std::string& app_id); |
305 | 301 |
306 // Re-syncs launcher model with prefs::kPinnedLauncherApps. | 302 // Re-syncs launcher model with prefs::kPinnedLauncherApps. |
307 void UpdateAppLaunchersFromPref(); | 303 void UpdateAppLaunchersFromPref(); |
308 | 304 |
309 // Sets the shelf auto-hide behavior from prefs. | 305 // Sets the shelf auto-hide behavior from prefs. |
310 void SetShelfAutoHideBehaviorFromPrefs(); | 306 void SetShelfAutoHideBehaviorFromPrefs(); |
311 | 307 |
312 // Sets the shelf alignment from prefs. | 308 // Sets the shelf alignment from prefs. |
313 void SetShelfAlignmentFromPrefs(); | 309 void SetShelfAlignmentFromPrefs(); |
314 | 310 |
315 // Returns the most recently active tab contents for an app. | 311 // Returns the most recently active tab contents for an app. |
316 TabContents* GetLastActiveTabContents(const std::string& app_id); | 312 TabContents* GetLastActiveTabContents(const std::string& app_id); |
317 | 313 |
318 // Creates an app launcher to insert at |index|. Note that |index| may be | 314 // Creates an app launcher to insert at |index|. Note that |index| may be |
319 // adjusted by the model to meet ordering constraints. | 315 // adjusted by the model to meet ordering constraints. |
320 ash::LauncherID InsertAppLauncherItem( | 316 ash::LauncherID InsertAppLauncherItem( |
321 BrowserLauncherItemController* controller, | 317 BrowserLauncherItemController* controller, |
322 const std::string& app_id, | 318 const std::string& app_id, |
323 ash::LauncherItemStatus status, | 319 ash::LauncherItemStatus status, |
324 int index); | 320 int index); |
325 | 321 |
326 // Checks whether sync is completed and no pending synced extension install | |
327 // and calls StopLoadingAnimation when both conditions are met. | |
328 void CheckAppSync(); | |
329 | |
330 void StartLoadingAnimation(); | |
331 void StopLoadingAnimation(); | |
332 | |
333 static ChromeLauncherController* instance_; | 322 static ChromeLauncherController* instance_; |
334 | 323 |
335 ash::LauncherModel* model_; | 324 ash::LauncherModel* model_; |
336 | 325 |
337 // Profile used for prefs and loading extensions. This is NOT necessarily the | 326 // Profile used for prefs and loading extensions. This is NOT necessarily the |
338 // profile new windows are created with. | 327 // profile new windows are created with. |
339 Profile* profile_; | 328 Profile* profile_; |
340 | 329 |
341 IDToItemMap id_to_item_map_; | 330 IDToItemMap id_to_item_map_; |
342 | 331 |
(...skipping 15 matching lines...) Expand all Loading... |
358 scoped_ptr<AppTabHelper> app_tab_helper_; | 347 scoped_ptr<AppTabHelper> app_tab_helper_; |
359 | 348 |
360 // Used to load the image for an app item. | 349 // Used to load the image for an app item. |
361 scoped_ptr<AppIconLoader> app_icon_loader_; | 350 scoped_ptr<AppIconLoader> app_icon_loader_; |
362 | 351 |
363 content::NotificationRegistrar notification_registrar_; | 352 content::NotificationRegistrar notification_registrar_; |
364 | 353 |
365 PrefChangeRegistrar pref_change_registrar_; | 354 PrefChangeRegistrar pref_change_registrar_; |
366 aura::client::ActivationClient* activation_client_; | 355 aura::client::ActivationClient* activation_client_; |
367 | 356 |
368 ProfileSyncService* observed_sync_service_; | |
369 base::OneShotTimer<ChromeLauncherController> loading_timer_; | |
370 | |
371 DISALLOW_COPY_AND_ASSIGN(ChromeLauncherController); | 357 DISALLOW_COPY_AND_ASSIGN(ChromeLauncherController); |
372 }; | 358 }; |
373 | 359 |
374 #endif // CHROME_BROWSER_UI_ASH_LAUNCHER_CHROME_LAUNCHER_CONTROLLER_H_ | 360 #endif // CHROME_BROWSER_UI_ASH_LAUNCHER_CHROME_LAUNCHER_CONTROLLER_H_ |
OLD | NEW |