Home | History | Annotate | Download | only in cocoa
      1 // Copyright 2014 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.
      4 
      5 #ifndef CONTENT_BROWSER_COCOA_SYSTEM_HOTKEY_HELPER_MAC_H_
      6 #define CONTENT_BROWSER_COCOA_SYSTEM_HOTKEY_HELPER_MAC_H_
      7 
      8 #include "base/memory/singleton.h"
      9 #include "base/memory/weak_ptr.h"
     10 
     11 #ifdef __OBJC__
     12 @class NSDictionary;
     13 #else
     14 class NSDictionary;
     15 #endif
     16 
     17 namespace content {
     18 
     19 class SystemHotkeyMap;
     20 
     21 // This singleton holds a global mapping of hotkeys reserved by OSX.
     22 class SystemHotkeyHelperMac {
     23  public:
     24   // Return pointer to the singleton instance for the current process.
     25   static SystemHotkeyHelperMac* GetInstance();
     26 
     27   // Loads the system hot keys after a brief delay, to reduce file system access
     28   // immediately after launch.
     29   void DeferredLoadSystemHotkeys();
     30 
     31   // Guaranteed to not be NULL.
     32   SystemHotkeyMap* map() { return map_.get(); }
     33 
     34  private:
     35   friend struct DefaultSingletonTraits<SystemHotkeyHelperMac>;
     36 
     37   SystemHotkeyHelperMac();
     38   ~SystemHotkeyHelperMac();
     39 
     40   // Must be called from the FILE thread. Loads the file containing the system
     41   // hotkeys into a NSDictionary* object, and passes the result to FileDidLoad
     42   // on the UI thread.
     43   void LoadSystemHotkeys();
     44 
     45   // Must be called from the UI thread.  This takes ownership of |dictionary|.
     46   // Parses the system hotkeys from the plist stored in |dictionary|.
     47   void FileDidLoad(NSDictionary* dictionary);
     48 
     49   scoped_ptr<SystemHotkeyMap> map_;
     50 
     51   DISALLOW_COPY_AND_ASSIGN(SystemHotkeyHelperMac);
     52 };
     53 
     54 }  // namespace content
     55 
     56 #endif  // CONTENT_BROWSER_COCOA_SYSTEM_HOTKEY_HELPER_MAC_H_
     57