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