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

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

Issue 13533009: Storage Monitor: Remove MediaTransferProtocolDeviceObserverLinux::GetInstance() and access it only … (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: rebase 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
« no previous file with comments | « no previous file | chrome/browser/storage_monitor/media_transfer_protocol_device_observer_linux.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "chrome/browser/storage_monitor/media_storage_util.h" 5 #include "chrome/browser/storage_monitor/media_storage_util.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/metrics/histogram.h" 12 #include "base/metrics/histogram.h"
13 #include "base/string_util.h" 13 #include "base/string_util.h"
14 #include "base/utf_string_conversions.h" 14 #include "base/utf_string_conversions.h"
15 #include "chrome/browser/storage_monitor/removable_device_constants.h" 15 #include "chrome/browser/storage_monitor/removable_device_constants.h"
16 #include "chrome/browser/storage_monitor/storage_monitor.h" 16 #include "chrome/browser/storage_monitor/storage_monitor.h"
17 #include "content/public/browser/browser_thread.h" 17 #include "content/public/browser/browser_thread.h"
18 #include "ui/base/text/bytes_formatting.h" 18 #include "ui/base/text/bytes_formatting.h"
19 19
20 #if defined(OS_LINUX) // Implies OS_CHROMEOS
21 #include "chrome/browser/storage_monitor/media_transfer_protocol_device_observer _linux.h"
22 #endif
23
24 using content::BrowserThread; 20 using content::BrowserThread;
25 21
26 namespace chrome { 22 namespace chrome {
27 23
28 namespace { 24 namespace {
29 25
30 // MediaDeviceNotification.DeviceInfo histogram values. 26 // MediaDeviceNotification.DeviceInfo histogram values.
31 enum DeviceInfoHistogramBuckets { 27 enum DeviceInfoHistogramBuckets {
32 MASS_STORAGE_DEVICE_NAME_AND_UUID_AVAILABLE, 28 MASS_STORAGE_DEVICE_NAME_AND_UUID_AVAILABLE,
33 MASS_STORAGE_DEVICE_UUID_MISSING, 29 MASS_STORAGE_DEVICE_UUID_MISSING,
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 done); 290 done);
295 } 291 }
296 292
297 // TODO(kmadhusu) Write unit tests for GetDeviceInfoFromPath(). 293 // TODO(kmadhusu) Write unit tests for GetDeviceInfoFromPath().
298 bool MediaStorageUtil::GetDeviceInfoFromPath(const base::FilePath& path, 294 bool MediaStorageUtil::GetDeviceInfoFromPath(const base::FilePath& path,
299 StorageInfo* device_info, 295 StorageInfo* device_info,
300 base::FilePath* relative_path) { 296 base::FilePath* relative_path) {
301 if (!path.IsAbsolute()) 297 if (!path.IsAbsolute())
302 return false; 298 return false;
303 299
304 bool found_device = false;
305 StorageInfo info; 300 StorageInfo info;
306 StorageMonitor* monitor = StorageMonitor::GetInstance(); 301 StorageMonitor* monitor = StorageMonitor::GetInstance();
307 found_device = monitor->GetStorageInfoForPath(path, &info); 302 bool found_device = monitor->GetStorageInfoForPath(path, &info);
308
309 // TODO(gbillock): Move this upstream into the RemovableStorageNotifications
310 // implementation to handle in its GetDeviceInfoForPath call.
311 #if defined(OS_LINUX)
312 if (!found_device) {
313 MediaTransferProtocolDeviceObserverLinux* mtp_manager =
314 MediaTransferProtocolDeviceObserverLinux::GetInstance();
315 found_device = mtp_manager->GetStorageInfoForPath(path, &info);
316 }
317 #endif
318 303
319 if (found_device && IsRemovableDevice(info.device_id)) { 304 if (found_device && IsRemovableDevice(info.device_id)) {
320 base::FilePath sub_folder_path; 305 base::FilePath sub_folder_path;
321 if (path.value() != info.location) { 306 if (path.value() != info.location) {
322 base::FilePath device_path(info.location); 307 base::FilePath device_path(info.location);
323 bool success = device_path.AppendRelativePath(path, &sub_folder_path); 308 bool success = device_path.AppendRelativePath(path, &sub_folder_path);
324 DCHECK(success); 309 DCHECK(success);
325 } 310 }
326 311
327 // TODO(gbillock): Don't do this. Leave for clients to do. 312 // TODO(gbillock): Don't do this. Leave for clients to do.
(...skipping 11 matching lines...) Expand all
339 return true; 324 return true;
340 } 325 }
341 326
342 // On Posix systems, there's one root so any absolute path could be valid. 327 // On Posix systems, there's one root so any absolute path could be valid.
343 #if !defined(OS_POSIX) 328 #if !defined(OS_POSIX)
344 if (!found_device) 329 if (!found_device)
345 return false; 330 return false;
346 #endif 331 #endif
347 332
348 // Handle non-removable devices. Note: this is just overwriting 333 // Handle non-removable devices. Note: this is just overwriting
349 // good values from RemovableStorageNotifications. 334 // good values from StorageMonitor.
350 // TODO(gbillock): Make sure return values from that class are definitive, 335 // TODO(gbillock): Make sure return values from that class are definitive,
351 // and don't do this here. 336 // and don't do this here.
352 info.device_id = MakeDeviceId(FIXED_MASS_STORAGE, path.AsUTF8Unsafe()); 337 info.device_id = MakeDeviceId(FIXED_MASS_STORAGE, path.AsUTF8Unsafe());
353 info.name = path.BaseName().LossyDisplayName(); 338 info.name = path.BaseName().LossyDisplayName();
354 if (device_info) 339 if (device_info)
355 *device_info = info; 340 *device_info = info;
356 if (relative_path) 341 if (relative_path)
357 *relative_path = base::FilePath(); 342 *relative_path = base::FilePath();
358 return true; 343 return true;
359 } 344 }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 static_cast<enum DeviceInfoHistogramBuckets>(event_number); 387 static_cast<enum DeviceInfoHistogramBuckets>(event_number);
403 if (event >= DEVICE_INFO_BUCKET_BOUNDARY) { 388 if (event >= DEVICE_INFO_BUCKET_BOUNDARY) {
404 NOTREACHED(); 389 NOTREACHED();
405 return; 390 return;
406 } 391 }
407 UMA_HISTOGRAM_ENUMERATION("MediaDeviceNotifications.DeviceInfo", event, 392 UMA_HISTOGRAM_ENUMERATION("MediaDeviceNotifications.DeviceInfo", event,
408 DEVICE_INFO_BUCKET_BOUNDARY); 393 DEVICE_INFO_BUCKET_BOUNDARY);
409 } 394 }
410 395
411 } // namespace chrome 396 } // namespace chrome
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/storage_monitor/media_transfer_protocol_device_observer_linux.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698