OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/extensions/file_manager/private_api_util.h" | 5 #include "chrome/browser/chromeos/extensions/file_manager/private_api_util.h" |
6 | 6 |
7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "chrome/browser/chromeos/drive/drive.pb.h" | 8 #include "chrome/browser/chromeos/drive/drive.pb.h" |
9 #include "chrome/browser/chromeos/drive/drive_integration_service.h" | 9 #include "chrome/browser/chromeos/drive/drive_integration_service.h" |
10 #include "chrome/browser/chromeos/drive/file_errors.h" | 10 #include "chrome/browser/chromeos/drive/file_errors.h" |
(...skipping 14 matching lines...) Expand all Loading... | |
25 using content::BrowserThread; | 25 using content::BrowserThread; |
26 using google_apis::InstalledApp; | 26 using google_apis::InstalledApp; |
27 | 27 |
28 namespace file_manager { | 28 namespace file_manager { |
29 namespace util { | 29 namespace util { |
30 namespace { | 30 namespace { |
31 | 31 |
32 // The struct is used for GetSelectedFileInfo(). | 32 // The struct is used for GetSelectedFileInfo(). |
33 struct GetSelectedFileInfoParams { | 33 struct GetSelectedFileInfoParams { |
34 bool for_opening; | 34 bool for_opening; |
35 bool need_local_path; | |
35 GetSelectedFileInfoCallback callback; | 36 GetSelectedFileInfoCallback callback; |
36 std::vector<base::FilePath> file_paths; | 37 std::vector<base::FilePath> file_paths; |
37 std::vector<ui::SelectedFileInfo> selected_files; | 38 std::vector<ui::SelectedFileInfo> selected_files; |
38 }; | 39 }; |
39 | 40 |
40 // Forward declarations of helper functions for GetSelectedFileInfo(). | 41 // Forward declarations of helper functions for GetSelectedFileInfo(). |
41 void ContinueGetSelectedFileInfo(Profile* profile, | 42 void ContinueGetSelectedFileInfo(Profile* profile, |
42 scoped_ptr<GetSelectedFileInfoParams> params, | 43 scoped_ptr<GetSelectedFileInfoParams> params, |
43 drive::FileError error, | 44 drive::FileError error, |
44 const base::FilePath& local_file_path, | 45 const base::FilePath& local_file_path, |
45 scoped_ptr<drive::ResourceEntry> entry); | 46 scoped_ptr<drive::ResourceEntry> entry); |
46 | 47 |
47 // Part of GetSelectedFileInfo(). | 48 // Part of GetSelectedFileInfo(). |
48 void GetSelectedFileInfoInternal(Profile* profile, | 49 void GetSelectedFileInfoInternal(Profile* profile, |
49 scoped_ptr<GetSelectedFileInfoParams> params) { | 50 scoped_ptr<GetSelectedFileInfoParams> params) { |
50 DCHECK(profile); | 51 DCHECK(profile); |
51 | 52 |
52 for (size_t i = params->selected_files.size(); | 53 for (size_t i = params->selected_files.size(); |
53 i < params->file_paths.size(); ++i) { | 54 i < params->file_paths.size(); ++i) { |
54 const base::FilePath& file_path = params->file_paths[i]; | 55 const base::FilePath& file_path = params->file_paths[i]; |
55 // When opening a drive file, we should get local file path. | 56 // When opening a drive file, we should get local file path. |
satorux1
2013/08/06 02:07:17
the comment needs to be updated? now need_local_pa
kinaba
2013/08/06 06:20:56
Done.
| |
56 if (params->for_opening && | 57 if (params->for_opening && |
58 params->need_local_path && | |
57 drive::util::IsUnderDriveMountPoint(file_path)) { | 59 drive::util::IsUnderDriveMountPoint(file_path)) { |
58 drive::DriveIntegrationService* integration_service = | 60 drive::DriveIntegrationService* integration_service = |
59 drive::DriveIntegrationServiceFactory::GetForProfile(profile); | 61 drive::DriveIntegrationServiceFactory::GetForProfile(profile); |
60 // |integration_service| is NULL if Drive is disabled. | 62 // |integration_service| is NULL if Drive is disabled. |
61 if (!integration_service) { | 63 if (!integration_service) { |
62 ContinueGetSelectedFileInfo(profile, | 64 ContinueGetSelectedFileInfo(profile, |
63 params.Pass(), | 65 params.Pass(), |
64 drive::FILE_ERROR_FAILED, | 66 drive::FILE_ERROR_FAILED, |
65 base::FilePath(), | 67 base::FilePath(), |
66 scoped_ptr<drive::ResourceEntry>()); | 68 scoped_ptr<drive::ResourceEntry>()); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
151 base::FilePath path; | 153 base::FilePath path; |
152 if (!chromeos::FileSystemBackend::CanHandleURL(filesystem_url)) | 154 if (!chromeos::FileSystemBackend::CanHandleURL(filesystem_url)) |
153 return base::FilePath(); | 155 return base::FilePath(); |
154 return filesystem_url.path(); | 156 return filesystem_url.path(); |
155 } | 157 } |
156 | 158 |
157 void GetSelectedFileInfo(content::RenderViewHost* render_view_host, | 159 void GetSelectedFileInfo(content::RenderViewHost* render_view_host, |
158 Profile* profile, | 160 Profile* profile, |
159 const std::vector<GURL>& file_urls, | 161 const std::vector<GURL>& file_urls, |
160 bool for_opening, | 162 bool for_opening, |
163 bool need_local_path, | |
161 GetSelectedFileInfoCallback callback) { | 164 GetSelectedFileInfoCallback callback) { |
162 DCHECK(render_view_host); | 165 DCHECK(render_view_host); |
163 DCHECK(profile); | 166 DCHECK(profile); |
164 | 167 |
165 scoped_ptr<GetSelectedFileInfoParams> params(new GetSelectedFileInfoParams); | 168 scoped_ptr<GetSelectedFileInfoParams> params(new GetSelectedFileInfoParams); |
166 params->for_opening = for_opening; | 169 params->for_opening = for_opening; |
170 params->need_local_path = need_local_path; | |
167 params->callback = callback; | 171 params->callback = callback; |
168 | 172 |
169 for (size_t i = 0; i < file_urls.size(); ++i) { | 173 for (size_t i = 0; i < file_urls.size(); ++i) { |
170 const GURL& file_url = file_urls[i]; | 174 const GURL& file_url = file_urls[i]; |
171 const base::FilePath path = GetLocalPathFromURL( | 175 const base::FilePath path = GetLocalPathFromURL( |
172 render_view_host, profile, file_url); | 176 render_view_host, profile, file_url); |
173 if (!path.empty()) { | 177 if (!path.empty()) { |
174 DVLOG(1) << "Selected: file path: " << path.value(); | 178 DVLOG(1) << "Selected: file path: " << path.value(); |
175 params->file_paths.push_back(path); | 179 params->file_paths.push_back(path); |
176 } | 180 } |
177 } | 181 } |
178 | 182 |
179 BrowserThread::PostTask( | 183 BrowserThread::PostTask( |
180 BrowserThread::UI, FROM_HERE, | 184 BrowserThread::UI, FROM_HERE, |
181 base::Bind(&GetSelectedFileInfoInternal, | 185 base::Bind(&GetSelectedFileInfoInternal, |
182 profile, | 186 profile, |
183 base::Passed(¶ms))); | 187 base::Passed(¶ms))); |
184 } | 188 } |
185 | 189 |
186 } // namespace util | 190 } // namespace util |
187 } // namespace file_manager | 191 } // namespace file_manager |
OLD | NEW |