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

Unified Diff: apps/app_shim/app_shim_handler_mac.cc

Issue 585123004: Mac: Give app_shim code a nicer home (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: various cleanups Created 6 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « apps/app_shim/app_shim_handler_mac.h ('k') | apps/app_shim/app_shim_host_mac.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: apps/app_shim/app_shim_handler_mac.cc
diff --git a/apps/app_shim/app_shim_handler_mac.cc b/apps/app_shim/app_shim_handler_mac.cc
deleted file mode 100644
index 3153bd4c591dbe02b56bb6dda1068e355fa4a45e..0000000000000000000000000000000000000000
--- a/apps/app_shim/app_shim_handler_mac.cc
+++ /dev/null
@@ -1,156 +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.
-
-#include "apps/app_shim/app_shim_handler_mac.h"
-
-#include <map>
-
-#include "base/bind.h"
-#include "base/logging.h"
-#include "base/memory/singleton.h"
-#include "base/message_loop/message_loop.h"
-#include "chrome/browser/chrome_notification_types.h"
-#include "chrome/browser/lifetime/application_lifetime.h"
-#include "chrome/browser/ui/app_list/app_list_service.h"
-#include "content/public/browser/notification_observer.h"
-#include "content/public/browser/notification_registrar.h"
-#include "content/public/browser/notification_service.h"
-#include "extensions/browser/app_window/app_window_registry.h"
-
-namespace apps {
-
-namespace {
-
-void TerminateIfNoAppWindows() {
- bool app_windows_left =
- extensions::AppWindowRegistry::IsAppWindowRegisteredInAnyProfile(0);
- if (!app_windows_left &&
- !AppListService::Get(chrome::HOST_DESKTOP_TYPE_NATIVE)
- ->IsAppListVisible()) {
- chrome::AttemptExit();
- }
-}
-
-class AppShimHandlerRegistry : public content::NotificationObserver {
- public:
- static AppShimHandlerRegistry* GetInstance() {
- return Singleton<AppShimHandlerRegistry,
- LeakySingletonTraits<AppShimHandlerRegistry> >::get();
- }
-
- AppShimHandler* GetForAppMode(const std::string& app_mode_id) const {
- HandlerMap::const_iterator it = handlers_.find(app_mode_id);
- if (it != handlers_.end())
- return it->second;
-
- return default_handler_;
- }
-
- bool SetForAppMode(const std::string& app_mode_id, AppShimHandler* handler) {
- bool inserted_or_removed = handler ?
- handlers_.insert(HandlerMap::value_type(app_mode_id, handler)).second :
- handlers_.erase(app_mode_id) == 1;
- DCHECK(inserted_or_removed);
- return inserted_or_removed;
- }
-
- void SetDefaultHandler(AppShimHandler* handler) {
- DCHECK_NE(default_handler_ == NULL, handler == NULL);
- default_handler_ = handler;
- }
-
- void MaybeTerminate() {
- if (!browser_session_running_) {
- // Post this to give AppWindows a chance to remove themselves from the
- // registry.
- base::MessageLoop::current()->PostTask(
- FROM_HERE, base::Bind(&TerminateIfNoAppWindows));
- }
- }
-
- bool ShouldRestoreSession() {
- return !browser_session_running_;
- }
-
- private:
- friend struct DefaultSingletonTraits<AppShimHandlerRegistry>;
- typedef std::map<std::string, AppShimHandler*> HandlerMap;
-
- AppShimHandlerRegistry()
- : default_handler_(NULL),
- browser_session_running_(false) {
- registrar_.Add(
- this, chrome::NOTIFICATION_BROWSER_OPENED,
- content::NotificationService::AllBrowserContextsAndSources());
- registrar_.Add(
- this, chrome::NOTIFICATION_CLOSE_ALL_BROWSERS_REQUEST,
- content::NotificationService::AllBrowserContextsAndSources());
- registrar_.Add(
- this, chrome::NOTIFICATION_BROWSER_CLOSE_CANCELLED,
- content::NotificationService::AllBrowserContextsAndSources());
- }
-
- virtual ~AppShimHandlerRegistry() {}
-
- // content::NotificationObserver override:
- virtual void Observe(
- int type,
- const content::NotificationSource& source,
- const content::NotificationDetails& details) OVERRIDE {
- switch (type) {
- case chrome::NOTIFICATION_BROWSER_OPENED:
- case chrome::NOTIFICATION_BROWSER_CLOSE_CANCELLED:
- browser_session_running_ = true;
- break;
- case chrome::NOTIFICATION_CLOSE_ALL_BROWSERS_REQUEST:
- browser_session_running_ = false;
- break;
- default:
- NOTREACHED();
- }
- }
-
- HandlerMap handlers_;
- AppShimHandler* default_handler_;
- content::NotificationRegistrar registrar_;
- bool browser_session_running_;
-
- DISALLOW_COPY_AND_ASSIGN(AppShimHandlerRegistry);
-};
-
-} // namespace
-
-// static
-void AppShimHandler::RegisterHandler(const std::string& app_mode_id,
- AppShimHandler* handler) {
- DCHECK(handler);
- AppShimHandlerRegistry::GetInstance()->SetForAppMode(app_mode_id, handler);
-}
-
-// static
-void AppShimHandler::RemoveHandler(const std::string& app_mode_id) {
- AppShimHandlerRegistry::GetInstance()->SetForAppMode(app_mode_id, NULL);
-}
-
-// static
-AppShimHandler* AppShimHandler::GetForAppMode(const std::string& app_mode_id) {
- return AppShimHandlerRegistry::GetInstance()->GetForAppMode(app_mode_id);
-}
-
-// static
-void AppShimHandler::SetDefaultHandler(AppShimHandler* handler) {
- AppShimHandlerRegistry::GetInstance()->SetDefaultHandler(handler);
-}
-
-// static
-void AppShimHandler::MaybeTerminate() {
- AppShimHandlerRegistry::GetInstance()->MaybeTerminate();
-}
-
-// static
-bool AppShimHandler::ShouldRestoreSession() {
- return AppShimHandlerRegistry::GetInstance()->ShouldRestoreSession();
-}
-
-} // namespace apps
« no previous file with comments | « apps/app_shim/app_shim_handler_mac.h ('k') | apps/app_shim/app_shim_host_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698