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

Side by Side Diff: chrome/browser/media_galleries/linux/mtp_device_delegate_impl_linux.cc

Issue 380863002: Cleanup: Fix some misc issues in Linux media galleries MTP code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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 #include "chrome/browser/media_galleries/linux/mtp_device_delegate_impl_linux.h" 5 #include "chrome/browser/media_galleries/linux/mtp_device_delegate_impl_linux.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
11 #include "base/numerics/safe_conversions.h" 11 #include "base/numerics/safe_conversions.h"
12 #include "base/strings/string_util.h" 12 #include "base/strings/string_util.h"
13 #include "chrome/browser/media_galleries/linux/mtp_device_task_helper.h" 13 #include "chrome/browser/media_galleries/linux/mtp_device_task_helper.h"
14 #include "chrome/browser/media_galleries/linux/mtp_device_task_helper_map_servic e.h" 14 #include "chrome/browser/media_galleries/linux/mtp_device_task_helper_map_servic e.h"
15 #include "chrome/browser/media_galleries/linux/snapshot_file_details.h" 15 #include "chrome/browser/media_galleries/linux/snapshot_file_details.h"
16 #include "content/public/browser/browser_thread.h" 16 #include "content/public/browser/browser_thread.h"
17 #include "net/base/io_buffer.h" 17 #include "net/base/io_buffer.h"
18 18
19 namespace { 19 namespace {
20 20
21 // File path separator constant. 21 // File path separator constant.
22 const char kRootPath[] = "/"; 22 const char kRootPath[] = "/";
23 23
24 // Returns the device relative file path given |file_path|. 24 // Returns the device relative file path given |file_path|.
25 // E.g.: If the |file_path| is "/usb:2,2:12345/DCIM" and |registered_dev_path| 25 // E.g.: If the |file_path| is "/usb:2,2:12345/DCIM" and |registered_dev_path|
26 // is "/usb:2,2:12345", this function returns the device relative path which is 26 // is "/usb:2,2:12345", this function returns the device relative path which is
27 // "/DCIM". 27 // "DCIM".
28 // In the special case when |registered_dev_path| and |file_path| are the same,
29 // return |kRootPath|.
28 std::string GetDeviceRelativePath(const base::FilePath& registered_dev_path, 30 std::string GetDeviceRelativePath(const base::FilePath& registered_dev_path,
29 const base::FilePath& file_path) { 31 const base::FilePath& file_path) {
30 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 32 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
31 DCHECK(!registered_dev_path.empty()); 33 DCHECK(!registered_dev_path.empty());
32 DCHECK(!file_path.empty()); 34 DCHECK(!file_path.empty());
33 if (registered_dev_path == file_path) 35 std::string result;
34 return kRootPath; 36 if (registered_dev_path == file_path) {
35 37 result = kRootPath;
36 base::FilePath relative_path; 38 } else {
37 if (!registered_dev_path.AppendRelativePath(file_path, &relative_path)) 39 base::FilePath relative_path;
38 return std::string(); 40 if (registered_dev_path.AppendRelativePath(file_path, &relative_path)) {
39 DCHECK(!relative_path.empty()); 41 DCHECK(!relative_path.empty());
40 return relative_path.value(); 42 result = relative_path.value();
43 }
44 }
45 return result;
41 } 46 }
42 47
43 // Returns the MTPDeviceTaskHelper object associated with the MTP device 48 // Returns the MTPDeviceTaskHelper object associated with the MTP device
44 // storage. 49 // storage.
45 // 50 //
46 // |storage_name| specifies the name of the storage device. 51 // |storage_name| specifies the name of the storage device.
47 // Returns NULL if the |storage_name| is no longer valid (e.g. because the 52 // Returns NULL if the |storage_name| is no longer valid (e.g. because the
48 // corresponding storage device is detached, etc). 53 // corresponding storage device is detached, etc).
49 MTPDeviceTaskHelper* GetDeviceTaskHelperForStorage( 54 MTPDeviceTaskHelper* GetDeviceTaskHelperForStorage(
50 const std::string& storage_name) { 55 const std::string& storage_name) {
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 task_in_progress_ = false; 512 task_in_progress_ = false;
508 ProcessNextPendingRequest(); 513 ProcessNextPendingRequest();
509 } 514 }
510 515
511 void CreateMTPDeviceAsyncDelegate( 516 void CreateMTPDeviceAsyncDelegate(
512 const std::string& device_location, 517 const std::string& device_location,
513 const CreateMTPDeviceAsyncDelegateCallback& callback) { 518 const CreateMTPDeviceAsyncDelegateCallback& callback) {
514 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 519 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
515 callback.Run(new MTPDeviceDelegateImplLinux(device_location)); 520 callback.Run(new MTPDeviceDelegateImplLinux(device_location));
516 } 521 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698