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

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: Document lifecycle in storage_monitor.h 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"
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 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 RemovableDeviceNotificationsLinux::RemovableDeviceNotificationsLinux( 238 RemovableDeviceNotificationsLinux::RemovableDeviceNotificationsLinux(
235 const base::FilePath& path, 239 const base::FilePath& path,
236 GetDeviceInfoFunc get_device_info_func) 240 GetDeviceInfoFunc get_device_info_func)
237 : initialized_(false), 241 : initialized_(false),
238 mtab_path_(path), 242 mtab_path_(path),
239 get_device_info_func_(get_device_info_func) { 243 get_device_info_func_(get_device_info_func) {
240 } 244 }
241 245
242 RemovableDeviceNotificationsLinux::~RemovableDeviceNotificationsLinux() { 246 RemovableDeviceNotificationsLinux::~RemovableDeviceNotificationsLinux() {
243 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 247 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
248 device::MediaTransferProtocolManager::Shutdown();
Lei Zhang 2013/03/01 04:40:15 ditto
Greg Billock 2013/03/01 18:00:50 Done.
244 } 249 }
245 250
246 void RemovableDeviceNotificationsLinux::Init() { 251 void RemovableDeviceNotificationsLinux::Init() {
247 DCHECK(!mtab_path_.empty()); 252 DCHECK(!mtab_path_.empty());
248 253
249 // Put |kKnownFileSystems| in std::set to get O(log N) access time. 254 // Put |kKnownFileSystems| in std::set to get O(log N) access time.
250 for (size_t i = 0; i < arraysize(kKnownFileSystems); ++i) 255 for (size_t i = 0; i < arraysize(kKnownFileSystems); ++i)
251 known_file_systems_.insert(kKnownFileSystems[i]); 256 known_file_systems_.insert(kKnownFileSystems[i]);
252 257
253 BrowserThread::PostTask( 258 BrowserThread::PostTask(
254 BrowserThread::FILE, FROM_HERE, 259 BrowserThread::FILE, FROM_HERE,
255 base::Bind(&RemovableDeviceNotificationsLinux::InitOnFileThread, this)); 260 base::Bind(&RemovableDeviceNotificationsLinux::InitOnFileThread, this));
261
262 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType)) {
263 scoped_refptr<base::MessageLoopProxy> loop_proxy;
264 loop_proxy = content::BrowserThread::GetMessageLoopProxyForThread(
265 content::BrowserThread::FILE);
266 device::MediaTransferProtocolManager::Initialize(loop_proxy);
267
268 media_transfer_protocol_device_observer_.reset(
269 new MediaTransferProtocolDeviceObserverLinux());
270 media_transfer_protocol_device_observer_->SetNotifications(receiver());
271 }
256 } 272 }
257 273
258 bool RemovableDeviceNotificationsLinux::GetStorageInfoForPath( 274 bool RemovableDeviceNotificationsLinux::GetStorageInfoForPath(
259 const base::FilePath& path, 275 const base::FilePath& path,
260 StorageInfo* device_info) const { 276 StorageInfo* device_info) const {
261 if (!path.IsAbsolute()) 277 if (!path.IsAbsolute())
262 return false; 278 return false;
263 279
264 base::FilePath current = path; 280 base::FilePath current = path;
265 while (!ContainsKey(mount_info_map_, current) && current != current.DirName()) 281 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; 471 mount_priority_map_[mount_device][mount_point] = removable;
456 472
457 if (removable) { 473 if (removable) {
458 receiver()->ProcessAttach(StorageInfo( 474 receiver()->ProcessAttach(StorageInfo(
459 device_id, GetDisplayNameForDevice(partition_size_in_bytes, name), 475 device_id, GetDisplayNameForDevice(partition_size_in_bytes, name),
460 mount_point.value())); 476 mount_point.value()));
461 } 477 }
462 } 478 }
463 479
464 } // namespace chrome 480 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698