OLD | NEW |
---|---|
(Empty) | |
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 #include "chrome/browser/ui/cocoa/system_hotkey_helper_mac.h" | |
6 | |
7 #include "base/bind.h" | |
8 #include "base/message_loop/message_loop.h" | |
9 #include "base/metrics/histogram.h" | |
10 #include "chrome/browser/ui/cocoa/system_hotkey_map.h" | |
11 | |
12 namespace { | |
13 | |
14 NSString* kSystemHotkeyPlistPath = | |
15 @"~/Library/Preferences/com.apple.symbolichotkeys.plist"; | |
16 | |
17 // Amount of time to delay loading the hotkeys. | |
18 const int kLoadHotkeysDelay = 10; | |
19 | |
20 } // namespace | |
21 | |
22 // static | |
23 SystemHotkeyHelperMac* SystemHotkeyHelperMac::GetInstance() { | |
24 return Singleton<SystemHotkeyHelperMac, | |
25 LeakySingletonTraits<SystemHotkeyHelperMac> >::get(); | |
26 } | |
27 | |
28 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'
| |
29 base::MessageLoop::current()->PostDelayedTask( | |
30 FROM_HERE, | |
31 base::Bind(&SystemHotkeyHelperMac::LoadSystemHotkeys, | |
32 weak_ptr_factory_.GetWeakPtr()), | |
33 base::TimeDelta::FromSeconds(kLoadHotkeysDelay)); | |
34 } | |
35 | |
36 SystemHotkeyHelperMac::SystemHotkeyHelperMac() | |
37 : map_(new SystemHotkeyMap), weak_ptr_factory_(this) { | |
38 } | |
39 | |
40 SystemHotkeyHelperMac::~SystemHotkeyHelperMac() { | |
41 } | |
42 | |
43 void SystemHotkeyHelperMac::LoadSystemHotkeys() { | |
44 base::WeakPtr<SystemHotkeyHelperMac> weak_self = | |
45 weak_ptr_factory_.GetWeakPtr(); | |
46 | |
47 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
| |
48 ^{ | |
49 NSString* expandedFilePath = | |
50 [kSystemHotkeyPlistPath stringByExpandingTildeInPath]; | |
51 NSData* data = [NSData dataWithContentsOfFile:expandedFilePath]; | |
52 dispatch_async(dispatch_get_main_queue(), ^{ | |
53 if (!weak_self.get()) | |
54 return; | |
55 bool success = weak_self.get()->map()->ParseData(data); | |
56 UMA_HISTOGRAM_BOOLEAN("Mac.SystemHotkeyMap.Load", success); | |
57 }); | |
58 }); | |
59 } | |
OLD | NEW |