OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/chromeos/file_manager/filesystem_api_util.h" | 5 #include "chrome/browser/chromeos/file_manager/filesystem_api_util.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "chrome/browser/chromeos/drive/file_errors.h" | 10 #include "chrome/browser/chromeos/drive/file_errors.h" |
(...skipping 18 matching lines...) Expand all Loading... | |
29 scoped_ptr<drive::ResourceEntry> entry) { | 29 scoped_ptr<drive::ResourceEntry> entry) { |
30 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 30 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
31 | 31 |
32 if (error != drive::FILE_ERROR_OK || !entry->has_file_specific_info()) { | 32 if (error != drive::FILE_ERROR_OK || !entry->has_file_specific_info()) { |
33 callback.Run(false, std::string()); | 33 callback.Run(false, std::string()); |
34 return; | 34 return; |
35 } | 35 } |
36 callback.Run(true, entry->file_specific_info().content_mime_type()); | 36 callback.Run(true, entry->file_specific_info().content_mime_type()); |
37 } | 37 } |
38 | 38 |
39 void CheckDirectoryAfterDriveCheck(const base::Callback<void(bool)>& callback, | 39 // Helper function to converts a callback that takes boolean value to that takes |
40 drive::FileError error) { | 40 // File::Error, by regarding FILE_OK as the only successful value. |
41 void BoolCallbackAsFileErrorCallback( | |
42 const base::Callback<void(bool)>& callback, | |
43 base::File::Error error) { | |
41 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 44 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
42 | 45 |
43 return callback.Run(error == drive::FILE_ERROR_OK); | 46 return callback.Run(error == base::File::FILE_OK); |
44 } | 47 } |
45 | 48 |
46 void CheckWritableAfterDriveCheck(const base::Callback<void(bool)>& callback, | 49 void CheckWritableAfterDriveCheck(const base::Callback<void(bool)>& callback, |
47 drive::FileError error, | 50 drive::FileError error, |
48 const base::FilePath& local_path) { | 51 const base::FilePath& local_path) { |
49 // This is called on the IO-allowed blocking pool. Call back to UI. | 52 // This is called on the IO-allowed blocking pool. Call back to UI. |
50 content::BrowserThread::PostTask( | 53 content::BrowserThread::PostTask( |
51 content::BrowserThread::UI, | 54 content::BrowserThread::UI, |
52 FROM_HERE, | 55 FROM_HERE, |
53 base::Bind(callback, error == drive::FILE_ERROR_OK)); | 56 base::Bind(callback, error == drive::FILE_ERROR_OK)); |
54 } | 57 } |
55 | 58 |
56 } // namespace | 59 } // namespace |
57 | 60 |
58 bool IsUnderNonNativeLocalPath(Profile* profile, | 61 bool IsUnderNonNativeLocalPath(Profile* profile, |
59 const base::FilePath& path) { | 62 const base::FilePath& path) { |
60 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 63 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
61 | 64 |
62 GURL url; | 65 GURL url; |
63 if (!util::ConvertAbsoluteFilePathToFileSystemUrl( | 66 if (!util::ConvertAbsoluteFilePathToFileSystemUrl( |
64 profile, path, kFileManagerAppId, &url)) { | 67 profile, path, kFileManagerAppId, &url)) { |
65 return false; | 68 return false; |
66 } | 69 } |
67 | 70 |
68 content::StoragePartition* partition = | 71 fileapi::FileSystemURL filesystem_url = |
69 content::BrowserContext::GetStoragePartitionForSite( | 72 GetFileSystemContextForExtensionId(profile, |
70 profile, | 73 kFileManagerAppId)->CrackURL(url); |
71 extensions::util::GetSiteForExtensionId(kFileManagerAppId, profile)); | |
72 fileapi::FileSystemContext* context = partition->GetFileSystemContext(); | |
73 | |
74 fileapi::FileSystemURL filesystem_url = context->CrackURL(url); | |
75 if (!filesystem_url.is_valid()) | 74 if (!filesystem_url.is_valid()) |
76 return false; | 75 return false; |
77 | 76 |
78 switch (filesystem_url.type()) { | 77 switch (filesystem_url.type()) { |
79 case fileapi::kFileSystemTypeNativeLocal: | 78 case fileapi::kFileSystemTypeNativeLocal: |
80 case fileapi::kFileSystemTypeRestrictedNativeLocal: | 79 case fileapi::kFileSystemTypeRestrictedNativeLocal: |
81 return false; | 80 return false; |
82 default: | 81 default: |
83 // The path indeed corresponds to a mount point not associated with a | 82 // The path indeed corresponds to a mount point not associated with a |
84 // native local path. | 83 // native local path. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
116 file_system->GetResourceEntry( | 115 file_system->GetResourceEntry( |
117 drive::util::ExtractDrivePath(path), | 116 drive::util::ExtractDrivePath(path), |
118 base::Bind(&GetMimeTypeAfterGetResourceEntry, callback)); | 117 base::Bind(&GetMimeTypeAfterGetResourceEntry, callback)); |
119 } | 118 } |
120 | 119 |
121 void IsNonNativeLocalPathDirectory( | 120 void IsNonNativeLocalPathDirectory( |
122 Profile* profile, | 121 Profile* profile, |
123 const base::FilePath& path, | 122 const base::FilePath& path, |
124 const base::Callback<void(bool)>& callback) { | 123 const base::Callback<void(bool)>& callback) { |
125 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 124 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
125 DCHECK(IsUnderNonNativeLocalPath(profile, path)); | |
126 | 126 |
127 // TODO(kinaba): support other types of volumes besides Drive. | 127 GURL url; |
128 drive::util::CheckDirectoryExists( | 128 if (!util::ConvertAbsoluteFilePathToFileSystemUrl( |
129 profile, | 129 profile, path, kFileManagerAppId, &url)) { |
130 path, | 130 content::BrowserThread::PostTask(content::BrowserThread::UI, |
mtomasz
2014/05/30 03:53:44
This PostTask looks unnecessary, since we are alre
kinaba
2014/05/30 04:07:01
This is intentional to make all callbacks done asy
mtomasz
2014/05/30 05:23:48
Hm. Isn't it an overkill? Do we always do that? If
kinaba
2014/05/30 05:43:00
We always do it at least in the Drive code (see, e
mtomasz
2014/05/30 05:55:07
Got it. I'll review File System Provider API code
| |
131 base::Bind(&CheckDirectoryAfterDriveCheck, callback)); | 131 FROM_HERE, |
132 base::Bind(callback, false)); | |
133 return; | |
134 } | |
135 | |
136 util::CheckIfDirectoryExists( | |
137 GetFileSystemContextForExtensionId(profile, kFileManagerAppId), | |
138 url, | |
139 base::Bind(&BoolCallbackAsFileErrorCallback, callback)); | |
132 } | 140 } |
133 | 141 |
134 void PrepareNonNativeLocalPathWritableFile( | 142 void PrepareNonNativeLocalPathWritableFile( |
135 Profile* profile, | 143 Profile* profile, |
136 const base::FilePath& path, | 144 const base::FilePath& path, |
137 const base::Callback<void(bool)>& callback) { | 145 const base::Callback<void(bool)>& callback) { |
138 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 146 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
139 | 147 |
140 // TODO(kinaba): support other types of volumes besides Drive. | 148 // TODO(kinaba): support other types of volumes besides Drive. |
141 drive::util::PrepareWritableFileAndRun( | 149 drive::util::PrepareWritableFileAndRun( |
142 profile, | 150 profile, |
143 path, | 151 path, |
144 base::Bind(&CheckWritableAfterDriveCheck, callback)); | 152 base::Bind(&CheckWritableAfterDriveCheck, callback)); |
145 } | 153 } |
146 | 154 |
147 } // namespace util | 155 } // namespace util |
148 } // namespace file_manager | 156 } // namespace file_manager |
OLD | NEW |