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/launcher_updater.h" | 5 #include "chrome/browser/ui/views/ash/launcher/launcher_updater.h" |
6 | 6 |
7 #include "ash/launcher/launcher.h" | 7 #include "ash/launcher/launcher.h" |
8 #include "ash/launcher/launcher_model.h" | 8 #include "ash/launcher/launcher_model.h" |
9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
10 #include "ash/wm/window_util.h" | 10 #include "ash/wm/window_util.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 LauncherUpdater::LauncherUpdater(aura::Window* window, | 31 LauncherUpdater::LauncherUpdater(aura::Window* window, |
32 TabStripModel* tab_model, | 32 TabStripModel* tab_model, |
33 ChromeLauncherDelegate* delegate, | 33 ChromeLauncherDelegate* delegate, |
34 Type type, | 34 Type type, |
35 const std::string& app_id) | 35 const std::string& app_id) |
36 : window_(window), | 36 : window_(window), |
37 tab_model_(tab_model), | 37 tab_model_(tab_model), |
38 launcher_delegate_(delegate), | 38 launcher_delegate_(delegate), |
39 type_(type), | 39 type_(type), |
40 app_id_(app_id), | 40 app_id_(app_id), |
41 is_incognito_(tab_model->profile()->GetOriginalProfile() != | |
42 tab_model->profile()), | |
43 item_id_(-1) { | 41 item_id_(-1) { |
44 } | 42 } |
45 | 43 |
46 LauncherUpdater::~LauncherUpdater() { | 44 LauncherUpdater::~LauncherUpdater() { |
47 tab_model_->RemoveObserver(this); | 45 tab_model_->RemoveObserver(this); |
48 if (item_id_ != -1) | 46 if (item_id_ != -1) |
49 launcher_delegate_->LauncherItemClosed(item_id_); | 47 launcher_delegate_->LauncherItemClosed(item_id_); |
50 for (AppTabMap::iterator i = app_map_.begin(); i != app_map_.end(); ++i) | 48 for (AppTabMap::iterator i = app_map_.begin(); i != app_map_.end(); ++i) |
51 launcher_delegate_->LauncherItemClosed(i->second.id); | 49 launcher_delegate_->LauncherItemClosed(i->second.id); |
52 } | 50 } |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 if (!launcher_delegate_->IsPinned(launcher_id)) { | 265 if (!launcher_delegate_->IsPinned(launcher_id)) { |
268 // Swap the item for a tabbed item. | 266 // Swap the item for a tabbed item. |
269 item_id_ = launcher_id; | 267 item_id_ = launcher_id; |
270 launcher_delegate_->ConvertAppToTabbed(item_id_); | 268 launcher_delegate_->ConvertAppToTabbed(item_id_); |
271 } else { | 269 } else { |
272 // If the app is pinned we have to leave it and create a new tabbed | 270 // If the app is pinned we have to leave it and create a new tabbed |
273 // item. | 271 // item. |
274 launcher_delegate_->LauncherItemClosed(launcher_id); | 272 launcher_delegate_->LauncherItemClosed(launcher_id); |
275 CreateTabbedItem(); | 273 CreateTabbedItem(); |
276 } | 274 } |
277 ash::LauncherItem item; | 275 ash::LauncherItem item(ash::TYPE_TABBED); |
278 item.type = ash::TYPE_TABBED; | |
279 item.is_incognito = is_incognito_; | |
280 item.num_tabs = tab_model_->count(); | 276 item.num_tabs = tab_model_->count(); |
281 launcher_model()->Set(launcher_model()->ItemIndexByID(item_id_), item); | 277 launcher_model()->Set(launcher_model()->ItemIndexByID(item_id_), item); |
282 } else { | 278 } else { |
283 // We have a tabbed item, so we can remove the the app item. | 279 // We have a tabbed item, so we can remove the the app item. |
284 launcher_delegate_->LauncherItemClosed(launcher_id); | 280 launcher_delegate_->LauncherItemClosed(launcher_id); |
285 } | 281 } |
286 } else { | 282 } else { |
287 // Going from not showing to showing. | 283 // Going from not showing to showing. |
288 if (item_id_ != -1 && | 284 if (item_id_ != -1 && |
289 static_cast<int>(app_map_.size()) + 1 == tab_model_->count()) { | 285 static_cast<int>(app_map_.size()) + 1 == tab_model_->count()) { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 void LauncherUpdater::RegisterAppItem(ash::LauncherID id, | 318 void LauncherUpdater::RegisterAppItem(ash::LauncherID id, |
323 TabContentsWrapper* tab) { | 319 TabContentsWrapper* tab) { |
324 AppTabDetails details; | 320 AppTabDetails details; |
325 details.id = id; | 321 details.id = id; |
326 details.app_id = launcher_delegate_->GetAppID(tab); | 322 details.app_id = launcher_delegate_->GetAppID(tab); |
327 app_map_[tab] = details; | 323 app_map_[tab] = details; |
328 } | 324 } |
329 | 325 |
330 void LauncherUpdater::CreateTabbedItem() { | 326 void LauncherUpdater::CreateTabbedItem() { |
331 DCHECK_EQ(-1, item_id_); | 327 DCHECK_EQ(-1, item_id_); |
332 item_id_ = launcher_delegate_->CreateTabbedLauncherItem( | 328 item_id_ = launcher_delegate_->CreateTabbedLauncherItem(this); |
333 this, | |
334 is_incognito_ ? ChromeLauncherDelegate::STATE_INCOGNITO : | |
335 ChromeLauncherDelegate::STATE_NOT_INCOGNITO); | |
336 } | 329 } |
337 | 330 |
338 bool LauncherUpdater::ContainsID(ash::LauncherID id, TabContentsWrapper** tab) { | 331 bool LauncherUpdater::ContainsID(ash::LauncherID id, TabContentsWrapper** tab) { |
339 if (item_id_ == id) | 332 if (item_id_ == id) |
340 return true; | 333 return true; |
341 for (AppTabMap::const_iterator i = app_map_.begin(); i != app_map_.end(); | 334 for (AppTabMap::const_iterator i = app_map_.begin(); i != app_map_.end(); |
342 ++i) { | 335 ++i) { |
343 if (i->second.id == id) { | 336 if (i->second.id == id) { |
344 *tab = i->first; | 337 *tab = i->first; |
345 return true; | 338 return true; |
346 } | 339 } |
347 } | 340 } |
348 return false; | 341 return false; |
349 } | 342 } |
350 | 343 |
351 ash::LauncherModel* LauncherUpdater::launcher_model() { | 344 ash::LauncherModel* LauncherUpdater::launcher_model() { |
352 return launcher_delegate_->model(); | 345 return launcher_delegate_->model(); |
353 } | 346 } |
OLD | NEW |