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 "content/browser/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 "content/browser/cocoa/system_hotkey_map.h" | |
11 #include "content/public/browser/browser_thread.h" | |
12 | |
13 namespace { | |
14 | |
15 NSString* kSystemHotkeyPlistPath = | |
16 @"~/Library/Preferences/com.apple.symbolichotkeys.plist"; | |
17 | |
18 // Amount of time to delay loading the hotkeys. | |
Robert Sesek
2014/07/08 13:40:01
Units? In the name of the symbol, too, please.
erikchen
2014/07/10 02:07:31
Done.
| |
19 const int kLoadHotkeysDelay = 10; | |
20 | |
21 } // namespace | |
22 | |
23 namespace content { | |
24 | |
25 // static | |
26 SystemHotkeyHelperMac* SystemHotkeyHelperMac::GetInstance() { | |
27 return Singleton<SystemHotkeyHelperMac, | |
28 LeakySingletonTraits<SystemHotkeyHelperMac> >::get(); | |
Robert Sesek
2014/07/08 13:40:01
Why does this need to be leaky?
erikchen
2014/07/10 02:07:31
I was copy-pasting some code, and didn't read it t
| |
29 } | |
30 | |
31 void SystemHotkeyHelperMac::DeferredLoadSystemHotkeys() { | |
32 base::MessageLoop::current()->PostDelayedTask( | |
Robert Sesek
2014/07/08 13:40:00
You can post this directly to the FILE thread.
erikchen
2014/07/10 02:07:32
Done.
| |
33 FROM_HERE, | |
34 base::Bind(&SystemHotkeyHelperMac::LoadSystemHotkeys, | |
35 weak_ptr_factory_.GetWeakPtr()), | |
36 base::TimeDelta::FromSeconds(kLoadHotkeysDelay)); | |
37 } | |
38 | |
39 SystemHotkeyHelperMac::SystemHotkeyHelperMac() | |
40 : map_(new SystemHotkeyMap), weak_ptr_factory_(this) { | |
41 } | |
42 | |
43 SystemHotkeyHelperMac::~SystemHotkeyHelperMac() { | |
44 } | |
45 | |
46 void SystemHotkeyHelperMac::LoadSystemHotkeys() { | |
47 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
48 | |
49 BrowserThread::PostTask( | |
50 BrowserThread::FILE, | |
51 FROM_HERE, | |
52 base::Bind(&SystemHotkeyHelperMac::LoadFile, base::Unretained(this))); | |
erikchen
2014/07/08 01:51:39
I couldn't use a weak ptr here because the weak pt
Robert Sesek
2014/07/08 13:40:01
Right, weak pointer only works on a given thread.
erikchen
2014/07/10 02:07:31
Removed all the weak pointers.
| |
53 } | |
54 | |
55 void SystemHotkeyHelperMac::LoadFile() { | |
56 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | |
57 | |
58 NSString* expandedFilePath = | |
59 [kSystemHotkeyPlistPath stringByExpandingTildeInPath]; | |
Robert Sesek
2014/07/08 13:40:00
base::mac::GetUserLibraryPath()
erikchen
2014/07/10 02:07:31
Done.
| |
60 NSData* data = [NSData dataWithContentsOfFile:expandedFilePath]; | |
Robert Sesek
2014/07/08 13:40:01
Alternatively, use base::ReadFileToString and pass
Robert Sesek
2014/07/08 13:40:01
Use alloc/init so you don't need to manually retai
erikchen
2014/07/10 02:07:31
On 2014/07/08 13:40:01, rsesek (OOO July 9-13) wro
erikchen
2014/07/10 02:07:32
Are you suggesting that we pass around a C++ objec
| |
61 [data retain]; | |
62 | |
63 BrowserThread::PostTask(BrowserThread::UI, | |
64 FROM_HERE, | |
65 base::Bind(&SystemHotkeyHelperMac::FileDidLoad, | |
66 weak_ptr_factory_.GetWeakPtr(), | |
67 data)); | |
68 } | |
69 | |
70 void SystemHotkeyHelperMac::FileDidLoad(NSData* data) { | |
71 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
72 | |
73 bool success = map()->ParseData(data); | |
Robert Sesek
2014/07/08 13:40:01
How long does parsing take? Consider doing it on t
| |
74 UMA_HISTOGRAM_BOOLEAN("Mac.SystemHotkeyMap.Load", success); | |
Robert Sesek
2014/07/08 13:40:01
Use OSX. instead of Mac.
erikchen
2014/07/10 02:07:31
Done.
| |
75 [data release]; | |
76 } | |
77 | |
78 } // namespace content | |
OLD | NEW |