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_device_notifications_utils.h" | 23 #include "chrome/browser/storage_monitor/media_device_notifications_utils.h" |
23 #include "chrome/browser/storage_monitor/media_storage_util.h" | 24 #include "chrome/browser/storage_monitor/media_storage_util.h" |
25 #include "chrome/browser/storage_monitor/media_transfer_protocol_device_observer _linux.h" | |
24 #include "chrome/browser/storage_monitor/removable_device_constants.h" | 26 #include "chrome/browser/storage_monitor/removable_device_constants.h" |
25 #include "chrome/browser/storage_monitor/udev_util_linux.h" | 27 #include "chrome/browser/storage_monitor/udev_util_linux.h" |
28 #include "chrome/common/chrome_switches.h" | |
29 #include "device/media_transfer_protocol/media_transfer_protocol_manager.h" | |
26 | 30 |
27 namespace chrome { | 31 namespace chrome { |
28 | 32 |
29 using content::BrowserThread; | 33 using content::BrowserThread; |
30 | 34 |
31 namespace { | 35 namespace { |
32 | 36 |
33 // List of file systems we care about. | 37 // List of file systems we care about. |
34 const char* const kKnownFileSystems[] = { | 38 const char* const kKnownFileSystems[] = { |
35 "ext2", | 39 "ext2", |
(...skipping 227 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 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType)) { | |
278 device::MediaTransferProtocolManager::Shutdown(); | |
279 } | |
273 } | 280 } |
274 | 281 |
275 void StorageMonitorLinux::Init() { | 282 void StorageMonitorLinux::Init() { |
276 DCHECK(!mtab_path_.empty()); | 283 DCHECK(!mtab_path_.empty()); |
277 | 284 |
278 // Put |kKnownFileSystems| in std::set to get O(log N) access time. | 285 // Put |kKnownFileSystems| in std::set to get O(log N) access time. |
279 for (size_t i = 0; i < arraysize(kKnownFileSystems); ++i) | 286 for (size_t i = 0; i < arraysize(kKnownFileSystems); ++i) |
280 known_file_systems_.insert(kKnownFileSystems[i]); | 287 known_file_systems_.insert(kKnownFileSystems[i]); |
281 | 288 |
282 BrowserThread::PostTask( | 289 BrowserThread::PostTask( |
283 BrowserThread::FILE, FROM_HERE, | 290 BrowserThread::FILE, FROM_HERE, |
284 base::Bind(&StorageMonitorLinux::InitOnFileThread, this)); | 291 base::Bind(&StorageMonitorLinux::InitOnFileThread, this)); |
292 | |
293 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType)) { | |
294 scoped_refptr<base::MessageLoopProxy> loop_proxy; | |
295 loop_proxy = content::BrowserThread::GetMessageLoopProxyForThread( | |
296 content::BrowserThread::FILE); | |
297 device::MediaTransferProtocolManager::Initialize(loop_proxy); | |
Joao da Silva
2013/03/12 14:15:23
This DCHECKS on Linux at shutdown.
::Initialize c
Greg Billock
2013/03/12 21:15:29
Yes, we need to post back to the UI thread to shut
| |
298 | |
299 media_transfer_protocol_device_observer_.reset( | |
300 new MediaTransferProtocolDeviceObserverLinux()); | |
301 media_transfer_protocol_device_observer_->SetNotifications(receiver()); | |
302 } | |
285 } | 303 } |
286 | 304 |
287 bool StorageMonitorLinux::GetStorageInfoForPath( | 305 bool StorageMonitorLinux::GetStorageInfoForPath( |
288 const base::FilePath& path, | 306 const base::FilePath& path, |
289 StorageInfo* device_info) const { | 307 StorageInfo* device_info) const { |
290 if (!path.IsAbsolute()) | 308 if (!path.IsAbsolute()) |
291 return false; | 309 return false; |
292 | 310 |
293 base::FilePath current = path; | 311 base::FilePath current = path; |
294 while (!ContainsKey(mount_info_map_, current) && current != current.DirName()) | 312 while (!ContainsKey(mount_info_map_, current) && current != current.DirName()) |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
463 mount_priority_map_[mount_device][mount_point] = removable; | 481 mount_priority_map_[mount_device][mount_point] = removable; |
464 | 482 |
465 if (removable) { | 483 if (removable) { |
466 receiver()->ProcessAttach(StorageInfo( | 484 receiver()->ProcessAttach(StorageInfo( |
467 device_id, GetDisplayNameForDevice(partition_size_in_bytes, name), | 485 device_id, GetDisplayNameForDevice(partition_size_in_bytes, name), |
468 mount_point.value())); | 486 mount_point.value())); |
469 } | 487 } |
470 } | 488 } |
471 | 489 |
472 } // namespace chrome | 490 } // namespace chrome |
OLD | NEW |