OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/ash/launcher/browser_status_monitor.h" | 5 #include "chrome/browser/ui/ash/launcher/browser_status_monitor.h" |
6 | 6 |
7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
8 #include "ash/wm/window_util.h" | 8 #include "ash/wm/window_util.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
252 RemoveWebContentsObserver(contents); | 252 RemoveWebContentsObserver(contents); |
253 } | 253 } |
254 | 254 |
255 void BrowserStatusMonitor::AddV1AppToShelf(Browser* browser) { | 255 void BrowserStatusMonitor::AddV1AppToShelf(Browser* browser) { |
256 DCHECK(browser->is_type_popup() && browser->is_app()); | 256 DCHECK(browser->is_type_popup() && browser->is_app()); |
257 DCHECK(initialized_); | 257 DCHECK(initialized_); |
258 | 258 |
259 std::string app_id = | 259 std::string app_id = |
260 web_app::GetExtensionIdFromApplicationName(browser->app_name()); | 260 web_app::GetExtensionIdFromApplicationName(browser->app_name()); |
261 if (!app_id.empty()) { | 261 if (!app_id.empty()) { |
262 if (!IsV1AppInShelfWithAppId(app_id)) | |
263 launcher_controller_->SetV1AppStatus(app_id, ash::STATUS_RUNNING); | |
262 browser_to_app_id_map_[browser] = app_id; | 264 browser_to_app_id_map_[browser] = app_id; |
263 launcher_controller_->LockV1AppWithID(app_id); | |
James Cook
2017/03/31 01:07:41
Like I mentioned on IM, I'm a little concerned in
msw
2017/03/31 03:27:14
This matches the existing behavior. Any popup brow
| |
264 } | 265 } |
265 } | 266 } |
266 | 267 |
267 void BrowserStatusMonitor::RemoveV1AppFromShelf(Browser* browser) { | 268 void BrowserStatusMonitor::RemoveV1AppFromShelf(Browser* browser) { |
268 DCHECK(browser->is_type_popup() && browser->is_app()); | 269 DCHECK(browser->is_type_popup() && browser->is_app()); |
269 DCHECK(initialized_); | 270 DCHECK(initialized_); |
270 | 271 |
271 if (browser_to_app_id_map_.find(browser) != browser_to_app_id_map_.end()) { | 272 auto iter = browser_to_app_id_map_.find(browser); |
272 launcher_controller_->UnlockV1AppWithID(browser_to_app_id_map_[browser]); | 273 if (iter != browser_to_app_id_map_.end()) { |
273 browser_to_app_id_map_.erase(browser); | 274 std::string app_id = iter->second; |
275 browser_to_app_id_map_.erase(iter); | |
276 if (!IsV1AppInShelfWithAppId(app_id)) | |
277 launcher_controller_->SetV1AppStatus(app_id, ash::STATUS_CLOSED); | |
274 } | 278 } |
275 } | 279 } |
276 | 280 |
277 bool BrowserStatusMonitor::IsV1AppInShelf(Browser* browser) { | 281 bool BrowserStatusMonitor::IsV1AppInShelf(Browser* browser) { |
278 return browser_to_app_id_map_.find(browser) != browser_to_app_id_map_.end(); | 282 return browser_to_app_id_map_.find(browser) != browser_to_app_id_map_.end(); |
279 } | 283 } |
280 | 284 |
285 bool BrowserStatusMonitor::IsV1AppInShelfWithAppId(std::string app_id) { | |
286 for (const auto& iter : browser_to_app_id_map_) { | |
James Cook
2017/03/31 01:07:41
optional: stl_util.h base::ContainsValue()
msw
2017/03/31 03:27:14
Unfortunately I'm looking for a map *value* matchi
| |
287 if (iter.second == app_id) | |
288 return true; | |
289 } | |
290 return false; | |
291 } | |
292 | |
281 void BrowserStatusMonitor::AddWebContentsObserver( | 293 void BrowserStatusMonitor::AddWebContentsObserver( |
282 content::WebContents* contents) { | 294 content::WebContents* contents) { |
283 if (webcontents_to_observer_map_.find(contents) == | 295 if (webcontents_to_observer_map_.find(contents) == |
284 webcontents_to_observer_map_.end()) { | 296 webcontents_to_observer_map_.end()) { |
285 webcontents_to_observer_map_[contents] = | 297 webcontents_to_observer_map_[contents] = |
286 base::MakeUnique<LocalWebContentsObserver>(contents, this); | 298 base::MakeUnique<LocalWebContentsObserver>(contents, this); |
287 } | 299 } |
288 } | 300 } |
289 | 301 |
290 void BrowserStatusMonitor::RemoveWebContentsObserver( | 302 void BrowserStatusMonitor::RemoveWebContentsObserver( |
291 content::WebContents* contents) { | 303 content::WebContents* contents) { |
292 DCHECK(webcontents_to_observer_map_.find(contents) != | 304 DCHECK(webcontents_to_observer_map_.find(contents) != |
293 webcontents_to_observer_map_.end()); | 305 webcontents_to_observer_map_.end()); |
294 webcontents_to_observer_map_.erase(contents); | 306 webcontents_to_observer_map_.erase(contents); |
295 } | 307 } |
296 | 308 |
297 ash::ShelfID BrowserStatusMonitor::GetShelfIDForWebContents( | 309 ash::ShelfID BrowserStatusMonitor::GetShelfIDForWebContents( |
298 content::WebContents* contents) { | 310 content::WebContents* contents) { |
299 return launcher_controller_->GetShelfIDForWebContents(contents); | 311 return launcher_controller_->GetShelfIDForWebContents(contents); |
300 } | 312 } |
301 | 313 |
302 void BrowserStatusMonitor::SetShelfIDForBrowserWindowContents( | 314 void BrowserStatusMonitor::SetShelfIDForBrowserWindowContents( |
303 Browser* browser, | 315 Browser* browser, |
304 content::WebContents* web_contents) { | 316 content::WebContents* web_contents) { |
305 launcher_controller_->GetBrowserShortcutLauncherItemController()-> | 317 launcher_controller_->GetBrowserShortcutLauncherItemController()-> |
306 SetShelfIDForBrowserWindowContents(browser, web_contents); | 318 SetShelfIDForBrowserWindowContents(browser, web_contents); |
307 } | 319 } |
OLD | NEW |