Index: chrome/browser/ui/cocoa/system_hotkey_helper_mac.mm |
diff --git a/chrome/browser/ui/cocoa/system_hotkey_helper_mac.mm b/chrome/browser/ui/cocoa/system_hotkey_helper_mac.mm |
new file mode 100644 |
index 0000000000000000000000000000000000000000..5f7515457959d89ab4fb3c561e56d97120cf13de |
--- /dev/null |
+++ b/chrome/browser/ui/cocoa/system_hotkey_helper_mac.mm |
@@ -0,0 +1,59 @@ |
+// Copyright 2014 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 "chrome/browser/ui/cocoa/system_hotkey_helper_mac.h" |
+ |
+#include "base/bind.h" |
+#include "base/message_loop/message_loop.h" |
+#include "base/metrics/histogram.h" |
+#include "chrome/browser/ui/cocoa/system_hotkey_map.h" |
+ |
+namespace { |
+ |
+NSString* kSystemHotkeyPlistPath = |
+ @"~/Library/Preferences/com.apple.symbolichotkeys.plist"; |
+ |
+// Amount of time to delay loading the hotkeys. |
+const int kLoadHotkeysDelay = 10; |
+ |
+} // namespace |
+ |
+// static |
+SystemHotkeyHelperMac* SystemHotkeyHelperMac::GetInstance() { |
+ return Singleton<SystemHotkeyHelperMac, |
+ LeakySingletonTraits<SystemHotkeyHelperMac> >::get(); |
+} |
+ |
+void SystemHotkeyHelperMac::DeferredLoadSystemHotkeys() { |
Avi (use Gerrit)
2014/07/07 21:57:49
This is called repeatedly from Browser::Browser. I
Robert Sesek
2014/07/07 22:21:36
Couldn't this just be done from the constructor, a
erikchen
2014/07/08 01:51:39
I've moved to code into content/ and mirrored avi'
|
+ base::MessageLoop::current()->PostDelayedTask( |
+ FROM_HERE, |
+ base::Bind(&SystemHotkeyHelperMac::LoadSystemHotkeys, |
+ weak_ptr_factory_.GetWeakPtr()), |
+ base::TimeDelta::FromSeconds(kLoadHotkeysDelay)); |
+} |
+ |
+SystemHotkeyHelperMac::SystemHotkeyHelperMac() |
+ : map_(new SystemHotkeyMap), weak_ptr_factory_(this) { |
+} |
+ |
+SystemHotkeyHelperMac::~SystemHotkeyHelperMac() { |
+} |
+ |
+void SystemHotkeyHelperMac::LoadSystemHotkeys() { |
+ base::WeakPtr<SystemHotkeyHelperMac> weak_self = |
+ weak_ptr_factory_.GetWeakPtr(); |
+ |
+ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), |
Robert Sesek
2014/07/07 22:21:36
I think it'd be better to use Chrome threading pri
erikchen
2014/07/08 01:51:39
I've removed the calls to gcd in favor of Chrome t
Robert Sesek
2014/07/08 13:40:00
Yes, your latest patch set is the correct way to d
erikchen
2014/07/10 02:07:31
I'm happy to discuss this point offline. I will di
|
+ ^{ |
+ NSString* expandedFilePath = |
+ [kSystemHotkeyPlistPath stringByExpandingTildeInPath]; |
+ NSData* data = [NSData dataWithContentsOfFile:expandedFilePath]; |
+ dispatch_async(dispatch_get_main_queue(), ^{ |
+ if (!weak_self.get()) |
+ return; |
+ bool success = weak_self.get()->map()->ParseData(data); |
+ UMA_HISTOGRAM_BOOLEAN("Mac.SystemHotkeyMap.Load", success); |
+ }); |
+ }); |
+} |