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

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

Issue 14016002: Storage Monitor: Make StorageMonitorLinux own the MediaTransferProtocolManager. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix browser_tests Created 7 years, 8 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 | Annotate | Revision Log
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 // 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/command_line.h"
17 #include "base/metrics/histogram.h" 17 #include "base/metrics/histogram.h"
18 #include "base/stl_util.h" 18 #include "base/stl_util.h"
19 #include "base/string_util.h" 19 #include "base/string_util.h"
20 #include "base/strings/string_number_conversions.h" 20 #include "base/strings/string_number_conversions.h"
21 #include "base/utf_string_conversions.h" 21 #include "base/utf_string_conversions.h"
22 #include "chrome/browser/storage_monitor/media_storage_util.h" 22 #include "chrome/browser/storage_monitor/media_storage_util.h"
23 #include "chrome/browser/storage_monitor/media_transfer_protocol_device_observer _linux.h" 23 #include "chrome/browser/storage_monitor/media_transfer_protocol_device_observer _linux.h"
24 #include "chrome/browser/storage_monitor/removable_device_constants.h" 24 #include "chrome/browser/storage_monitor/removable_device_constants.h"
25 #include "chrome/browser/storage_monitor/test_media_transfer_protocol_manager_li nux.h"
25 #include "chrome/browser/storage_monitor/udev_util_linux.h" 26 #include "chrome/browser/storage_monitor/udev_util_linux.h"
26 #include "chrome/common/chrome_switches.h" 27 #include "chrome/common/chrome_switches.h"
27 #include "device/media_transfer_protocol/media_transfer_protocol_manager.h" 28 #include "device/media_transfer_protocol/media_transfer_protocol_manager.h"
28 29
29 namespace chrome { 30 namespace chrome {
30 31
31 using content::BrowserThread; 32 using content::BrowserThread;
32 typedef MtabWatcherLinux::MountPointDeviceMap MountPointDeviceMap; 33 typedef MtabWatcherLinux::MountPointDeviceMap MountPointDeviceMap;
33 34
34 namespace { 35 namespace {
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 return new MtabWatcherLinux(mtab_path, delegate); 226 return new MtabWatcherLinux(mtab_path, delegate);
226 } 227 }
227 228
228 } // namespace 229 } // namespace
229 230
230 StorageMonitorLinux::StorageMonitorLinux(const base::FilePath& path) 231 StorageMonitorLinux::StorageMonitorLinux(const base::FilePath& path)
231 : mtab_path_(path), 232 : mtab_path_(path),
232 get_device_info_callback_(base::Bind(&GetDeviceInfo)), 233 get_device_info_callback_(base::Bind(&GetDeviceInfo)),
233 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { 234 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {
234 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 235 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
236
237 // TODO(thestig) Do not do this here. Do it in TestingBrowserProcess when
238 // BrowserProcess owns StorageMonitor.
239 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType)) {
240 SetMediaTransferProtocolManagerForTest(
241 new TestMediaTransferProtocolManagerLinux());
242 }
235 } 243 }
236 244
237 StorageMonitorLinux::~StorageMonitorLinux() { 245 StorageMonitorLinux::~StorageMonitorLinux() {
238 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 246 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
239 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType))
240 device::MediaTransferProtocolManager::Shutdown();
241 } 247 }
242 248
243 void StorageMonitorLinux::Init() { 249 void StorageMonitorLinux::Init() {
244 DCHECK(!mtab_path_.empty()); 250 DCHECK(!mtab_path_.empty());
245 251
246 BrowserThread::PostTaskAndReplyWithResult( 252 BrowserThread::PostTaskAndReplyWithResult(
247 BrowserThread::FILE, FROM_HERE, 253 BrowserThread::FILE, FROM_HERE,
248 base::Bind(&CreateMtabWatcherLinuxOnFileThread, 254 base::Bind(&CreateMtabWatcherLinuxOnFileThread,
249 mtab_path_, 255 mtab_path_,
250 weak_ptr_factory_.GetWeakPtr()), 256 weak_ptr_factory_.GetWeakPtr()),
251 base::Bind(&StorageMonitorLinux::OnMtabWatcherCreated, 257 base::Bind(&StorageMonitorLinux::OnMtabWatcherCreated,
252 weak_ptr_factory_.GetWeakPtr())); 258 weak_ptr_factory_.GetWeakPtr()));
253 259
254 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType)) { 260 if (!media_transfer_protocol_manager_) {
255 scoped_refptr<base::MessageLoopProxy> loop_proxy; 261 scoped_refptr<base::MessageLoopProxy> loop_proxy =
256 loop_proxy = content::BrowserThread::GetMessageLoopProxyForThread( 262 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE);
257 content::BrowserThread::FILE); 263 media_transfer_protocol_manager_.reset(
258 device::MediaTransferProtocolManager::Initialize(loop_proxy); 264 device::MediaTransferProtocolManager::Initialize(loop_proxy));
265 }
259 266
260 media_transfer_protocol_device_observer_.reset( 267 media_transfer_protocol_device_observer_.reset(
261 new MediaTransferProtocolDeviceObserverLinux(receiver())); 268 new MediaTransferProtocolDeviceObserverLinux(receiver()));
262 }
263 } 269 }
264 270
265 bool StorageMonitorLinux::GetStorageInfoForPath( 271 bool StorageMonitorLinux::GetStorageInfoForPath(
266 const base::FilePath& path, 272 const base::FilePath& path,
267 StorageInfo* device_info) const { 273 StorageInfo* device_info) const {
268 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 274 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
269 275
270 // TODO(thestig) |media_transfer_protocol_device_observer_| should always be 276 // TODO(thestig) |media_transfer_protocol_device_observer_| should always be
271 // valid. 277 // valid.
272 if (media_transfer_protocol_device_observer_ && 278 if (media_transfer_protocol_device_observer_ &&
(...skipping 10 matching lines...) Expand all
283 current = current.DirName(); 289 current = current.DirName();
284 290
285 MountMap::const_iterator mount_info = mount_info_map_.find(current); 291 MountMap::const_iterator mount_info = mount_info_map_.find(current);
286 if (mount_info == mount_info_map_.end()) 292 if (mount_info == mount_info_map_.end())
287 return false; 293 return false;
288 if (device_info) 294 if (device_info)
289 *device_info = mount_info->second.storage_info; 295 *device_info = mount_info->second.storage_info;
290 return true; 296 return true;
291 } 297 }
292 298
299 device::MediaTransferProtocolManager*
300 StorageMonitorLinux::media_transfer_protocol_manager() {
301 return media_transfer_protocol_manager_.get();
302 }
303
293 void StorageMonitorLinux::SetGetDeviceInfoCallbackForTest( 304 void StorageMonitorLinux::SetGetDeviceInfoCallbackForTest(
294 const GetDeviceInfoCallback& get_device_info_callback) { 305 const GetDeviceInfoCallback& get_device_info_callback) {
295 get_device_info_callback_ = get_device_info_callback; 306 get_device_info_callback_ = get_device_info_callback;
296 } 307 }
297 308
309 void StorageMonitorLinux::SetMediaTransferProtocolManagerForTest(
310 device::MediaTransferProtocolManager* test_manager) {
311 DCHECK(!media_transfer_protocol_manager_);
312 media_transfer_protocol_manager_.reset(test_manager);
313 }
314
298 void StorageMonitorLinux::OnMtabWatcherCreated(MtabWatcherLinux* watcher) { 315 void StorageMonitorLinux::OnMtabWatcherCreated(MtabWatcherLinux* watcher) {
299 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 316 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
300 mtab_watcher_.reset(watcher); 317 mtab_watcher_.reset(watcher);
301 } 318 }
302 319
303 void StorageMonitorLinux::UpdateMtab(const MountPointDeviceMap& new_mtab) { 320 void StorageMonitorLinux::UpdateMtab(const MountPointDeviceMap& new_mtab) {
304 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 321 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
305 322
306 // Check existing mtab entries for unaccounted mount points. 323 // Check existing mtab entries for unaccounted mount points.
307 // These mount points must have been removed in the new mtab. 324 // These mount points must have been removed in the new mtab.
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 445
429 if (removable) { 446 if (removable) {
430 // TODO(gbillock) Do this in a higher level instead of here. 447 // TODO(gbillock) Do this in a higher level instead of here.
431 storage_info->name = MediaStorageUtil::GetDisplayNameForDevice( 448 storage_info->name = MediaStorageUtil::GetDisplayNameForDevice(
432 storage_info->total_size_in_bytes, storage_info->name); 449 storage_info->total_size_in_bytes, storage_info->name);
433 receiver()->ProcessAttach(*storage_info); 450 receiver()->ProcessAttach(*storage_info);
434 } 451 }
435 } 452 }
436 453
437 } // namespace chrome 454 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698