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

Side by Side Diff: chrome/browser/chromeos/extensions/file_manager/private_api_util.cc

Issue 22165002: Change the meaning of SelectFileDialog.support_drive: it means Drive-aware callers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review fix (#2). Created 7 years, 4 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 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 13 matching lines...) Expand all
24 24
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 GetSelectedFileInfoLocalPathOption local_path_option;
35 GetSelectedFileInfoCallback callback; 35 GetSelectedFileInfoCallback callback;
36 std::vector<base::FilePath> file_paths; 36 std::vector<base::FilePath> file_paths;
37 std::vector<ui::SelectedFileInfo> selected_files; 37 std::vector<ui::SelectedFileInfo> selected_files;
38 }; 38 };
39 39
40 // Forward declarations of helper functions for GetSelectedFileInfo(). 40 // Forward declarations of helper functions for GetSelectedFileInfo().
41 void ContinueGetSelectedFileInfo(Profile* profile, 41 void ContinueGetSelectedFileInfo(Profile* profile,
42 scoped_ptr<GetSelectedFileInfoParams> params, 42 scoped_ptr<GetSelectedFileInfoParams> params,
43 drive::FileError error, 43 drive::FileError error,
44 const base::FilePath& local_file_path, 44 const base::FilePath& local_file_path,
45 scoped_ptr<drive::ResourceEntry> entry); 45 scoped_ptr<drive::ResourceEntry> entry);
46 46
47 // Part of GetSelectedFileInfo(). 47 // Part of GetSelectedFileInfo().
48 void GetSelectedFileInfoInternal(Profile* profile, 48 void GetSelectedFileInfoInternal(Profile* profile,
49 scoped_ptr<GetSelectedFileInfoParams> params) { 49 scoped_ptr<GetSelectedFileInfoParams> params) {
50 DCHECK(profile); 50 DCHECK(profile);
51 51
52 for (size_t i = params->selected_files.size(); 52 for (size_t i = params->selected_files.size();
53 i < params->file_paths.size(); ++i) { 53 i < params->file_paths.size(); ++i) {
54 const base::FilePath& file_path = params->file_paths[i]; 54 const base::FilePath& file_path = params->file_paths[i];
55 // When opening a drive file, we should get local file path. 55 // When the caller of the select file dialog wants local file paths,
56 if (params->for_opening && 56 // we should retrieve Drive files onto the local cache.
57 drive::util::IsUnderDriveMountPoint(file_path)) { 57 if (params->local_path_option == NO_LOCAL_PATH_RESOLUTION ||
58 !drive::util::IsUnderDriveMountPoint(file_path)) {
59 params->selected_files.push_back(
60 ui::SelectedFileInfo(file_path, base::FilePath()));
61 } else {
58 drive::DriveIntegrationService* integration_service = 62 drive::DriveIntegrationService* integration_service =
59 drive::DriveIntegrationServiceFactory::GetForProfile(profile); 63 drive::DriveIntegrationServiceFactory::GetForProfile(profile);
60 // |integration_service| is NULL if Drive is disabled. 64 // |integration_service| is NULL if Drive is disabled.
61 if (!integration_service) { 65 if (!integration_service) {
62 ContinueGetSelectedFileInfo(profile, 66 ContinueGetSelectedFileInfo(profile,
63 params.Pass(), 67 params.Pass(),
64 drive::FILE_ERROR_FAILED, 68 drive::FILE_ERROR_FAILED,
65 base::FilePath(), 69 base::FilePath(),
66 scoped_ptr<drive::ResourceEntry>()); 70 scoped_ptr<drive::ResourceEntry>());
67 return; 71 return;
68 } 72 }
73 // TODO(kinaba): crbug.com/140425 support FOR_SAVING
74 DCHECK(params->local_path_option == NEED_LOCAL_PATH_FOR_OPENING);
69 integration_service->file_system()->GetFileByPath( 75 integration_service->file_system()->GetFileByPath(
70 drive::util::ExtractDrivePath(file_path), 76 drive::util::ExtractDrivePath(file_path),
71 base::Bind(&ContinueGetSelectedFileInfo, 77 base::Bind(&ContinueGetSelectedFileInfo,
72 profile, 78 profile,
73 base::Passed(&params))); 79 base::Passed(&params)));
74 return; 80 return;
75 } else {
76 params->selected_files.push_back(
77 ui::SelectedFileInfo(file_path, base::FilePath()));
78 } 81 }
79 } 82 }
80 params->callback.Run(params->selected_files); 83 params->callback.Run(params->selected_files);
81 } 84 }
82 85
83 // Part of GetSelectedFileInfo(). 86 // Part of GetSelectedFileInfo().
84 void ContinueGetSelectedFileInfo(Profile* profile, 87 void ContinueGetSelectedFileInfo(Profile* profile,
85 scoped_ptr<GetSelectedFileInfoParams> params, 88 scoped_ptr<GetSelectedFileInfoParams> params,
86 drive::FileError error, 89 drive::FileError error,
87 const base::FilePath& local_file_path, 90 const base::FilePath& local_file_path,
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 file_system_context->CrackURL(url)); 153 file_system_context->CrackURL(url));
151 base::FilePath path; 154 base::FilePath path;
152 if (!chromeos::FileSystemBackend::CanHandleURL(filesystem_url)) 155 if (!chromeos::FileSystemBackend::CanHandleURL(filesystem_url))
153 return base::FilePath(); 156 return base::FilePath();
154 return filesystem_url.path(); 157 return filesystem_url.path();
155 } 158 }
156 159
157 void GetSelectedFileInfo(content::RenderViewHost* render_view_host, 160 void GetSelectedFileInfo(content::RenderViewHost* render_view_host,
158 Profile* profile, 161 Profile* profile,
159 const std::vector<GURL>& file_urls, 162 const std::vector<GURL>& file_urls,
160 bool for_opening, 163 GetSelectedFileInfoLocalPathOption local_path_option,
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->local_path_option = local_path_option;
167 params->callback = callback; 170 params->callback = callback;
168 171
169 for (size_t i = 0; i < file_urls.size(); ++i) { 172 for (size_t i = 0; i < file_urls.size(); ++i) {
170 const GURL& file_url = file_urls[i]; 173 const GURL& file_url = file_urls[i];
171 const base::FilePath path = GetLocalPathFromURL( 174 const base::FilePath path = GetLocalPathFromURL(
172 render_view_host, profile, file_url); 175 render_view_host, profile, file_url);
173 if (!path.empty()) { 176 if (!path.empty()) {
174 DVLOG(1) << "Selected: file path: " << path.value(); 177 DVLOG(1) << "Selected: file path: " << path.value();
175 params->file_paths.push_back(path); 178 params->file_paths.push_back(path);
176 } 179 }
177 } 180 }
178 181
179 BrowserThread::PostTask( 182 BrowserThread::PostTask(
180 BrowserThread::UI, FROM_HERE, 183 BrowserThread::UI, FROM_HERE,
181 base::Bind(&GetSelectedFileInfoInternal, 184 base::Bind(&GetSelectedFileInfoInternal,
182 profile, 185 profile,
183 base::Passed(&params))); 186 base::Passed(&params)));
184 } 187 }
185 188
186 } // namespace util 189 } // namespace util
187 } // namespace file_manager 190 } // namespace file_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698