diff options
author | simon.hong81@gmail.com <simon.hong81@gmail.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-10-23 17:16:25 +0000 |
---|---|---|
committer | simon.hong81@gmail.com <simon.hong81@gmail.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-10-23 17:16:25 +0000 |
commit | 3fced99a1af83ffc1aa07fec83f96c65c4eaa591 (patch) | |
tree | bb31c35c83af236ee295b93b73025ddccbcace0b /ash | |
parent | 35f1db63561965c8744a23c3eccd89bf944dd070 (diff) | |
download | chromium_src-3fced99a1af83ffc1aa07fec83f96c65c4eaa591.zip chromium_src-3fced99a1af83ffc1aa07fec83f96c65c4eaa591.tar.gz chromium_src-3fced99a1af83ffc1aa07fec83f96c65c4eaa591.tar.bz2 |
Change GetBrowserItemIndex() to GetLauncherItemIndexForType()
Makes GetBrowserItemIndex() more general function to get item index.
Move this function to ./ash/launcher/launcher_item_util.h
R=sky@chromium.org
BUG=NONE
TEST=browser_tests, ash_unittests
Review URL: https://codereview.chromium.org/27369004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@230456 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash')
-rw-r--r-- | ash/ash.gyp | 4 | ||||
-rw-r--r-- | ash/launcher/launcher_model_util.cc (renamed from ash/shelf/shelf_util.cc) | 8 | ||||
-rw-r--r-- | ash/launcher/launcher_model_util.h | 25 | ||||
-rw-r--r-- | ash/shelf/shelf_util.h | 19 | ||||
-rw-r--r-- | ash/shell.cc | 14 | ||||
-rw-r--r-- | ash/test/test_launcher_delegate.cc | 1 |
6 files changed, 36 insertions, 35 deletions
diff --git a/ash/ash.gyp b/ash/ash.gyp index df74c49..d8aeaaa 100644 --- a/ash/ash.gyp +++ b/ash/ash.gyp @@ -162,6 +162,8 @@ 'launcher/launcher_model.cc', 'launcher/launcher_model.h', 'launcher/launcher_model_observer.h', + 'launcher/launcher_model_util.cc', + 'launcher/launcher_model_util.h', 'launcher/launcher_types.cc', 'launcher/launcher_types.h', 'magnifier/magnification_controller.cc', @@ -213,8 +215,6 @@ 'shelf/shelf_tooltip_manager.cc', 'shelf/shelf_tooltip_manager.h', 'shelf/shelf_types.h', - 'shelf/shelf_util.cc', - 'shelf/shelf_util.h', 'shelf/shelf_view.cc', 'shelf/shelf_view.h', 'shelf/shelf_widget.cc', diff --git a/ash/shelf/shelf_util.cc b/ash/launcher/launcher_model_util.cc index 07dfbbe..b1d63a4 100644 --- a/ash/shelf/shelf_util.cc +++ b/ash/launcher/launcher_model_util.cc @@ -2,16 +2,16 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "ash/shelf/shelf_util.h" +#include "ash/launcher/launcher_model_util.h" #include "ash/launcher/launcher_model.h" -#include "ash/launcher/launcher_types.h" namespace ash { -int GetBrowserItemIndex(const LauncherModel& launcher_model) { +int GetLauncherItemIndexForType(LauncherItemType type, + const LauncherModel& launcher_model) { for (size_t i = 0; i < launcher_model.items().size(); i++) { - if (launcher_model.items()[i].type == ash::TYPE_BROWSER_SHORTCUT) + if (launcher_model.items()[i].type == type) return i; } return -1; diff --git a/ash/launcher/launcher_model_util.h b/ash/launcher/launcher_model_util.h new file mode 100644 index 0000000..9cc9932 --- /dev/null +++ b/ash/launcher/launcher_model_util.h @@ -0,0 +1,25 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef ASH_LAUNCHER_LAUNCHER_MODEL_UTIL_H_ +#define ASH_LAUNCHER_LAUNCHER_MODEL_UTIL_H_ + +#include "ash/ash_export.h" +#include "ash/launcher/launcher_types.h" + +namespace ash { + +class LauncherModel; + +// Return the index of the |type| from a given |launcher_model|. +// Note: +// * If there are many items for |type| in the |launcher_model|, an index of +// first item will be returned. +// * If there is no item for |type|, -1 will be returned. +ASH_EXPORT int GetLauncherItemIndexForType(LauncherItemType type, + const LauncherModel& launcher_model); + +} // namespace ash + +#endif // ASH_LAUNCHER_LAUNCHER_MODEL_UTIL_H_ diff --git a/ash/shelf/shelf_util.h b/ash/shelf/shelf_util.h deleted file mode 100644 index daf6c0f..0000000 --- a/ash/shelf/shelf_util.h +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ASH_SHELF_SHELF_UTIL_H_ -#define ASH_SHELF_SHELF_UTIL_H_ - -#include "ash/ash_export.h" - -namespace ash { - -class LauncherModel; - -// Return the index of the browser item from a given |launcher_model|. -ASH_EXPORT int GetBrowserItemIndex(const LauncherModel& launcher_model); - -} // namespace ash - -#endif // ASH_SHELF_SHELF_UTIL_H_ diff --git a/ash/shell.cc b/ash/shell.cc index 6e25c52..b87a946 100644 --- a/ash/shell.cc +++ b/ash/shell.cc @@ -33,6 +33,7 @@ #include "ash/launcher/launcher_item_delegate.h" #include "ash/launcher/launcher_item_delegate_manager.h" #include "ash/launcher/launcher_model.h" +#include "ash/launcher/launcher_model_util.h" #include "ash/magnifier/magnification_controller.h" #include "ash/magnifier/partial_magnification_controller.h" #include "ash/root_window_controller.h" @@ -40,7 +41,6 @@ #include "ash/session_state_delegate.h" #include "ash/shelf/app_list_shelf_item_delegate.h" #include "ash/shelf/shelf_layout_manager.h" -#include "ash/shelf/shelf_util.h" #include "ash/shelf/shelf_widget.h" #include "ash/shell_delegate.h" #include "ash/shell_factory.h" @@ -491,16 +491,12 @@ LauncherDelegate* Shell::GetLauncherDelegate() { scoped_ptr<LauncherItemDelegate> controller( new internal::AppListShelfItemDelegate); - ash::LauncherID app_list_id = 0; - // TODO(simon.hong81): Make function for this in shelf_util.h // Finding the launcher model's location of the app list and setting its // LauncherItemDelegate. - for (size_t i = 0; i < launcher_model_->items().size(); ++i) { - if (launcher_model_->items()[i].type == ash::TYPE_APP_LIST) { - app_list_id = launcher_model_->items()[i].id; - break; - } - } + int app_list_index = + ash::GetLauncherItemIndexForType(ash::TYPE_APP_LIST, *launcher_model_); + DCHECK_GE(app_list_index, 0); + ash::LauncherID app_list_id = launcher_model_->items()[app_list_index].id; DCHECK(app_list_id); launcher_item_delegate_manager_->SetLauncherItemDelegate( app_list_id, diff --git a/ash/test/test_launcher_delegate.cc b/ash/test/test_launcher_delegate.cc index 98f1db0..1867980 100644 --- a/ash/test/test_launcher_delegate.cc +++ b/ash/test/test_launcher_delegate.cc @@ -6,7 +6,6 @@ #include "ash/launcher/launcher_item_delegate_manager.h" #include "ash/launcher/launcher_model.h" -#include "ash/shelf/shelf_util.h" #include "ash/shell.h" #include "ash/test/test_launcher_item_delegate.h" #include "base/strings/string_util.h" |