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 #include "chrome/browser/ui/views/ash/launcher/chrome_launcher_delegate.h" | 5 #include "chrome/browser/ui/views/ash/launcher/chrome_launcher_delegate.h" |
6 | 6 |
7 #include "ash/launcher/launcher_model.h" | 7 #include "ash/launcher/launcher_model.h" |
8 #include "ash/launcher/launcher_types.h" | 8 #include "ash/launcher/launcher_types.h" |
9 #include "ash/wm/window_util.h" | 9 #include "ash/wm/window_util.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 | 115 |
116 // static | 116 // static |
117 void ChromeLauncherDelegate::RegisterUserPrefs(PrefService* user_prefs) { | 117 void ChromeLauncherDelegate::RegisterUserPrefs(PrefService* user_prefs) { |
118 // TODO: If we want to support multiple profiles this will likely need to be | 118 // TODO: If we want to support multiple profiles this will likely need to be |
119 // pushed to local state and we'll need to track profile per item. | 119 // pushed to local state and we'll need to track profile per item. |
120 user_prefs->RegisterListPref(prefs::kPinnedLauncherApps, | 120 user_prefs->RegisterListPref(prefs::kPinnedLauncherApps, |
121 PrefService::SYNCABLE_PREF); | 121 PrefService::SYNCABLE_PREF); |
122 } | 122 } |
123 | 123 |
124 ash::LauncherID ChromeLauncherDelegate::CreateTabbedLauncherItem( | 124 ash::LauncherID ChromeLauncherDelegate::CreateTabbedLauncherItem( |
125 LauncherUpdater* updater, | 125 LauncherUpdater* updater) { |
126 IncognitoState is_incognito) { | |
127 // Tabbed items always get a new item. Put the tabbed item before the app | 126 // Tabbed items always get a new item. Put the tabbed item before the app |
128 // tabs. If there are no app tabs put it at the end. | 127 // tabs. If there are no app tabs put it at the end. |
129 int index = static_cast<int>(model_->items().size()); | 128 int index = static_cast<int>(model_->items().size()); |
130 for (IDToItemMap::const_iterator i = id_to_item_map_.begin(); | 129 for (IDToItemMap::const_iterator i = id_to_item_map_.begin(); |
131 i != id_to_item_map_.end(); ++i) { | 130 i != id_to_item_map_.end(); ++i) { |
132 if (i->second.updater == updater) { | 131 if (i->second.updater == updater) { |
133 DCHECK_EQ(TYPE_APP, i->second.item_type); | 132 DCHECK_EQ(TYPE_APP, i->second.item_type); |
134 index = std::min(index, model_->ItemIndexByID(i->first)); | 133 index = std::min(index, model_->ItemIndexByID(i->first)); |
135 } | 134 } |
136 } | 135 } |
137 ash::LauncherID id = model_->next_id(); | 136 ash::LauncherID id = model_->next_id(); |
138 ash::LauncherItem item; | 137 ash::LauncherItem item(ash::TYPE_TABBED); |
139 item.type = ash::TYPE_TABBED; | |
140 item.is_incognito = (is_incognito == STATE_INCOGNITO); | |
141 item.status = ash::STATUS_RUNNING; | 138 item.status = ash::STATUS_RUNNING; |
142 model_->Add(index, item); | 139 model_->Add(index, item); |
143 DCHECK(id_to_item_map_.find(id) == id_to_item_map_.end()); | 140 DCHECK(id_to_item_map_.find(id) == id_to_item_map_.end()); |
144 id_to_item_map_[id].item_type = TYPE_TABBED_BROWSER; | 141 id_to_item_map_[id].item_type = TYPE_TABBED_BROWSER; |
145 id_to_item_map_[id].updater = updater; | 142 id_to_item_map_[id].updater = updater; |
146 return id; | 143 return id; |
147 } | 144 } |
148 | 145 |
149 ash::LauncherID ChromeLauncherDelegate::CreateAppLauncherItem( | 146 ash::LauncherID ChromeLauncherDelegate::CreateAppLauncherItem( |
150 LauncherUpdater* updater, | 147 LauncherUpdater* updater, |
(...skipping 28 matching lines...) Expand all Loading... |
179 } else { | 176 } else { |
180 min_tab_index = | 177 min_tab_index = |
181 std::min(min_app_index, model_->ItemIndexByID(i->first)); | 178 std::min(min_app_index, model_->ItemIndexByID(i->first)); |
182 } | 179 } |
183 } | 180 } |
184 } | 181 } |
185 } | 182 } |
186 int insert_index = min_app_index != item_count ? | 183 int insert_index = min_app_index != item_count ? |
187 min_app_index : std::min(item_count, min_tab_index + 1); | 184 min_app_index : std::min(item_count, min_tab_index + 1); |
188 ash::LauncherID id = model_->next_id(); | 185 ash::LauncherID id = model_->next_id(); |
189 ash::LauncherItem item; | 186 ash::LauncherItem item(ash::TYPE_APP); |
190 item.type = ash::TYPE_APP; | |
191 item.is_incognito = false; | |
192 item.image = Extension::GetDefaultIcon(true); | 187 item.image = Extension::GetDefaultIcon(true); |
193 item.status = status; | 188 item.status = status; |
194 model_->Add(insert_index, item); | 189 model_->Add(insert_index, item); |
195 DCHECK(id_to_item_map_.find(id) == id_to_item_map_.end()); | 190 DCHECK(id_to_item_map_.find(id) == id_to_item_map_.end()); |
196 id_to_item_map_[id].item_type = TYPE_APP; | 191 id_to_item_map_[id].item_type = TYPE_APP; |
197 id_to_item_map_[id].app_type = app_type; | 192 id_to_item_map_[id].app_type = app_type; |
198 id_to_item_map_[id].app_id = app_id; | 193 id_to_item_map_[id].app_id = app_id; |
199 id_to_item_map_[id].updater = updater; | 194 id_to_item_map_[id].updater = updater; |
200 id_to_item_map_[id].pinned = updater == NULL; | 195 id_to_item_map_[id].pinned = updater == NULL; |
201 | 196 |
(...skipping 21 matching lines...) Expand all Loading... |
223 void ChromeLauncherDelegate::ConvertTabbedToApp(ash::LauncherID id, | 218 void ChromeLauncherDelegate::ConvertTabbedToApp(ash::LauncherID id, |
224 const std::string& app_id, | 219 const std::string& app_id, |
225 AppType app_type) { | 220 AppType app_type) { |
226 DCHECK(id_to_item_map_.find(id) != id_to_item_map_.end()); | 221 DCHECK(id_to_item_map_.find(id) != id_to_item_map_.end()); |
227 DCHECK_EQ(TYPE_TABBED_BROWSER, id_to_item_map_[id].item_type); | 222 DCHECK_EQ(TYPE_TABBED_BROWSER, id_to_item_map_[id].item_type); |
228 DCHECK(!id_to_item_map_[id].pinned); | 223 DCHECK(!id_to_item_map_[id].pinned); |
229 id_to_item_map_[id].item_type = TYPE_APP; | 224 id_to_item_map_[id].item_type = TYPE_APP; |
230 id_to_item_map_[id].app_type = app_type; | 225 id_to_item_map_[id].app_type = app_type; |
231 id_to_item_map_[id].app_id = app_id; | 226 id_to_item_map_[id].app_id = app_id; |
232 | 227 |
233 ash::LauncherItem item; | 228 ash::LauncherItem item(ash::TYPE_APP); |
234 item.type = ash::TYPE_APP; | |
235 item.is_incognito = false; | |
236 item.id = id; | 229 item.id = id; |
237 model_->Set(model_->ItemIndexByID(id), item); | 230 model_->Set(model_->ItemIndexByID(id), item); |
238 | 231 |
239 app_icon_loader_->FetchImage(app_id); | 232 app_icon_loader_->FetchImage(app_id); |
240 } | 233 } |
241 | 234 |
242 void ChromeLauncherDelegate::LauncherItemClosed(ash::LauncherID id) { | 235 void ChromeLauncherDelegate::LauncherItemClosed(ash::LauncherID id) { |
243 DCHECK(id_to_item_map_.find(id) != id_to_item_map_.end()); | 236 DCHECK(id_to_item_map_.find(id) != id_to_item_map_.end()); |
244 if (id_to_item_map_[id].pinned) { | 237 if (id_to_item_map_[id].pinned) { |
245 // The item is pinned, leave it in the launcher. | 238 // The item is pinned, leave it in the launcher. |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
510 Profile* ChromeLauncherDelegate::GetProfileForNewWindows() { | 503 Profile* ChromeLauncherDelegate::GetProfileForNewWindows() { |
511 Profile* profile = ProfileManager::GetDefaultProfile(); | 504 Profile* profile = ProfileManager::GetDefaultProfile(); |
512 if (browser_defaults::kAlwaysOpenIncognitoWindow && | 505 if (browser_defaults::kAlwaysOpenIncognitoWindow && |
513 IncognitoModePrefs::ShouldLaunchIncognito( | 506 IncognitoModePrefs::ShouldLaunchIncognito( |
514 *CommandLine::ForCurrentProcess(), | 507 *CommandLine::ForCurrentProcess(), |
515 profile->GetPrefs())) { | 508 profile->GetPrefs())) { |
516 profile = profile->GetOffTheRecordProfile(); | 509 profile = profile->GetOffTheRecordProfile(); |
517 } | 510 } |
518 return profile; | 511 return profile; |
519 } | 512 } |
OLD | NEW |