| OLD | NEW |
| 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 <fcntl.h> | 7 #include <fcntl.h> |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 1814 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1825 base::FilePath MTPDeviceDelegateImplLinux::NextUncachedPathComponent( | 1825 base::FilePath MTPDeviceDelegateImplLinux::NextUncachedPathComponent( |
| 1826 const base::FilePath& path, | 1826 const base::FilePath& path, |
| 1827 const base::FilePath& cached_path) const { | 1827 const base::FilePath& cached_path) const { |
| 1828 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 1828 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
| 1829 DCHECK(cached_path.empty() || cached_path.IsParent(path)); | 1829 DCHECK(cached_path.empty() || cached_path.IsParent(path)); |
| 1830 | 1830 |
| 1831 base::FilePath uncached_path; | 1831 base::FilePath uncached_path; |
| 1832 std::string device_relpath = GetDeviceRelativePath(device_path_, path); | 1832 std::string device_relpath = GetDeviceRelativePath(device_path_, path); |
| 1833 if (!device_relpath.empty() && device_relpath != kRootPath) { | 1833 if (!device_relpath.empty() && device_relpath != kRootPath) { |
| 1834 uncached_path = device_path_; | 1834 uncached_path = device_path_; |
| 1835 std::vector<std::string> device_relpath_components; | 1835 std::vector<std::string> device_relpath_components = base::SplitString( |
| 1836 base::SplitString(device_relpath, '/', &device_relpath_components); | 1836 device_relpath, "/", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
| 1837 DCHECK(!device_relpath_components.empty()); | 1837 DCHECK(!device_relpath_components.empty()); |
| 1838 bool all_components_cached = true; | 1838 bool all_components_cached = true; |
| 1839 const MTPFileNode* current_node = root_node_.get(); | 1839 const MTPFileNode* current_node = root_node_.get(); |
| 1840 for (size_t i = 0; i < device_relpath_components.size(); ++i) { | 1840 for (size_t i = 0; i < device_relpath_components.size(); ++i) { |
| 1841 current_node = current_node->GetChild(device_relpath_components[i]); | 1841 current_node = current_node->GetChild(device_relpath_components[i]); |
| 1842 if (!current_node) { | 1842 if (!current_node) { |
| 1843 // With a cache miss, check if it is a genuine failure. If so, pretend | 1843 // With a cache miss, check if it is a genuine failure. If so, pretend |
| 1844 // the entire |path| is cached, so there is no further attempt to do | 1844 // the entire |path| is cached, so there is no further attempt to do |
| 1845 // more caching. The actual operation will then fail. | 1845 // more caching. The actual operation will then fail. |
| 1846 all_components_cached = | 1846 all_components_cached = |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1872 | 1872 |
| 1873 | 1873 |
| 1874 bool MTPDeviceDelegateImplLinux::CachedPathToId(const base::FilePath& path, | 1874 bool MTPDeviceDelegateImplLinux::CachedPathToId(const base::FilePath& path, |
| 1875 uint32* id) const { | 1875 uint32* id) const { |
| 1876 DCHECK(id); | 1876 DCHECK(id); |
| 1877 | 1877 |
| 1878 std::string device_relpath = GetDeviceRelativePath(device_path_, path); | 1878 std::string device_relpath = GetDeviceRelativePath(device_path_, path); |
| 1879 if (device_relpath.empty()) | 1879 if (device_relpath.empty()) |
| 1880 return false; | 1880 return false; |
| 1881 std::vector<std::string> device_relpath_components; | 1881 std::vector<std::string> device_relpath_components; |
| 1882 if (device_relpath != kRootPath) | 1882 if (device_relpath != kRootPath) { |
| 1883 base::SplitString(device_relpath, '/', &device_relpath_components); | 1883 device_relpath_components = base::SplitString( |
| 1884 device_relpath, "/", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
| 1885 } |
| 1884 const MTPFileNode* current_node = root_node_.get(); | 1886 const MTPFileNode* current_node = root_node_.get(); |
| 1885 for (size_t i = 0; i < device_relpath_components.size(); ++i) { | 1887 for (size_t i = 0; i < device_relpath_components.size(); ++i) { |
| 1886 current_node = current_node->GetChild(device_relpath_components[i]); | 1888 current_node = current_node->GetChild(device_relpath_components[i]); |
| 1887 if (!current_node) | 1889 if (!current_node) |
| 1888 return false; | 1890 return false; |
| 1889 } | 1891 } |
| 1890 *id = current_node->file_id(); | 1892 *id = current_node->file_id(); |
| 1891 return true; | 1893 return true; |
| 1892 } | 1894 } |
| 1893 | 1895 |
| 1894 void MTPDeviceDelegateImplLinux::EvictCachedPathToId(const uint32 id) { | 1896 void MTPDeviceDelegateImplLinux::EvictCachedPathToId(const uint32 id) { |
| 1895 FileIdToMTPFileNodeMap::iterator it = file_id_to_node_map_.find(id); | 1897 FileIdToMTPFileNodeMap::iterator it = file_id_to_node_map_.find(id); |
| 1896 if (it != file_id_to_node_map_.end()) { | 1898 if (it != file_id_to_node_map_.end()) { |
| 1897 DCHECK(!it->second->HasChildren()); | 1899 DCHECK(!it->second->HasChildren()); |
| 1898 MTPFileNode* parent = it->second->parent(); | 1900 MTPFileNode* parent = it->second->parent(); |
| 1899 if (parent) { | 1901 if (parent) { |
| 1900 const bool ret = parent->DeleteChild(id); | 1902 const bool ret = parent->DeleteChild(id); |
| 1901 DCHECK(ret); | 1903 DCHECK(ret); |
| 1902 } | 1904 } |
| 1903 } | 1905 } |
| 1904 } | 1906 } |
| 1905 | 1907 |
| 1906 void CreateMTPDeviceAsyncDelegate( | 1908 void CreateMTPDeviceAsyncDelegate( |
| 1907 const std::string& device_location, | 1909 const std::string& device_location, |
| 1908 const bool read_only, | 1910 const bool read_only, |
| 1909 const CreateMTPDeviceAsyncDelegateCallback& callback) { | 1911 const CreateMTPDeviceAsyncDelegateCallback& callback) { |
| 1910 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 1912 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
| 1911 callback.Run(new MTPDeviceDelegateImplLinux(device_location, read_only)); | 1913 callback.Run(new MTPDeviceDelegateImplLinux(device_location, read_only)); |
| 1912 } | 1914 } |
| OLD | NEW |