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

Side by Side Diff: chrome/browser/storage_monitor/removable_device_notifications_chromeos.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 // chromeos::RemovableDeviceNotificationsCros implementation. 5 // chromeos::RemovableDeviceNotificationsCros implementation.
6 6
7 #include "chrome/browser/storage_monitor/removable_device_notifications_chromeos .h" 7 #include "chrome/browser/storage_monitor/removable_device_notifications_chromeos .h"
8 8
9 #include "base/command_line.h"
9 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
10 #include "base/logging.h" 11 #include "base/logging.h"
11 #include "base/stl_util.h" 12 #include "base/stl_util.h"
12 #include "base/string_util.h" 13 #include "base/string_util.h"
13 #include "base/strings/string_number_conversions.h" 14 #include "base/strings/string_number_conversions.h"
14 #include "base/utf_string_conversions.h" 15 #include "base/utf_string_conversions.h"
15 #include "chrome/browser/storage_monitor/media_device_notifications_utils.h" 16 #include "chrome/browser/storage_monitor/media_device_notifications_utils.h"
16 #include "chrome/browser/storage_monitor/media_storage_util.h" 17 #include "chrome/browser/storage_monitor/media_storage_util.h"
18 #include "chrome/browser/storage_monitor/media_transfer_protocol_device_observer _linux.h"
17 #include "chrome/browser/storage_monitor/removable_device_constants.h" 19 #include "chrome/browser/storage_monitor/removable_device_constants.h"
20 #include "chrome/common/chrome_switches.h"
18 #include "content/public/browser/browser_thread.h" 21 #include "content/public/browser/browser_thread.h"
22 #include "device/media_transfer_protocol/media_transfer_protocol_manager.h"
19 23
20 namespace chromeos { 24 namespace chromeos {
21 25
22 namespace { 26 namespace {
23 27
24 // Constructs a device name using label or manufacturer (vendor and product) 28 // Constructs a device name using label or manufacturer (vendor and product)
25 // name details. 29 // name details.
26 string16 GetDeviceName(const disks::DiskMountManager::Disk& disk) { 30 string16 GetDeviceName(const disks::DiskMountManager::Disk& disk) {
27 if (disk.device_type() == DEVICE_TYPE_SD) { 31 if (disk.device_type() == DEVICE_TYPE_SD) {
28 // Mount path of an SD card will be one of the following: 32 // Mount path of an SD card will be one of the following:
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 if (storage_size_in_bytes) 84 if (storage_size_in_bytes)
81 *storage_size_in_bytes = disk->total_size_in_bytes(); 85 *storage_size_in_bytes = disk->total_size_in_bytes();
82 return true; 86 return true;
83 } 87 }
84 88
85 } // namespace 89 } // namespace
86 90
87 using content::BrowserThread; 91 using content::BrowserThread;
88 92
89 RemovableDeviceNotificationsCros::RemovableDeviceNotificationsCros() { 93 RemovableDeviceNotificationsCros::RemovableDeviceNotificationsCros() {
90 DCHECK(disks::DiskMountManager::GetInstance());
91 disks::DiskMountManager::GetInstance()->AddObserver(this);
92 CheckExistingMountPointsOnUIThread();
93 } 94 }
94 95
95 RemovableDeviceNotificationsCros::~RemovableDeviceNotificationsCros() { 96 RemovableDeviceNotificationsCros::~RemovableDeviceNotificationsCros() {
97 device::MediaTransferProtocolManager::Shutdown();
Lei Zhang 2013/03/01 04:40:15 Add a check before calling this to avoid the shutd
Greg Billock 2013/03/01 18:00:50 Done.
98
96 disks::DiskMountManager* manager = disks::DiskMountManager::GetInstance(); 99 disks::DiskMountManager* manager = disks::DiskMountManager::GetInstance();
97 if (manager) { 100 if (manager) {
98 manager->RemoveObserver(this); 101 manager->RemoveObserver(this);
99 } 102 }
100 } 103 }
101 104
105 void RemovableDeviceNotificationsCros::Init() {
106 DCHECK(disks::DiskMountManager::GetInstance());
107 disks::DiskMountManager::GetInstance()->AddObserver(this);
108 CheckExistingMountPointsOnUIThread();
109
110 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType)) {
111 scoped_refptr<base::MessageLoopProxy> loop_proxy;
112 device::MediaTransferProtocolManager::Initialize(loop_proxy);
113
114 media_transfer_protocol_device_observer_.reset(
115 new chrome::MediaTransferProtocolDeviceObserverLinux());
116 media_transfer_protocol_device_observer_->SetNotifications(receiver());
117 }
118 }
119
120
102 void RemovableDeviceNotificationsCros::CheckExistingMountPointsOnUIThread() { 121 void RemovableDeviceNotificationsCros::CheckExistingMountPointsOnUIThread() {
103 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 122 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
104 const disks::DiskMountManager::MountPointMap& mount_point_map = 123 const disks::DiskMountManager::MountPointMap& mount_point_map =
105 disks::DiskMountManager::GetInstance()->mount_points(); 124 disks::DiskMountManager::GetInstance()->mount_points();
106 for (disks::DiskMountManager::MountPointMap::const_iterator it = 125 for (disks::DiskMountManager::MountPointMap::const_iterator it =
107 mount_point_map.begin(); it != mount_point_map.end(); ++it) { 126 mount_point_map.begin(); it != mount_point_map.end(); ++it) {
108 BrowserThread::PostTask( 127 BrowserThread::PostTask(
109 BrowserThread::FILE, FROM_HERE, 128 BrowserThread::FILE, FROM_HERE,
110 base::Bind( 129 base::Bind(
111 &RemovableDeviceNotificationsCros::CheckMountedPathOnFileThread, 130 &RemovableDeviceNotificationsCros::CheckMountedPathOnFileThread,
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 storage_size_in_bytes 265 storage_size_in_bytes
247 }; 266 };
248 mount_map_.insert(std::make_pair(mount_info.mount_path, object_info)); 267 mount_map_.insert(std::make_pair(mount_info.mount_path, object_info));
249 receiver()->ProcessAttach(StorageInfo( 268 receiver()->ProcessAttach(StorageInfo(
250 device_id, 269 device_id,
251 chrome::GetDisplayNameForDevice(storage_size_in_bytes, device_label), 270 chrome::GetDisplayNameForDevice(storage_size_in_bytes, device_label),
252 mount_info.mount_path)); 271 mount_info.mount_path));
253 } 272 }
254 273
255 } // namespace chromeos 274 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698