OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/extensions/api/music_manager_private/device_id.h" | 5 #include "chrome/browser/extensions/api/music_manager_private/device_id.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
11 | 11 |
12 namespace { | 12 namespace { |
13 | 13 |
14 const char kDBusFilename[] = "/var/lib/dbus/machine-id"; | 14 const char kDBusFilename[] = "/var/lib/dbus/machine-id"; |
15 | 15 |
16 void GetDBusMachineId(const extensions::api::DeviceId::IdCallback& callback) { | 16 void GetDBusMachineId(const extensions::api::DeviceId::IdCallback& callback) { |
17 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); | 17 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); |
18 | 18 |
19 std::string result; | 19 std::string result; |
20 if (!file_util::ReadFileToString(base::FilePath(kDBusFilename), &result)) { | 20 if (!base::ReadFileToString(base::FilePath(kDBusFilename), &result)) { |
21 DLOG(WARNING) << "Error reading dbus machine id file."; | 21 DLOG(WARNING) << "Error reading dbus machine id file."; |
22 result = ""; | 22 result = ""; |
23 } | 23 } |
24 | 24 |
25 content::BrowserThread::PostTask( | 25 content::BrowserThread::PostTask( |
26 content::BrowserThread::UI, | 26 content::BrowserThread::UI, |
27 FROM_HERE, | 27 FROM_HERE, |
28 base::Bind(callback, result)); | 28 base::Bind(callback, result)); |
29 } | 29 } |
30 | 30 |
31 } | 31 } |
32 | 32 |
33 namespace extensions { | 33 namespace extensions { |
34 namespace api { | 34 namespace api { |
35 | 35 |
36 // Linux: Use the content of the "DBus" machine-id file. | 36 // Linux: Use the content of the "DBus" machine-id file. |
37 /* static */ | 37 /* static */ |
38 void DeviceId::GetMachineId(const IdCallback& callback) { | 38 void DeviceId::GetMachineId(const IdCallback& callback) { |
39 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 39 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
40 | 40 |
41 content::BrowserThread::PostTask( | 41 content::BrowserThread::PostTask( |
42 content::BrowserThread::FILE, | 42 content::BrowserThread::FILE, |
43 FROM_HERE, | 43 FROM_HERE, |
44 base::Bind(GetDBusMachineId, callback)); | 44 base::Bind(GetDBusMachineId, callback)); |
45 } | 45 } |
46 | 46 |
47 } // namespace api | 47 } // namespace api |
48 } // namespace extensions | 48 } // namespace extensions |
OLD | NEW |