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

Unified Diff: chrome/browser/ui/views/ash/launcher/chrome_launcher_delegate.cc

Issue 9808073: okashii (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: a Created 8 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/views/ash/launcher/chrome_launcher_delegate.cc
diff --git a/chrome/browser/ui/views/ash/launcher/chrome_launcher_delegate.cc b/chrome/browser/ui/views/ash/launcher/chrome_launcher_delegate.cc
index 161d1ad1bf8994e268b66188bc10baaa474a3019..8c39286c93fef9eacb8eac5a1d7e5ae39f4b6ad1 100644
--- a/chrome/browser/ui/views/ash/launcher/chrome_launcher_delegate.cc
+++ b/chrome/browser/ui/views/ash/launcher/chrome_launcher_delegate.cc
@@ -69,17 +69,16 @@ ChromeLauncherDelegate::ChromeLauncherDelegate(Profile* profile,
ash::LauncherModel* model)
: model_(model),
profile_(profile) {
- if (!profile_) {
- // Use the original profile as on chromeos we may get a temporary off the
- // record profile.
- profile_ = ProfileManager::GetDefaultProfile()->GetOriginalProfile();
- }
instance_ = this;
model_->AddObserver(this);
- app_icon_loader_.reset(new LauncherAppIconLoader(profile_, this));
- registrar_.Add(this,
- chrome::NOTIFICATION_EXTENSION_UNLOADED,
- content::Source<Profile>(profile_));
+
+ if (profile) {
+ PostProfileInit();
+ } else {
+ registrar_.Add(this,
+ chrome::NOTIFICATION_PROFILE_CREATED,
+ content::NotificationService::AllSources());
+ }
}
ChromeLauncherDelegate::~ChromeLauncherDelegate() {
@@ -92,29 +91,6 @@ ChromeLauncherDelegate::~ChromeLauncherDelegate() {
instance_ = NULL;
}
-void ChromeLauncherDelegate::Init() {
- const base::ListValue* pinned_apps =
- profile_->GetPrefs()->GetList(prefs::kPinnedLauncherApps);
- for (size_t i = 0; i < pinned_apps->GetSize(); ++i) {
- DictionaryValue* app = NULL;
- if (pinned_apps->GetDictionary(i, &app)) {
- std::string app_id, type_string;
- if (app->GetString(kAppIDPath, &app_id) &&
- app->GetString(kAppTypePath, &type_string) &&
- app_icon_loader_->IsValidID(app_id)) {
- AppType app_type;
- if (type_string == kAppTypeWindow)
- app_type = APP_TYPE_WINDOW;
- else if (type_string == kAppTypePanel)
- app_type = APP_TYPE_APP_PANEL;
- else
- app_type = APP_TYPE_TAB;
- CreateAppLauncherItem(NULL, app_id, app_type, ash::STATUS_CLOSED);
- }
- }
- }
-}
-
// static
void ChromeLauncherDelegate::RegisterUserPrefs(PrefService* user_prefs) {
// TODO: If we want to support multiple profiles this will likely need to be
@@ -153,6 +129,7 @@ ash::LauncherID ChromeLauncherDelegate::CreateAppLauncherItem(
const std::string& app_id,
AppType app_type,
ash::LauncherItemStatus status) {
+ DCHECK(profile_);
// See if we have a closed item that matches the app.
if (updater) {
for (IDToItemMap::iterator i = id_to_item_map_.begin();
@@ -229,6 +206,7 @@ void ChromeLauncherDelegate::ConvertTabbedToApp(ash::LauncherID id,
DCHECK(id_to_item_map_.find(id) != id_to_item_map_.end());
DCHECK_EQ(TYPE_TABBED_BROWSER, id_to_item_map_[id].item_type);
DCHECK(!id_to_item_map_[id].pinned);
+ DCHECK(profile_);
id_to_item_map_[id].item_type = TYPE_APP;
id_to_item_map_[id].app_type = app_type;
id_to_item_map_[id].app_id = app_id;
@@ -257,6 +235,7 @@ void ChromeLauncherDelegate::LauncherItemClosed(ash::LauncherID id) {
void ChromeLauncherDelegate::AppIDChanged(ash::LauncherID id,
const std::string& app_id) {
DCHECK(id_to_item_map_.find(id) != id_to_item_map_.end());
+ DCHECK(profile_);
id_to_item_map_[id].app_id = app_id;
PersistPinnedState();
@@ -312,6 +291,8 @@ bool ChromeLauncherDelegate::IsPinnable(ash::LauncherID id) {
}
void ChromeLauncherDelegate::Open(ash::LauncherID id) {
+ DCHECK(profile_);
+
if (id_to_item_map_.find(id) == id_to_item_map_.end())
return; // In case invoked from menu and item closed while menu up.
@@ -387,6 +368,7 @@ ChromeLauncherDelegate::AppType ChromeLauncherDelegate::GetAppType(
}
std::string ChromeLauncherDelegate::GetAppID(TabContentsWrapper* tab) {
+ DCHECK(profile_);
return app_icon_loader_->GetAppID(tab);
}
@@ -424,6 +406,7 @@ int ChromeLauncherDelegate::GetBrowserShortcutResourceId() {
string16 ChromeLauncherDelegate::GetTitle(const ash::LauncherItem& item) {
DCHECK(id_to_item_map_.find(item.id) != id_to_item_map_.end());
+ DCHECK(profile_);
LauncherUpdater* updater = id_to_item_map_[item.id].updater;
if (updater) {
if (id_to_item_map_[item.id].item_type == TYPE_TABBED_BROWSER) {
@@ -493,10 +476,34 @@ void ChromeLauncherDelegate::Observe(
int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
- DCHECK_EQ(type, chrome::NOTIFICATION_EXTENSION_UNLOADED);
- const Extension* extension =
- content::Details<UnloadedExtensionInfo>(details)->extension;
- UnpinAppsWithID(extension->id());
+ switch (type) {
+ case chrome::NOTIFICATION_EXTENSION_UNLOADED: {
+ const Extension* extension =
+ content::Details<UnloadedExtensionInfo>(details)->extension;
+ UnpinAppsWithID(extension->id());
+ break;
+ }
+ case chrome::NOTIFICATION_PROFILE_CREATED: {
+ profile_ = content::Source<Profile>(source)->GetOriginalProfile();
+ PostProfileInit();
+
+ registrar_.Remove(this,
+ chrome::NOTIFICATION_PROFILE_CREATED,
+ content::NotificationService::AllSources());
+ break;
+ }
+ default:
+ NOTREACHED();
+ }
+}
+
+void ChromeLauncherDelegate::PostProfileInit() {
+ DCHECK(profile_);
+ SetAppIconLoader(new LauncherAppIconLoader(profile_, this));
+
+ registrar_.Add(this,
+ chrome::NOTIFICATION_EXTENSION_UNLOADED,
+ content::Source<Profile>(profile_));
}
void ChromeLauncherDelegate::PersistPinnedState() {
@@ -538,8 +545,30 @@ void ChromeLauncherDelegate::UnpinAppsWithID(const std::string& app_id) {
}
}
-void ChromeLauncherDelegate::SetAppIconLoaderForTest(AppIconLoader* loader) {
+void ChromeLauncherDelegate::SetAppIconLoader(AppIconLoader* loader) {
+ DCHECK(profile_);
app_icon_loader_.reset(loader);
+
+ const base::ListValue* pinned_apps =
+ profile_->GetPrefs()->GetList(prefs::kPinnedLauncherApps);
+ for (size_t i = 0; i < pinned_apps->GetSize(); ++i) {
+ DictionaryValue* app = NULL;
+ if (pinned_apps->GetDictionary(i, &app)) {
+ std::string app_id, type_string;
+ if (app->GetString(kAppIDPath, &app_id) &&
+ app->GetString(kAppTypePath, &type_string) &&
+ app_icon_loader_->IsValidID(app_id)) {
+ AppType app_type;
+ if (type_string == kAppTypeWindow)
+ app_type = APP_TYPE_WINDOW;
+ else if (type_string == kAppTypePanel)
+ app_type = APP_TYPE_APP_PANEL;
+ else
+ app_type = APP_TYPE_TAB;
+ CreateAppLauncherItem(NULL, app_id, app_type, ash::STATUS_CLOSED);
+ }
+ }
+ }
}
Profile* ChromeLauncherDelegate::GetProfileForNewWindows() {

Powered by Google App Engine
This is Rietveld 408576698