Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(92)

Side by Side Diff: chrome/browser/apps/app_shim/extension_app_shim_handler_mac.cc

Issue 2729503007: Remove Profile usage from //apps (Closed)
Patch Set: deps Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/apps/app_shim/extension_app_shim_handler_mac.h" 5 #include "chrome/browser/apps/app_shim/extension_app_shim_handler_mac.h"
6 6
7 #include "apps/app_lifetime_monitor_factory.h" 7 #include "apps/app_lifetime_monitor_factory.h"
8 #include "apps/launcher.h" 8 #include "apps/launcher.h"
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 13 matching lines...) Expand all
24 #include "chrome/browser/ui/extensions/application_launch.h" 24 #include "chrome/browser/ui/extensions/application_launch.h"
25 #include "chrome/browser/ui/extensions/extension_enable_flow.h" 25 #include "chrome/browser/ui/extensions/extension_enable_flow.h"
26 #include "chrome/browser/ui/extensions/extension_enable_flow_delegate.h" 26 #include "chrome/browser/ui/extensions/extension_enable_flow_delegate.h"
27 #include "chrome/browser/ui/user_manager.h" 27 #include "chrome/browser/ui/user_manager.h"
28 #include "chrome/browser/web_applications/web_app_mac.h" 28 #include "chrome/browser/web_applications/web_app_mac.h"
29 #include "chrome/common/extensions/extension_constants.h" 29 #include "chrome/common/extensions/extension_constants.h"
30 #include "chrome/common/extensions/extension_metrics.h" 30 #include "chrome/common/extensions/extension_metrics.h"
31 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" 31 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h"
32 #include "chrome/common/mac/app_shim_messages.h" 32 #include "chrome/common/mac/app_shim_messages.h"
33 #include "components/crx_file/id_util.h" 33 #include "components/crx_file/id_util.h"
34 #include "content/public/browser/browser_context.h"
34 #include "content/public/browser/notification_details.h" 35 #include "content/public/browser/notification_details.h"
35 #include "content/public/browser/notification_service.h" 36 #include "content/public/browser/notification_service.h"
36 #include "content/public/browser/notification_source.h" 37 #include "content/public/browser/notification_source.h"
37 #include "extensions/browser/app_window/app_window.h" 38 #include "extensions/browser/app_window/app_window.h"
38 #include "extensions/browser/app_window/app_window_registry.h" 39 #include "extensions/browser/app_window/app_window_registry.h"
39 #include "extensions/browser/app_window/native_app_window.h" 40 #include "extensions/browser/app_window/native_app_window.h"
40 #include "extensions/browser/extension_host.h" 41 #include "extensions/browser/extension_host.h"
41 #include "extensions/browser/extension_prefs.h" 42 #include "extensions/browser/extension_prefs.h"
42 #include "extensions/browser/extension_registry.h" 43 #include "extensions/browser/extension_registry.h"
43 #include "extensions/common/constants.h" 44 #include "extensions/common/constants.h"
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 return profiles::IsProfileLocked(full_path); 190 return profiles::IsProfileLocked(full_path);
190 } 191 }
191 192
192 AppWindowList ExtensionAppShimHandler::Delegate::GetWindows( 193 AppWindowList ExtensionAppShimHandler::Delegate::GetWindows(
193 Profile* profile, 194 Profile* profile,
194 const std::string& extension_id) { 195 const std::string& extension_id) {
195 return AppWindowRegistry::Get(profile)->GetAppWindowsForApp(extension_id); 196 return AppWindowRegistry::Get(profile)->GetAppWindowsForApp(extension_id);
196 } 197 }
197 198
198 const Extension* ExtensionAppShimHandler::Delegate::MaybeGetAppExtension( 199 const Extension* ExtensionAppShimHandler::Delegate::MaybeGetAppExtension(
199 Profile* profile, 200 content::BrowserContext* context,
200 const std::string& extension_id) { 201 const std::string& extension_id) {
201 return ExtensionAppShimHandler::MaybeGetAppExtension(profile, extension_id); 202 return ExtensionAppShimHandler::MaybeGetAppExtension(context, extension_id);
202 } 203 }
203 204
204 void ExtensionAppShimHandler::Delegate::EnableExtension( 205 void ExtensionAppShimHandler::Delegate::EnableExtension(
205 Profile* profile, 206 Profile* profile,
206 const std::string& extension_id, 207 const std::string& extension_id,
207 const base::Callback<void()>& callback) { 208 const base::Callback<void()>& callback) {
208 (new EnableViaPrompt(profile, extension_id, callback))->Run(); 209 (new EnableViaPrompt(profile, extension_id, callback))->Run();
209 } 210 }
210 211
211 void ExtensionAppShimHandler::Delegate::LaunchApp( 212 void ExtensionAppShimHandler::Delegate::LaunchApp(
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 290
290 if (hidden) 291 if (hidden)
291 browser->window()->Hide(); 292 browser->window()->Hide();
292 else 293 else
293 browser->window()->Show(); 294 browser->window()->Show();
294 } 295 }
295 } 296 }
296 297
297 // static 298 // static
298 const Extension* ExtensionAppShimHandler::MaybeGetAppExtension( 299 const Extension* ExtensionAppShimHandler::MaybeGetAppExtension(
299 Profile* profile, 300 content::BrowserContext* context,
300 const std::string& extension_id) { 301 const std::string& extension_id) {
301 if (!profile) 302 if (!context)
302 return NULL; 303 return NULL;
303 304
304 ExtensionRegistry* registry = ExtensionRegistry::Get(profile); 305 ExtensionRegistry* registry = ExtensionRegistry::Get(context);
305 const Extension* extension = 306 const Extension* extension =
306 registry->GetExtensionById(extension_id, ExtensionRegistry::ENABLED); 307 registry->GetExtensionById(extension_id, ExtensionRegistry::ENABLED);
307 return extension && 308 return extension &&
308 (extension->is_platform_app() || extension->is_hosted_app()) 309 (extension->is_platform_app() || extension->is_hosted_app())
309 ? extension 310 ? extension
310 : NULL; 311 : NULL;
311 } 312 }
312 313
313 // static 314 // static
314 const Extension* ExtensionAppShimHandler::MaybeGetAppForBrowser( 315 const Extension* ExtensionAppShimHandler::MaybeGetAppForBrowser(
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
654 void ExtensionAppShimHandler::Observe( 655 void ExtensionAppShimHandler::Observe(
655 int type, 656 int type,
656 const content::NotificationSource& source, 657 const content::NotificationSource& source,
657 const content::NotificationDetails& details) { 658 const content::NotificationDetails& details) {
658 switch (type) { 659 switch (type) {
659 case chrome::NOTIFICATION_PROFILE_CREATED: { 660 case chrome::NOTIFICATION_PROFILE_CREATED: {
660 Profile* profile = content::Source<Profile>(source).ptr(); 661 Profile* profile = content::Source<Profile>(source).ptr();
661 if (profile->IsOffTheRecord()) 662 if (profile->IsOffTheRecord())
662 return; 663 return;
663 664
664 AppLifetimeMonitorFactory::GetForProfile(profile)->AddObserver(this); 665 AppLifetimeMonitorFactory::GetForBrowserContext(profile)->AddObserver(
666 this);
665 break; 667 break;
666 } 668 }
667 case chrome::NOTIFICATION_PROFILE_DESTROYED: { 669 case chrome::NOTIFICATION_PROFILE_DESTROYED: {
668 Profile* profile = content::Source<Profile>(source).ptr(); 670 Profile* profile = content::Source<Profile>(source).ptr();
669 if (profile->IsOffTheRecord()) 671 if (profile->IsOffTheRecord())
670 return; 672 return;
671 673
672 AppLifetimeMonitorFactory::GetForProfile(profile)->RemoveObserver(this); 674 AppLifetimeMonitorFactory::GetForBrowserContext(profile)->RemoveObserver(
675 this);
673 // Shut down every shim associated with this profile. 676 // Shut down every shim associated with this profile.
674 for (HostMap::iterator it = hosts_.begin(); it != hosts_.end(); ) { 677 for (HostMap::iterator it = hosts_.begin(); it != hosts_.end(); ) {
675 // Increment the iterator first as OnAppClosed may call back to 678 // Increment the iterator first as OnAppClosed may call back to
676 // OnShimClose and invalidate the iterator. 679 // OnShimClose and invalidate the iterator.
677 HostMap::iterator current = it++; 680 HostMap::iterator current = it++;
678 if (profile->IsSameProfile(current->first.first)) { 681 if (profile->IsSameProfile(current->first.first)) {
679 Host* host = current->second; 682 Host* host = current->second;
680 host->OnAppClosed(); 683 host->OnAppClosed();
681 } 684 }
682 } 685 }
(...skipping 13 matching lines...) Expand all
696 699
697 break; 700 break;
698 } 701 }
699 default: { 702 default: {
700 NOTREACHED(); // Unexpected notification. 703 NOTREACHED(); // Unexpected notification.
701 break; 704 break;
702 } 705 }
703 } 706 }
704 } 707 }
705 708
706 void ExtensionAppShimHandler::OnAppStart(Profile* profile, 709 void ExtensionAppShimHandler::OnAppStart(content::BrowserContext* context,
707 const std::string& app_id) {} 710 const std::string& app_id) {}
708 711
709 void ExtensionAppShimHandler::OnAppActivated(Profile* profile, 712 void ExtensionAppShimHandler::OnAppActivated(content::BrowserContext* context,
710 const std::string& app_id) { 713 const std::string& app_id) {
711 const Extension* extension = delegate_->MaybeGetAppExtension(profile, app_id); 714 const Extension* extension = delegate_->MaybeGetAppExtension(context, app_id);
712 if (!extension) 715 if (!extension)
713 return; 716 return;
714 717
718 Profile* profile = static_cast<Profile*>(context);
715 Host* host = FindHost(profile, app_id); 719 Host* host = FindHost(profile, app_id);
716 if (host) { 720 if (host) {
717 host->OnAppLaunchComplete(APP_SHIM_LAUNCH_SUCCESS); 721 host->OnAppLaunchComplete(APP_SHIM_LAUNCH_SUCCESS);
718 OnShimFocus(host, APP_SHIM_FOCUS_NORMAL, std::vector<base::FilePath>()); 722 OnShimFocus(host, APP_SHIM_FOCUS_NORMAL, std::vector<base::FilePath>());
719 return; 723 return;
720 } 724 }
721 725
722 delegate_->LaunchShim(profile, extension); 726 delegate_->LaunchShim(profile, extension);
723 } 727 }
724 728
725 void ExtensionAppShimHandler::OnAppDeactivated(Profile* profile, 729 void ExtensionAppShimHandler::OnAppDeactivated(content::BrowserContext* context,
726 const std::string& app_id) { 730 const std::string& app_id) {
727 Host* host = FindHost(profile, app_id); 731 Host* host = FindHost(static_cast<Profile*>(context), app_id);
728 if (host) 732 if (host)
729 host->OnAppClosed(); 733 host->OnAppClosed();
730 734
731 if (hosts_.empty()) 735 if (hosts_.empty())
732 delegate_->MaybeTerminate(); 736 delegate_->MaybeTerminate();
733 } 737 }
734 738
735 void ExtensionAppShimHandler::OnAppStop(Profile* profile, 739 void ExtensionAppShimHandler::OnAppStop(content::BrowserContext* context,
736 const std::string& app_id) {} 740 const std::string& app_id) {}
737 741
738 // The BrowserWindow may be NULL when this is called. 742 // The BrowserWindow may be NULL when this is called.
739 // Therefore we listen for the notification 743 // Therefore we listen for the notification
740 // chrome::NOTIFICATION_BROWSER_WINDOW_READY and then call OnAppActivated. 744 // chrome::NOTIFICATION_BROWSER_WINDOW_READY and then call OnAppActivated.
741 // If this notification is removed, check that OnBrowserAdded is called after 745 // If this notification is removed, check that OnBrowserAdded is called after
742 // the BrowserWindow is ready. 746 // the BrowserWindow is ready.
743 void ExtensionAppShimHandler::OnBrowserAdded(Browser* browser) { 747 void ExtensionAppShimHandler::OnBrowserAdded(Browser* browser) {
744 } 748 }
745 749
746 void ExtensionAppShimHandler::OnBrowserRemoved(Browser* browser) { 750 void ExtensionAppShimHandler::OnBrowserRemoved(Browser* browser) {
747 const Extension* extension = MaybeGetAppForBrowser(browser); 751 const Extension* extension = MaybeGetAppForBrowser(browser);
748 if (!extension) 752 if (!extension)
749 return; 753 return;
750 754
751 AppBrowserMap::iterator it = app_browser_windows_.find(extension->id()); 755 AppBrowserMap::iterator it = app_browser_windows_.find(extension->id());
752 if (it != app_browser_windows_.end()) { 756 if (it != app_browser_windows_.end()) {
753 BrowserSet& browsers = it->second; 757 BrowserSet& browsers = it->second;
754 browsers.erase(browser); 758 browsers.erase(browser);
755 if (browsers.empty()) 759 if (browsers.empty())
756 OnAppDeactivated(browser->profile(), extension->id()); 760 OnAppDeactivated(browser->profile(), extension->id());
757 } 761 }
758 } 762 }
759 763
760 } // namespace apps 764 } // namespace apps
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698