Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(48)

Side by Side Diff: chrome/browser/storage_monitor/removable_device_notifications_linux.cc

Issue 12334096: Regularize ownerships and lifecycle for storage monitor platform classes. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 // RemovableDeviceNotificationsLinux implementation. 5 // RemovableDeviceNotificationsLinux implementation.
6 6
7 #include "chrome/browser/storage_monitor/removable_device_notifications_linux.h" 7 #include "chrome/browser/storage_monitor/removable_device_notifications_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"
26 29
27 namespace chrome { 30 namespace chrome {
28 31
29 using content::BrowserThread; 32 using content::BrowserThread;
30 33
31 namespace { 34 namespace {
32 35
33 // List of file systems we care about. 36 // List of file systems we care about.
34 const char* const kKnownFileSystems[] = { 37 const char* const kKnownFileSystems[] = {
35 "ext2", 38 "ext2",
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 void RemovableDeviceNotificationsLinux::Init() { 249 void RemovableDeviceNotificationsLinux::Init() {
247 DCHECK(!mtab_path_.empty()); 250 DCHECK(!mtab_path_.empty());
248 251
249 // Put |kKnownFileSystems| in std::set to get O(log N) access time. 252 // Put |kKnownFileSystems| in std::set to get O(log N) access time.
250 for (size_t i = 0; i < arraysize(kKnownFileSystems); ++i) 253 for (size_t i = 0; i < arraysize(kKnownFileSystems); ++i)
251 known_file_systems_.insert(kKnownFileSystems[i]); 254 known_file_systems_.insert(kKnownFileSystems[i]);
252 255
253 BrowserThread::PostTask( 256 BrowserThread::PostTask(
254 BrowserThread::FILE, FROM_HERE, 257 BrowserThread::FILE, FROM_HERE,
255 base::Bind(&RemovableDeviceNotificationsLinux::InitOnFileThread, this)); 258 base::Bind(&RemovableDeviceNotificationsLinux::InitOnFileThread, this));
259
260 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType)) {
261 media_transfer_protocol_device_observer_.reset(
262 new MediaTransferProtocolDeviceObserverLinux());
263 media_transfer_protocol_device_observer_->SetNotifications(receiver());
264 }
256 } 265 }
257 266
258 bool RemovableDeviceNotificationsLinux::GetDeviceInfoForPath( 267 bool RemovableDeviceNotificationsLinux::GetDeviceInfoForPath(
259 const base::FilePath& path, 268 const base::FilePath& path,
260 StorageInfo* device_info) const { 269 StorageInfo* device_info) const {
261 if (!path.IsAbsolute()) 270 if (!path.IsAbsolute())
262 return false; 271 return false;
263 272
264 base::FilePath current = path; 273 base::FilePath current = path;
265 while (!ContainsKey(mount_info_map_, current) && current != current.DirName()) 274 while (!ContainsKey(mount_info_map_, current) && current != current.DirName())
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 mount_priority_map_[mount_device][mount_point] = removable; 464 mount_priority_map_[mount_device][mount_point] = removable;
456 465
457 if (removable) { 466 if (removable) {
458 receiver()->ProcessAttach( 467 receiver()->ProcessAttach(
459 device_id, GetDisplayNameForDevice(partition_size_in_bytes, name), 468 device_id, GetDisplayNameForDevice(partition_size_in_bytes, name),
460 mount_point.value()); 469 mount_point.value());
461 } 470 }
462 } 471 }
463 472
464 } // namespace chrome 473 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698