OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // StorageMonitorLinux implementation. | 5 // StorageMonitorLinux implementation. |
6 | 6 |
7 #include "chrome/browser/storage_monitor/storage_monitor_linux.h" | 7 #include "chrome/browser/storage_monitor/storage_monitor_linux.h" |
8 | 8 |
9 #include <mntent.h> | 9 #include <mntent.h> |
10 #include <stdio.h> | 10 #include <stdio.h> |
11 | 11 |
12 #include <list> | 12 #include <list> |
13 | 13 |
14 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
15 #include "base/bind.h" | 15 #include "base/bind.h" |
| 16 #include "base/command_line.h" |
16 #include "base/files/file_path.h" | 17 #include "base/files/file_path.h" |
17 #include "base/metrics/histogram.h" | 18 #include "base/metrics/histogram.h" |
18 #include "base/stl_util.h" | 19 #include "base/stl_util.h" |
19 #include "base/string_util.h" | 20 #include "base/string_util.h" |
20 #include "base/strings/string_number_conversions.h" | 21 #include "base/strings/string_number_conversions.h" |
21 #include "base/utf_string_conversions.h" | 22 #include "base/utf_string_conversions.h" |
22 #include "chrome/browser/storage_monitor/media_storage_util.h" | 23 #include "chrome/browser/storage_monitor/media_storage_util.h" |
| 24 #include "chrome/browser/storage_monitor/media_transfer_protocol_device_observer
_linux.h" |
23 #include "chrome/browser/storage_monitor/removable_device_constants.h" | 25 #include "chrome/browser/storage_monitor/removable_device_constants.h" |
24 #include "chrome/browser/storage_monitor/udev_util_linux.h" | 26 #include "chrome/browser/storage_monitor/udev_util_linux.h" |
| 27 #include "chrome/common/chrome_switches.h" |
| 28 #include "device/media_transfer_protocol/media_transfer_protocol_manager.h" |
25 | 29 |
26 namespace chrome { | 30 namespace chrome { |
27 | 31 |
28 using content::BrowserThread; | 32 using content::BrowserThread; |
29 | 33 |
30 namespace { | 34 namespace { |
31 | 35 |
32 // List of file systems we care about. | 36 // List of file systems we care about. |
33 const char* const kKnownFileSystems[] = { | 37 const char* const kKnownFileSystems[] = { |
34 "ext2", | 38 "ext2", |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 | 267 |
264 StorageMonitorLinux::StorageMonitorLinux(const base::FilePath& path, | 268 StorageMonitorLinux::StorageMonitorLinux(const base::FilePath& path, |
265 GetDeviceInfoFunc get_device_info_func) | 269 GetDeviceInfoFunc get_device_info_func) |
266 : initialized_(false), | 270 : initialized_(false), |
267 mtab_path_(path), | 271 mtab_path_(path), |
268 get_device_info_func_(get_device_info_func) { | 272 get_device_info_func_(get_device_info_func) { |
269 } | 273 } |
270 | 274 |
271 StorageMonitorLinux::~StorageMonitorLinux() { | 275 StorageMonitorLinux::~StorageMonitorLinux() { |
272 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 276 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 277 |
| 278 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType)) { |
| 279 BrowserThread::PostTask( |
| 280 BrowserThread::UI, FROM_HERE, |
| 281 base::Bind(&device::MediaTransferProtocolManager::Shutdown)); |
| 282 } |
273 } | 283 } |
274 | 284 |
275 void StorageMonitorLinux::Init() { | 285 void StorageMonitorLinux::Init() { |
276 DCHECK(!mtab_path_.empty()); | 286 DCHECK(!mtab_path_.empty()); |
277 | 287 |
278 // Put |kKnownFileSystems| in std::set to get O(log N) access time. | 288 // Put |kKnownFileSystems| in std::set to get O(log N) access time. |
279 for (size_t i = 0; i < arraysize(kKnownFileSystems); ++i) | 289 for (size_t i = 0; i < arraysize(kKnownFileSystems); ++i) |
280 known_file_systems_.insert(kKnownFileSystems[i]); | 290 known_file_systems_.insert(kKnownFileSystems[i]); |
281 | 291 |
282 BrowserThread::PostTask( | 292 BrowserThread::PostTask( |
283 BrowserThread::FILE, FROM_HERE, | 293 BrowserThread::FILE, FROM_HERE, |
284 base::Bind(&StorageMonitorLinux::InitOnFileThread, this)); | 294 base::Bind(&StorageMonitorLinux::InitOnFileThread, this)); |
| 295 |
| 296 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType)) { |
| 297 scoped_refptr<base::MessageLoopProxy> loop_proxy; |
| 298 loop_proxy = content::BrowserThread::GetMessageLoopProxyForThread( |
| 299 content::BrowserThread::FILE); |
| 300 device::MediaTransferProtocolManager::Initialize(loop_proxy); |
| 301 |
| 302 media_transfer_protocol_device_observer_.reset( |
| 303 new MediaTransferProtocolDeviceObserverLinux()); |
| 304 media_transfer_protocol_device_observer_->SetNotifications(receiver()); |
| 305 } |
285 } | 306 } |
286 | 307 |
287 bool StorageMonitorLinux::GetStorageInfoForPath( | 308 bool StorageMonitorLinux::GetStorageInfoForPath( |
288 const base::FilePath& path, | 309 const base::FilePath& path, |
289 StorageInfo* device_info) const { | 310 StorageInfo* device_info) const { |
290 if (!path.IsAbsolute()) | 311 if (!path.IsAbsolute()) |
291 return false; | 312 return false; |
292 | 313 |
293 base::FilePath current = path; | 314 base::FilePath current = path; |
294 while (!ContainsKey(mount_info_map_, current) && current != current.DirName()) | 315 while (!ContainsKey(mount_info_map_, current) && current != current.DirName()) |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
465 if (removable) { | 486 if (removable) { |
466 string16 display_name = MediaStorageUtil::GetDisplayNameForDevice( | 487 string16 display_name = MediaStorageUtil::GetDisplayNameForDevice( |
467 partition_size_in_bytes, name); | 488 partition_size_in_bytes, name); |
468 | 489 |
469 receiver()->ProcessAttach(StorageInfo(device_id, display_name, | 490 receiver()->ProcessAttach(StorageInfo(device_id, display_name, |
470 mount_point.value())); | 491 mount_point.value())); |
471 } | 492 } |
472 } | 493 } |
473 | 494 |
474 } // namespace chrome | 495 } // namespace chrome |
OLD | NEW |