Windows should animate when they are about to get docked at screen edges.
[chromium-blink-merge.git] / apps / app_shim / app_shim_handler_mac.cc
blob6076557710a7a1e7644139931643bfd52ffaab81
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
3 // found in the LICENSE file.
5 #include "apps/app_shim/app_shim_handler_mac.h"
7 #include <map>
9 #include "base/logging.h"
10 #include "base/memory/singleton.h"
12 namespace apps {
14 namespace {
16 class AppShimHandlerRegistry {
17 public:
18 static AppShimHandlerRegistry* GetInstance() {
19 return Singleton<AppShimHandlerRegistry,
20 LeakySingletonTraits<AppShimHandlerRegistry> >::get();
23 AppShimHandler* GetForAppMode(const std::string& app_mode_id) const {
24 HandlerMap::const_iterator it = handlers_.find(app_mode_id);
25 if (it != handlers_.end())
26 return it->second;
28 return default_handler_;
31 bool SetForAppMode(const std::string& app_mode_id, AppShimHandler* handler) {
32 bool inserted_or_removed = handler ?
33 handlers_.insert(HandlerMap::value_type(app_mode_id, handler)).second :
34 handlers_.erase(app_mode_id) == 1;
35 DCHECK(inserted_or_removed);
36 return inserted_or_removed;
39 void SetDefaultHandler(AppShimHandler* handler) {
40 DCHECK_NE(default_handler_ == NULL, handler == NULL);
41 default_handler_ = handler;
44 private:
45 friend struct DefaultSingletonTraits<AppShimHandlerRegistry>;
46 typedef std::map<std::string, AppShimHandler*> HandlerMap;
48 AppShimHandlerRegistry() : default_handler_(NULL) {}
49 ~AppShimHandlerRegistry() {}
51 HandlerMap handlers_;
52 AppShimHandler* default_handler_;
54 DISALLOW_COPY_AND_ASSIGN(AppShimHandlerRegistry);
57 } // namespace
59 // static
60 void AppShimHandler::RegisterHandler(const std::string& app_mode_id,
61 AppShimHandler* handler) {
62 DCHECK(handler);
63 AppShimHandlerRegistry::GetInstance()->SetForAppMode(app_mode_id, handler);
66 // static
67 void AppShimHandler::RemoveHandler(const std::string& app_mode_id) {
68 AppShimHandlerRegistry::GetInstance()->SetForAppMode(app_mode_id, NULL);
71 // static
72 AppShimHandler* AppShimHandler::GetForAppMode(const std::string& app_mode_id) {
73 return AppShimHandlerRegistry::GetInstance()->GetForAppMode(app_mode_id);
76 // static
77 void AppShimHandler::SetDefaultHandler(AppShimHandler* handler) {
78 AppShimHandlerRegistry::GetInstance()->SetDefaultHandler(handler);
81 } // namespace apps