OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "mash/quick_launch/quick_launch.h" | 5 #include "mash/quick_launch/quick_launch.h" |
6 | 6 |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/strings/string16.h" | 9 #include "base/strings/string16.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 class AuraInit; | 28 class AuraInit; |
29 } | 29 } |
30 | 30 |
31 namespace mash { | 31 namespace mash { |
32 namespace quick_launch { | 32 namespace quick_launch { |
33 | 33 |
34 class QuickLaunchUI : public views::WidgetDelegateView, | 34 class QuickLaunchUI : public views::WidgetDelegateView, |
35 public views::TextfieldController { | 35 public views::TextfieldController { |
36 public: | 36 public: |
37 QuickLaunchUI(QuickLaunch* quick_launch, | 37 QuickLaunchUI(QuickLaunch* quick_launch, |
38 shell::Connector* connector, | 38 service_manager::Connector* connector, |
39 catalog::mojom::CatalogPtr catalog) | 39 catalog::mojom::CatalogPtr catalog) |
40 : quick_launch_(quick_launch), | 40 : quick_launch_(quick_launch), |
41 connector_(connector), | 41 connector_(connector), |
42 prompt_(new views::Textfield), | 42 prompt_(new views::Textfield), |
43 catalog_(std::move(catalog)) { | 43 catalog_(std::move(catalog)) { |
44 set_background(views::Background::CreateStandardPanelBackground()); | 44 set_background(views::Background::CreateStandardPanelBackground()); |
45 prompt_->set_controller(this); | 45 prompt_->set_controller(this); |
46 AddChildView(prompt_); | 46 AddChildView(prompt_); |
47 | 47 |
48 UpdateEntries(); | 48 UpdateEntries(); |
49 } | 49 } |
50 ~QuickLaunchUI() override { | 50 ~QuickLaunchUI() override { |
51 quick_launch_->RemoveWindow(GetWidget()); | 51 quick_launch_->RemoveWindow(GetWidget()); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 base::Bind(&QuickLaunchUI::OnGotCatalogEntries, | 124 base::Bind(&QuickLaunchUI::OnGotCatalogEntries, |
125 base::Unretained(this))); | 125 base::Unretained(this))); |
126 } | 126 } |
127 | 127 |
128 void OnGotCatalogEntries(std::vector<catalog::mojom::EntryPtr> entries) { | 128 void OnGotCatalogEntries(std::vector<catalog::mojom::EntryPtr> entries) { |
129 for (const auto& entry : entries) | 129 for (const auto& entry : entries) |
130 app_names_.insert(base::UTF8ToUTF16(entry->name)); | 130 app_names_.insert(base::UTF8ToUTF16(entry->name)); |
131 } | 131 } |
132 | 132 |
133 void Launch(const std::string& name, bool new_window) { | 133 void Launch(const std::string& name, bool new_window) { |
134 std::unique_ptr<shell::Connection> connection = connector_->Connect(name); | 134 std::unique_ptr<service_manager::Connection> connection = |
| 135 connector_->Connect(name); |
135 mojom::LaunchablePtr launchable; | 136 mojom::LaunchablePtr launchable; |
136 connection->GetInterface(&launchable); | 137 connection->GetInterface(&launchable); |
137 connections_.push_back(std::move(connection)); | 138 connections_.push_back(std::move(connection)); |
138 launchable->Launch(mojom::kWindow, | 139 launchable->Launch(mojom::kWindow, |
139 new_window ? mojom::LaunchMode::MAKE_NEW | 140 new_window ? mojom::LaunchMode::MAKE_NEW |
140 : mojom::LaunchMode::REUSE); | 141 : mojom::LaunchMode::REUSE); |
141 } | 142 } |
142 | 143 |
143 QuickLaunch* quick_launch_; | 144 QuickLaunch* quick_launch_; |
144 shell::Connector* connector_; | 145 service_manager::Connector* connector_; |
145 views::Textfield* prompt_; | 146 views::Textfield* prompt_; |
146 std::vector<std::unique_ptr<shell::Connection>> connections_; | 147 std::vector<std::unique_ptr<service_manager::Connection>> connections_; |
147 catalog::mojom::CatalogPtr catalog_; | 148 catalog::mojom::CatalogPtr catalog_; |
148 std::set<base::string16> app_names_; | 149 std::set<base::string16> app_names_; |
149 bool suggestion_rejected_ = false; | 150 bool suggestion_rejected_ = false; |
150 | 151 |
151 DISALLOW_COPY_AND_ASSIGN(QuickLaunchUI); | 152 DISALLOW_COPY_AND_ASSIGN(QuickLaunchUI); |
152 }; | 153 }; |
153 | 154 |
154 QuickLaunch::QuickLaunch() {} | 155 QuickLaunch::QuickLaunch() {} |
155 QuickLaunch::~QuickLaunch() {} | 156 QuickLaunch::~QuickLaunch() {} |
156 | 157 |
157 void QuickLaunch::RemoveWindow(views::Widget* window) { | 158 void QuickLaunch::RemoveWindow(views::Widget* window) { |
158 auto it = std::find(windows_.begin(), windows_.end(), window); | 159 auto it = std::find(windows_.begin(), windows_.end(), window); |
159 DCHECK(it != windows_.end()); | 160 DCHECK(it != windows_.end()); |
160 windows_.erase(it); | 161 windows_.erase(it); |
161 if (windows_.empty() && base::MessageLoop::current()->is_running()) | 162 if (windows_.empty() && base::MessageLoop::current()->is_running()) |
162 base::MessageLoop::current()->QuitWhenIdle(); | 163 base::MessageLoop::current()->QuitWhenIdle(); |
163 } | 164 } |
164 | 165 |
165 void QuickLaunch::OnStart(const shell::Identity& identity) { | 166 void QuickLaunch::OnStart(const service_manager::Identity& identity) { |
166 tracing_.Initialize(connector(), identity.name()); | 167 tracing_.Initialize(connector(), identity.name()); |
167 | 168 |
168 aura_init_.reset( | 169 aura_init_.reset( |
169 new views::AuraInit(connector(), "views_mus_resources.pak")); | 170 new views::AuraInit(connector(), "views_mus_resources.pak")); |
170 window_manager_connection_ = | 171 window_manager_connection_ = |
171 views::WindowManagerConnection::Create(connector(), identity); | 172 views::WindowManagerConnection::Create(connector(), identity); |
172 | 173 |
173 Launch(mojom::kWindow, mojom::LaunchMode::MAKE_NEW); | 174 Launch(mojom::kWindow, mojom::LaunchMode::MAKE_NEW); |
174 } | 175 } |
175 | 176 |
176 bool QuickLaunch::OnConnect(const shell::Identity& remote_identity, | 177 bool QuickLaunch::OnConnect(const service_manager::Identity& remote_identity, |
177 shell::InterfaceRegistry* registry) { | 178 service_manager::InterfaceRegistry* registry) { |
178 registry->AddInterface<mojom::Launchable>(this); | 179 registry->AddInterface<mojom::Launchable>(this); |
179 return true; | 180 return true; |
180 } | 181 } |
181 | 182 |
182 void QuickLaunch::Launch(uint32_t what, mojom::LaunchMode how) { | 183 void QuickLaunch::Launch(uint32_t what, mojom::LaunchMode how) { |
183 bool reuse = how == mojom::LaunchMode::REUSE || | 184 bool reuse = how == mojom::LaunchMode::REUSE || |
184 how == mojom::LaunchMode::DEFAULT; | 185 how == mojom::LaunchMode::DEFAULT; |
185 if (reuse && !windows_.empty()) { | 186 if (reuse && !windows_.empty()) { |
186 windows_.back()->Activate(); | 187 windows_.back()->Activate(); |
187 return; | 188 return; |
188 } | 189 } |
189 catalog::mojom::CatalogPtr catalog; | 190 catalog::mojom::CatalogPtr catalog; |
190 connector()->ConnectToInterface("service:catalog", &catalog); | 191 connector()->ConnectToInterface("service:catalog", &catalog); |
191 | 192 |
192 views::Widget* window = views::Widget::CreateWindowWithContextAndBounds( | 193 views::Widget* window = views::Widget::CreateWindowWithContextAndBounds( |
193 new QuickLaunchUI(this, connector(), std::move(catalog)), | 194 new QuickLaunchUI(this, connector(), std::move(catalog)), |
194 nullptr, gfx::Rect(10, 640, 0, 0)); | 195 nullptr, gfx::Rect(10, 640, 0, 0)); |
195 window->Show(); | 196 window->Show(); |
196 windows_.push_back(window); | 197 windows_.push_back(window); |
197 } | 198 } |
198 | 199 |
199 void QuickLaunch::Create(const shell::Identity& remote_identity, | 200 void QuickLaunch::Create(const service_manager::Identity& remote_identity, |
200 mojom::LaunchableRequest request) { | 201 mojom::LaunchableRequest request) { |
201 bindings_.AddBinding(this, std::move(request)); | 202 bindings_.AddBinding(this, std::move(request)); |
202 } | 203 } |
203 | 204 |
204 } // namespace quick_launch | 205 } // namespace quick_launch |
205 } // namespace mash | 206 } // namespace mash |
OLD | NEW |