Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / ui / ash / launcher / launcher_item_controller.h
blobfee31b2ecb1274bb14a548808d0ed4c965006a27
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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_UI_ASH_LAUNCHER_LAUNCHER_ITEM_CONTROLLER_H_
6 #define CHROME_BROWSER_UI_ASH_LAUNCHER_LAUNCHER_ITEM_CONTROLLER_H_
8 #include <string>
10 #include "ash/shelf/shelf_item_delegate.h"
11 #include "ash/shelf/shelf_item_types.h"
12 #include "base/basictypes.h"
13 #include "base/compiler_specific.h"
14 #include "base/memory/scoped_vector.h"
15 #include "base/strings/string16.h"
16 #include "chrome/browser/ui/ash/launcher/chrome_launcher_types.h"
17 #include "ui/events/event.h"
19 class ChromeLauncherController;
20 class ChromeLauncherAppMenuItem;
22 typedef ScopedVector<ChromeLauncherAppMenuItem> ChromeLauncherAppMenuItems;
24 namespace aura {
25 class Window;
28 namespace content {
29 class WebContents;
32 // LauncherItemController is used by ChromeLauncherController to track one
33 // or more windows associated with a shelf item.
34 class LauncherItemController : public ash::ShelfItemDelegate {
35 public:
36 enum Type {
37 TYPE_APP,
38 TYPE_APP_PANEL,
39 TYPE_SHORTCUT,
40 TYPE_WINDOWED_APP
43 LauncherItemController(Type type,
44 const std::string& app_id,
45 ChromeLauncherController* launcher_controller);
46 ~LauncherItemController() override;
48 Type type() const { return type_; }
49 ash::ShelfID shelf_id() const { return shelf_id_; }
50 void set_shelf_id(ash::ShelfID id) { shelf_id_ = id; }
51 virtual const std::string& app_id() const;
52 ChromeLauncherController* launcher_controller() const {
53 return launcher_controller_;
56 // Lock this item to the launcher without being pinned (windowed v1 apps).
57 void lock() { locked_++; }
58 void unlock() {
59 DCHECK(locked_);
60 locked_--;
62 bool locked() { return locked_ > 0; }
64 bool image_set_by_controller() const { return image_set_by_controller_; }
65 void set_image_set_by_controller(bool image_set_by_controller) {
66 image_set_by_controller_ = image_set_by_controller;
69 // Returns true if this item is open.
70 virtual bool IsOpen() const = 0;
72 // Returns true if this item is visible (e.g. not minimized).
73 virtual bool IsVisible() const = 0;
75 // Launches a new instance of the app associated with this item.
76 virtual void Launch(ash::LaunchSource source, int event_flags) = 0;
78 // Shows and activates the most-recently-active window associated with the
79 // item, or launches the item if it is not currently open.
80 // Returns the action performed by activating the item.
81 virtual PerformedAction Activate(ash::LaunchSource source) = 0;
83 // Called to retrieve the list of running applications.
84 virtual ChromeLauncherAppMenuItems GetApplicationList(int event_flags) = 0;
86 // Helper function to get the ash::ShelfItemType for the item type.
87 ash::ShelfItemType GetShelfItemType() const;
89 protected:
90 // Helper function to return the title associated with |app_id_|.
91 // Returns an empty title if no matching extension can be found.
92 base::string16 GetAppTitle() const;
94 private:
95 const Type type_;
96 // App id will be empty if there is no app associated with the window.
97 const std::string app_id_;
98 ash::ShelfID shelf_id_;
99 ChromeLauncherController* launcher_controller_;
101 // The lock counter which tells the launcher if the item can be removed from
102 // the launcher (0) or not (>0). It is being used for windowed V1
103 // applications.
104 int locked_;
106 // Set to true if the launcher item image has been set by the controller.
107 bool image_set_by_controller_;
109 DISALLOW_COPY_AND_ASSIGN(LauncherItemController);
112 #endif // CHROME_BROWSER_UI_ASH_LAUNCHER_LAUNCHER_ITEM_CONTROLLER_H_