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