OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/cocoa/system_hotkey_helper_mac.h" | 5 #include "content/browser/cocoa/system_hotkey_helper_mac.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/mac/foundation_util.h" | 9 #include "base/mac/foundation_util.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 base::TimeDelta::FromSeconds(kLoadHotkeysDelaySeconds)); | 38 base::TimeDelta::FromSeconds(kLoadHotkeysDelaySeconds)); |
39 } | 39 } |
40 | 40 |
41 SystemHotkeyHelperMac::SystemHotkeyHelperMac() : map_(new SystemHotkeyMap) { | 41 SystemHotkeyHelperMac::SystemHotkeyHelperMac() : map_(new SystemHotkeyMap) { |
42 } | 42 } |
43 | 43 |
44 SystemHotkeyHelperMac::~SystemHotkeyHelperMac() { | 44 SystemHotkeyHelperMac::~SystemHotkeyHelperMac() { |
45 } | 45 } |
46 | 46 |
47 void SystemHotkeyHelperMac::LoadSystemHotkeys() { | 47 void SystemHotkeyHelperMac::LoadSystemHotkeys() { |
48 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 48 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
49 | 49 |
50 std::string library_path(base::mac::GetUserLibraryPath().value()); | 50 std::string library_path(base::mac::GetUserLibraryPath().value()); |
51 NSString* expanded_file_path = | 51 NSString* expanded_file_path = |
52 [NSString stringWithFormat:@"%s%@", | 52 [NSString stringWithFormat:@"%s%@", |
53 library_path.c_str(), | 53 library_path.c_str(), |
54 kSystemHotkeyPlistExtension]; | 54 kSystemHotkeyPlistExtension]; |
55 | 55 |
56 // Loads the file into memory. | 56 // Loads the file into memory. |
57 NSData* data = [NSData dataWithContentsOfFile:expanded_file_path]; | 57 NSData* data = [NSData dataWithContentsOfFile:expanded_file_path]; |
58 // Intentionally create the object with +1 retain count, as FileDidLoad | 58 // Intentionally create the object with +1 retain count, as FileDidLoad |
59 // will destroy the object. | 59 // will destroy the object. |
60 NSDictionary* dictionary = [SystemHotkeyMap::DictionaryFromData(data) retain]; | 60 NSDictionary* dictionary = [SystemHotkeyMap::DictionaryFromData(data) retain]; |
61 | 61 |
62 BrowserThread::PostTask(BrowserThread::UI, | 62 BrowserThread::PostTask(BrowserThread::UI, |
63 FROM_HERE, | 63 FROM_HERE, |
64 base::Bind(&SystemHotkeyHelperMac::FileDidLoad, | 64 base::Bind(&SystemHotkeyHelperMac::FileDidLoad, |
65 base::Unretained(this), | 65 base::Unretained(this), |
66 dictionary)); | 66 dictionary)); |
67 } | 67 } |
68 | 68 |
69 void SystemHotkeyHelperMac::FileDidLoad(NSDictionary* dictionary) { | 69 void SystemHotkeyHelperMac::FileDidLoad(NSDictionary* dictionary) { |
70 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 70 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
71 | 71 |
72 bool success = map()->ParseDictionary(dictionary); | 72 bool success = map()->ParseDictionary(dictionary); |
73 UMA_HISTOGRAM_BOOLEAN("OSX.SystemHotkeyMap.LoadSuccess", success); | 73 UMA_HISTOGRAM_BOOLEAN("OSX.SystemHotkeyMap.LoadSuccess", success); |
74 [dictionary release]; | 74 [dictionary release]; |
75 } | 75 } |
76 | 76 |
77 } // namespace content | 77 } // namespace content |
OLD | NEW |