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

Side by Side Diff: chrome/browser/ui/ash/launcher/chrome_launcher_controller.cc

Issue 10829268: chromeos: Sync animation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: wrap up + rebase Created 8 years, 4 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 | Annotate | Revision Log
OLDNEW
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 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" 5 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
6 6
7 #include <set> 7 #include <set>
8 #include <vector> 8 #include <vector>
9 9
10 #include "ash/launcher/launcher_model.h" 10 #include "ash/launcher/launcher_model.h"
11 #include "ash/launcher/launcher_types.h" 11 #include "ash/launcher/launcher_types.h"
12 #include "ash/shell.h" 12 #include "ash/shell.h"
13 #include "ash/wm/window_util.h" 13 #include "ash/wm/window_util.h"
14 #include "base/command_line.h" 14 #include "base/command_line.h"
15 #include "base/utf_string_conversions.h" 15 #include "base/utf_string_conversions.h"
16 #include "base/values.h" 16 #include "base/values.h"
17 #include "chrome/browser/defaults.h" 17 #include "chrome/browser/defaults.h"
18 #include "chrome/browser/extensions/extension_service.h" 18 #include "chrome/browser/extensions/extension_service.h"
19 #include "chrome/browser/extensions/pending_extension_manager.h"
19 #include "chrome/browser/prefs/incognito_mode_prefs.h" 20 #include "chrome/browser/prefs/incognito_mode_prefs.h"
20 #include "chrome/browser/prefs/pref_service.h" 21 #include "chrome/browser/prefs/pref_service.h"
21 #include "chrome/browser/prefs/scoped_user_pref_update.h" 22 #include "chrome/browser/prefs/scoped_user_pref_update.h"
22 #include "chrome/browser/profiles/profile.h" 23 #include "chrome/browser/profiles/profile.h"
23 #include "chrome/browser/profiles/profile_manager.h" 24 #include "chrome/browser/profiles/profile_manager.h"
25 #include "chrome/browser/sync/profile_sync_service.h"
26 #include "chrome/browser/sync/profile_sync_service_factory.h"
24 #include "chrome/browser/ui/ash/chrome_launcher_prefs.h" 27 #include "chrome/browser/ui/ash/chrome_launcher_prefs.h"
25 #include "chrome/browser/ui/ash/extension_utils.h" 28 #include "chrome/browser/ui/ash/extension_utils.h"
26 #include "chrome/browser/ui/ash/launcher/browser_launcher_item_controller.h" 29 #include "chrome/browser/ui/ash/launcher/browser_launcher_item_controller.h"
27 #include "chrome/browser/ui/ash/launcher/launcher_app_icon_loader.h" 30 #include "chrome/browser/ui/ash/launcher/launcher_app_icon_loader.h"
28 #include "chrome/browser/ui/ash/launcher/launcher_app_tab_helper.h" 31 #include "chrome/browser/ui/ash/launcher/launcher_app_tab_helper.h"
29 #include "chrome/browser/ui/ash/launcher/launcher_context_menu.h" 32 #include "chrome/browser/ui/ash/launcher/launcher_context_menu.h"
30 #include "chrome/browser/ui/browser.h" 33 #include "chrome/browser/ui/browser.h"
31 #include "chrome/browser/ui/browser_commands.h" 34 #include "chrome/browser/ui/browser_commands.h"
32 #include "chrome/browser/ui/browser_finder.h" 35 #include "chrome/browser/ui/browser_finder.h"
33 #include "chrome/browser/ui/browser_window.h" 36 #include "chrome/browser/ui/browser_window.h"
34 #include "chrome/browser/ui/extensions/shell_window.h" 37 #include "chrome/browser/ui/extensions/shell_window.h"
35 #include "chrome/browser/ui/tab_contents/tab_contents.h" 38 #include "chrome/browser/ui/tab_contents/tab_contents.h"
36 #include "chrome/browser/ui/tabs/tab_strip_model.h" 39 #include "chrome/browser/ui/tabs/tab_strip_model.h"
37 #include "chrome/browser/web_applications/web_app.h" 40 #include "chrome/browser/web_applications/web_app.h"
38 #include "chrome/common/chrome_notification_types.h" 41 #include "chrome/common/chrome_notification_types.h"
39 #include "chrome/common/chrome_switches.h" 42 #include "chrome/common/chrome_switches.h"
40 #include "chrome/common/extensions/extension.h" 43 #include "chrome/common/extensions/extension.h"
41 #include "chrome/common/extensions/extension_resource.h" 44 #include "chrome/common/extensions/extension_resource.h"
42 #include "chrome/common/pref_names.h" 45 #include "chrome/common/pref_names.h"
43 #include "content/public/browser/notification_service.h" 46 #include "content/public/browser/notification_service.h"
44 #include "content/public/browser/web_contents.h" 47 #include "content/public/browser/web_contents.h"
45 #include "grit/theme_resources.h" 48 #include "grit/theme_resources.h"
46 #include "ui/aura/client/activation_client.h" 49 #include "ui/aura/client/activation_client.h"
47 #include "ui/aura/window.h" 50 #include "ui/aura/window.h"
48 #include "ui/views/widget/widget.h" 51 #include "ui/views/widget/widget.h"
49 52
50 using extensions::Extension; 53 using extensions::Extension;
51 54
55 namespace {
56
57 // Max loading animation time in milliseconds.
58 const int kMaxLoadingTimeMs = 60 * 1000;
59
60 } // namespace
61
52 // ChromeLauncherController::Item ---------------------------------------------- 62 // ChromeLauncherController::Item ----------------------------------------------
53 63
54 ChromeLauncherController::Item::Item() 64 ChromeLauncherController::Item::Item()
55 : item_type(TYPE_TABBED_BROWSER), 65 : item_type(TYPE_TABBED_BROWSER),
56 controller(NULL) { 66 controller(NULL) {
57 } 67 }
58 68
59 ChromeLauncherController::Item::~Item() { 69 ChromeLauncherController::Item::~Item() {
60 } 70 }
61 71
62 // ChromeLauncherController ---------------------------------------------------- 72 // ChromeLauncherController ----------------------------------------------------
63 73
64 // static 74 // static
65 ChromeLauncherController* ChromeLauncherController::instance_ = NULL; 75 ChromeLauncherController* ChromeLauncherController::instance_ = NULL;
66 76
67 ChromeLauncherController::ChromeLauncherController(Profile* profile, 77 ChromeLauncherController::ChromeLauncherController(Profile* profile,
68 ash::LauncherModel* model) 78 ash::LauncherModel* model)
69 : model_(model), 79 : model_(model),
70 profile_(profile), 80 profile_(profile),
71 activation_client_(NULL) { 81 activation_client_(NULL),
82 observed_sync_service_(NULL) {
72 if (!profile_) { 83 if (!profile_) {
73 // Use the original profile as on chromeos we may get a temporary off the 84 // Use the original profile as on chromeos we may get a temporary off the
74 // record profile. 85 // record profile.
75 profile_ = ProfileManager::GetDefaultProfile()->GetOriginalProfile(); 86 profile_ = ProfileManager::GetDefaultProfile()->GetOriginalProfile();
76 } 87 }
77 instance_ = this; 88 instance_ = this;
78 model_->AddObserver(this); 89 model_->AddObserver(this);
79 ShellWindowRegistry::Get(profile_)->AddObserver(this); 90 ShellWindowRegistry::Get(profile_)->AddObserver(this);
80 app_tab_helper_.reset(new LauncherAppTabHelper(profile_)); 91 app_tab_helper_.reset(new LauncherAppTabHelper(profile_));
81 app_icon_loader_.reset(new LauncherAppIconLoader(profile_, this)); 92 app_icon_loader_.reset(new LauncherAppIconLoader(profile_, this));
82 93
83 notification_registrar_.Add(this, 94 notification_registrar_.Add(this,
84 chrome::NOTIFICATION_EXTENSION_LOADED, 95 chrome::NOTIFICATION_EXTENSION_LOADED,
85 content::Source<Profile>(profile_)); 96 content::Source<Profile>(profile_));
86 notification_registrar_.Add(this, 97 notification_registrar_.Add(this,
87 chrome::NOTIFICATION_EXTENSION_UNLOADED, 98 chrome::NOTIFICATION_EXTENSION_UNLOADED,
88 content::Source<Profile>(profile_)); 99 content::Source<Profile>(profile_));
89 pref_change_registrar_.Init(profile_->GetPrefs()); 100 pref_change_registrar_.Init(profile_->GetPrefs());
90 pref_change_registrar_.Add(prefs::kPinnedLauncherApps, this); 101 pref_change_registrar_.Add(prefs::kPinnedLauncherApps, this);
91 pref_change_registrar_.Add(prefs::kShelfAlignment, this); 102 pref_change_registrar_.Add(prefs::kShelfAlignment, this);
92 pref_change_registrar_.Add(prefs::kShelfAutoHideBehavior, this); 103 pref_change_registrar_.Add(prefs::kShelfAutoHideBehavior, this);
104
105 if (!IsLoggedInAsGuest()) {
106 observed_sync_service_ =
107 ProfileSyncServiceFactory::GetForProfile(profile_);
108 if (observed_sync_service_) {
109 observed_sync_service_->AddObserver(this);
110 StartLoadingUI();
111 }
112 }
93 } 113 }
94 114
95 ChromeLauncherController::~ChromeLauncherController() { 115 ChromeLauncherController::~ChromeLauncherController() {
96 ShellWindowRegistry::Get(profile_)->RemoveObserver(this); 116 ShellWindowRegistry::Get(profile_)->RemoveObserver(this);
97 model_->RemoveObserver(this); 117 model_->RemoveObserver(this);
98 for (IDToItemMap::iterator i = id_to_item_map_.begin(); 118 for (IDToItemMap::iterator i = id_to_item_map_.begin();
99 i != id_to_item_map_.end(); ++i) { 119 i != id_to_item_map_.end(); ++i) {
100 model_->RemoveItemAt(model_->ItemIndexByID(i->first)); 120 model_->RemoveItemAt(model_->ItemIndexByID(i->first));
101 } 121 }
102 if (instance_ == this) 122 if (instance_ == this)
103 instance_ = NULL; 123 instance_ = NULL;
104 if (activation_client_) 124 if (activation_client_)
105 activation_client_->RemoveObserver(this); 125 activation_client_->RemoveObserver(this);
106 126
107 for (WindowToIDMap::iterator i = window_to_id_map_.begin(); 127 for (WindowToIDMap::iterator i = window_to_id_map_.begin();
108 i != window_to_id_map_.end(); ++i) { 128 i != window_to_id_map_.end(); ++i) {
109 i->first->RemoveObserver(this); 129 i->first->RemoveObserver(this);
110 } 130 }
111 131
112 if (ash::Shell::HasInstance()) 132 if (ash::Shell::HasInstance())
113 ash::Shell::GetInstance()->RemoveShellObserver(this); 133 ash::Shell::GetInstance()->RemoveShellObserver(this);
134
135 if (observed_sync_service_)
136 observed_sync_service_->RemoveObserver(this);
114 } 137 }
115 138
116 void ChromeLauncherController::Init() { 139 void ChromeLauncherController::Init() {
117 // TODO(xiyuan): Remove migration code and kUseDefaultPinnedApp after M20. 140 // TODO(xiyuan): Remove migration code and kUseDefaultPinnedApp after M20.
118 // Migration cases: 141 // Migration cases:
119 // - Users that unpin all apps: 142 // - Users that unpin all apps:
120 // - have default pinned apps 143 // - have default pinned apps
121 // - kUseDefaultPinnedApps set to false 144 // - kUseDefaultPinnedApps set to false
122 // Migrate them by setting an empty list for kPinnedLauncherApps. 145 // Migrate them by setting an empty list for kPinnedLauncherApps.
123 // 146 //
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 void ChromeLauncherController::Open(ash::LauncherID id, int event_flags) { 279 void ChromeLauncherController::Open(ash::LauncherID id, int event_flags) {
257 if (id_to_item_map_.find(id) == id_to_item_map_.end()) 280 if (id_to_item_map_.find(id) == id_to_item_map_.end())
258 return; // In case invoked from menu and item closed while menu up. 281 return; // In case invoked from menu and item closed while menu up.
259 282
260 BrowserLauncherItemController* controller = id_to_item_map_[id].controller; 283 BrowserLauncherItemController* controller = id_to_item_map_[id].controller;
261 if (controller) { 284 if (controller) {
262 controller->window()->Show(); 285 controller->window()->Show();
263 ash::wm::ActivateWindow(controller->window()); 286 ash::wm::ActivateWindow(controller->window());
264 } else { 287 } else {
265 DCHECK_EQ(TYPE_APP, id_to_item_map_[id].item_type); 288 DCHECK_EQ(TYPE_APP, id_to_item_map_[id].item_type);
266
267 // Do nothing for pending app shortcut.
268 if (GetItemStatus(id) == ash::STATUS_IS_PENDING)
269 return;
270
271 OpenAppID(id_to_item_map_[id].app_id, event_flags); 289 OpenAppID(id_to_item_map_[id].app_id, event_flags);
272 } 290 }
273 } 291 }
274 292
275 void ChromeLauncherController::OpenAppID( 293 void ChromeLauncherController::OpenAppID(
276 const std::string& app_id, 294 const std::string& app_id,
277 int event_flags) { 295 int event_flags) {
278 ash::LauncherID launcher_id = GetLauncherIDForAppID(app_id); 296 ash::LauncherID launcher_id = GetLauncherIDForAppID(app_id);
279 // Check if this item has any windows in the activation list. 297 // Check if this item has any windows in the activation list.
280 for (WindowList::const_iterator i = platform_app_windows_.begin(); 298 for (WindowList::const_iterator i = platform_app_windows_.begin();
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 aura::Window* window_to_activate = 624 aura::Window* window_to_activate =
607 id_to_item_map_[id].controller->window(); 625 id_to_item_map_[id].controller->window();
608 if (window_to_activate && ash::wm::IsActiveWindow(window_to_activate)) 626 if (window_to_activate && ash::wm::IsActiveWindow(window_to_activate))
609 return; 627 return;
610 window_to_activate->Show(); 628 window_to_activate->Show();
611 ash::wm::ActivateWindow(window_to_activate); 629 ash::wm::ActivateWindow(window_to_activate);
612 } 630 }
613 } 631 }
614 } 632 }
615 633
634 void ChromeLauncherController::LauncherUIStateChanged() {
635 }
636
616 void ChromeLauncherController::Observe( 637 void ChromeLauncherController::Observe(
617 int type, 638 int type,
618 const content::NotificationSource& source, 639 const content::NotificationSource& source,
619 const content::NotificationDetails& details) { 640 const content::NotificationDetails& details) {
620 switch (type) { 641 switch (type) {
621 case chrome::NOTIFICATION_EXTENSION_LOADED: { 642 case chrome::NOTIFICATION_EXTENSION_LOADED: {
622 UpdateAppLaunchersFromPref(); 643 UpdateAppLaunchersFromPref();
644 CheckAppSync();
623 break; 645 break;
624 } 646 }
625 case chrome::NOTIFICATION_EXTENSION_UNLOADED: { 647 case chrome::NOTIFICATION_EXTENSION_UNLOADED: {
626 const content::Details<extensions::UnloadedExtensionInfo> unload_info( 648 const content::Details<extensions::UnloadedExtensionInfo> unload_info(
627 details); 649 details);
628 const Extension* extension = unload_info->extension; 650 const Extension* extension = unload_info->extension;
629 if (IsAppPinned(extension->id())) { 651 if (IsAppPinned(extension->id()))
630 if (unload_info->reason == extension_misc::UNLOAD_REASON_UPDATE) 652 DoUnpinAppsWithID(extension->id());
631 MarkAppPending(extension->id());
632 else
633 DoUnpinAppsWithID(extension->id());
634 }
635 break; 653 break;
636 } 654 }
637 case chrome::NOTIFICATION_PREF_CHANGED: { 655 case chrome::NOTIFICATION_PREF_CHANGED: {
638 const std::string& pref_name( 656 const std::string& pref_name(
639 *content::Details<std::string>(details).ptr()); 657 *content::Details<std::string>(details).ptr());
640 if (pref_name == prefs::kPinnedLauncherApps) 658 if (pref_name == prefs::kPinnedLauncherApps)
641 UpdateAppLaunchersFromPref(); 659 UpdateAppLaunchersFromPref();
642 else if (pref_name == prefs::kShelfAlignment) 660 else if (pref_name == prefs::kShelfAlignment)
643 SetShelfAlignmentFromPrefs(); 661 SetShelfAlignmentFromPrefs();
644 else if (pref_name == prefs::kShelfAutoHideBehavior) 662 else if (pref_name == prefs::kShelfAutoHideBehavior)
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
736 case ash::SHELF_ALIGNMENT_LEFT: 754 case ash::SHELF_ALIGNMENT_LEFT:
737 pref_value = ash::kShelfAlignmentLeft; 755 pref_value = ash::kShelfAlignmentLeft;
738 break; 756 break;
739 case ash::SHELF_ALIGNMENT_RIGHT: 757 case ash::SHELF_ALIGNMENT_RIGHT:
740 pref_value = ash::kShelfAlignmentRight; 758 pref_value = ash::kShelfAlignmentRight;
741 break; 759 break;
742 } 760 }
743 profile_->GetPrefs()->SetString(prefs::kShelfAlignment, pref_value); 761 profile_->GetPrefs()->SetString(prefs::kShelfAlignment, pref_value);
744 } 762 }
745 763
764 void ChromeLauncherController::OnStateChanged() {
765 DCHECK(observed_sync_service_);
766 CheckAppSync();
767 }
768
746 void ChromeLauncherController::PersistPinnedState() { 769 void ChromeLauncherController::PersistPinnedState() {
747 // It is a coding error to call PersistPinnedState() if the pinned apps are 770 // It is a coding error to call PersistPinnedState() if the pinned apps are
748 // not user-editable. The code should check earlier and not perform any 771 // not user-editable. The code should check earlier and not perform any
749 // modification actions that trigger persisting the state. 772 // modification actions that trigger persisting the state.
750 if (!CanPin()) { 773 if (!CanPin()) {
751 NOTREACHED() << "Can't pin but pinned state being updated"; 774 NOTREACHED() << "Can't pin but pinned state being updated";
752 return; 775 return;
753 } 776 }
754 777
755 // Set kUseDefaultPinnedApps to false and use pinned apps list from prefs 778 // Set kUseDefaultPinnedApps to false and use pinned apps list from prefs
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
792 } 815 }
793 816
794 ash::LauncherItemStatus ChromeLauncherController::GetItemStatus( 817 ash::LauncherItemStatus ChromeLauncherController::GetItemStatus(
795 ash::LauncherID id) const { 818 ash::LauncherID id) const {
796 int index = model_->ItemIndexByID(id); 819 int index = model_->ItemIndexByID(id);
797 DCHECK_GE(index, 0); 820 DCHECK_GE(index, 0);
798 const ash::LauncherItem& item = model_->items()[index]; 821 const ash::LauncherItem& item = model_->items()[index];
799 return item.status; 822 return item.status;
800 } 823 }
801 824
802 void ChromeLauncherController::MarkAppPending(const std::string& app_id) {
803 for (IDToItemMap::const_iterator i = id_to_item_map_.begin();
804 i != id_to_item_map_.end(); ++i) {
805 if (i->second.item_type == TYPE_APP && i->second.app_id == app_id) {
806 if (GetItemStatus(i->first) == ash::STATUS_CLOSED)
807 SetItemStatus(i->first, ash::STATUS_IS_PENDING);
808
809 break;
810 }
811 }
812 }
813
814 void ChromeLauncherController::DoPinAppWithID(const std::string& app_id) { 825 void ChromeLauncherController::DoPinAppWithID(const std::string& app_id) {
815 // If there is an item, do nothing and return. 826 // If there is an item, do nothing and return.
816 if (IsAppPinned(app_id)) 827 if (IsAppPinned(app_id))
817 return; 828 return;
818 829
819 // Otherwise, create an item for it. 830 // Otherwise, create an item for it.
820 CreateAppLauncherItem(NULL, app_id, ash::STATUS_CLOSED); 831 CreateAppLauncherItem(NULL, app_id, ash::STATUS_CLOSED);
821 if (CanPin()) 832 if (CanPin())
822 PersistPinnedState(); 833 PersistPinnedState();
823 } 834 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
861 // delete all app launcher entries in between. 872 // delete all app launcher entries in between.
862 if (IsAppPinned(*pref_app_id)) { 873 if (IsAppPinned(*pref_app_id)) {
863 for (; index < model_->item_count(); ++index) { 874 for (; index < model_->item_count(); ++index) {
864 const ash::LauncherItem& item(model_->items()[index]); 875 const ash::LauncherItem& item(model_->items()[index]);
865 if (item.type != ash::TYPE_APP_SHORTCUT) 876 if (item.type != ash::TYPE_APP_SHORTCUT)
866 continue; 877 continue;
867 878
868 IDToItemMap::const_iterator entry(id_to_item_map_.find(item.id)); 879 IDToItemMap::const_iterator entry(id_to_item_map_.find(item.id));
869 if (entry != id_to_item_map_.end() && 880 if (entry != id_to_item_map_.end() &&
870 entry->second.app_id == *pref_app_id) { 881 entry->second.app_id == *pref_app_id) {
871 // Current item will be kept. Reset its pending state and ensure
872 // its icon is loaded since it has to be valid to be in |pinned_apps|.
873 if (item.status == ash::STATUS_IS_PENDING) {
874 SetItemStatus(item.id, ash::STATUS_CLOSED);
875 app_icon_loader_->FetchImage(*pref_app_id);
876 }
877
878 ++pref_app_id; 882 ++pref_app_id;
879 break; 883 break;
880 } else { 884 } else {
881 LauncherItemClosed(item.id); 885 LauncherItemClosed(item.id);
882 --index; 886 --index;
883 } 887 }
884 } 888 }
885 // If the item wasn't found, that means id_to_item_map_ is out of sync. 889 // If the item wasn't found, that means id_to_item_map_ is out of sync.
886 DCHECK(index < model_->item_count()); 890 DCHECK(index < model_->item_count());
887 } else { 891 } else {
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
964 } else if (controller->type() == 968 } else if (controller->type() ==
965 BrowserLauncherItemController::TYPE_APP_PANEL || 969 BrowserLauncherItemController::TYPE_APP_PANEL ||
966 controller->type() == 970 controller->type() ==
967 BrowserLauncherItemController::TYPE_EXTENSION_PANEL) { 971 BrowserLauncherItemController::TYPE_EXTENSION_PANEL) {
968 item.type = ash::TYPE_APP_PANEL; 972 item.type = ash::TYPE_APP_PANEL;
969 } else { 973 } else {
970 item.type = ash::TYPE_TABBED; 974 item.type = ash::TYPE_TABBED;
971 } 975 }
972 item.is_incognito = false; 976 item.is_incognito = false;
973 item.image = Extension::GetDefaultIcon(true); 977 item.image = Extension::GetDefaultIcon(true);
974 if (item.type == ash::TYPE_APP_SHORTCUT && 978
975 !app_tab_helper_->IsValidID(app_id)) { 979 TabContents* active_tab = GetLastActiveTabContents(app_id);
976 item.status = ash::STATUS_IS_PENDING; 980 if (active_tab) {
977 } else { 981 Browser* browser = browser::FindBrowserWithWebContents(
978 TabContents* active_tab = GetLastActiveTabContents(app_id); 982 active_tab->web_contents());
979 if (active_tab) { 983 DCHECK(browser);
980 Browser* browser = browser::FindBrowserWithWebContents( 984 if (browser->window()->IsActive())
981 active_tab->web_contents()); 985 status = ash::STATUS_ACTIVE;
982 DCHECK(browser); 986 else
983 if (browser->window()->IsActive()) 987 status = ash::STATUS_RUNNING;
984 status = ash::STATUS_ACTIVE;
985 else
986 status = ash::STATUS_RUNNING;
987 }
988 item.status = status;
989 } 988 }
989 item.status = status;
990
990 model_->AddAt(index, item); 991 model_->AddAt(index, item);
991 992
992 if (!controller || controller->type() != 993 if (!controller || controller->type() !=
993 BrowserLauncherItemController::TYPE_EXTENSION_PANEL) { 994 BrowserLauncherItemController::TYPE_EXTENSION_PANEL) {
994 if (item.status != ash::STATUS_IS_PENDING) 995 app_icon_loader_->FetchImage(app_id);
995 app_icon_loader_->FetchImage(app_id);
996 } 996 }
997 return id; 997 return id;
998 } 998 }
999
1000 void ChromeLauncherController::CheckAppSync() {
1001 if (!observed_sync_service_ ||
1002 model_->ui_state() != ash::LauncherModel::LOADING)
1003 return;
1004
1005 const bool synced = observed_sync_service_->ShouldPushChanges();
1006 const bool has_pending_extension = profile_->GetExtensionService()->
1007 pending_extension_manager()->HasPendingExtensionFromSync();
1008
1009 if (synced && !has_pending_extension)
1010 StopLoadingUI();
1011 }
1012
1013 void ChromeLauncherController::StartLoadingUI() {
1014 if (model_->ui_state() == ash::LauncherModel::LOADING)
1015 return;
1016
1017 model_->SetUIState(ash::LauncherModel::LOADING);
1018
1019 DCHECK(!loading_timer_.IsRunning());
1020 loading_timer_.Start(
1021 FROM_HERE,
1022 base::TimeDelta::FromMilliseconds(kMaxLoadingTimeMs),
1023 this, &ChromeLauncherController::StopLoadingUI);
1024 }
1025
1026 void ChromeLauncherController::StopLoadingUI() {
1027 model_->SetUIState(ash::LauncherModel::NORMAL);
1028 loading_timer_.Stop();
1029 observed_sync_service_->RemoveObserver(this);
1030 observed_sync_service_ = NULL;
1031 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698