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 30 matching lines...) Expand all Loading... |
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 drive::DriveIntegrationService* integration_service = |
| 52 drive::DriveIntegrationServiceFactory::GetForProfile(profile); |
51 | 53 |
52 for (size_t i = params->selected_files.size(); | 54 for (size_t i = params->selected_files.size(); |
53 i < params->file_paths.size(); ++i) { | 55 i < params->file_paths.size(); ++i) { |
54 const base::FilePath& file_path = params->file_paths[i]; | 56 const base::FilePath& file_path = params->file_paths[i]; |
55 // When the caller of the select file dialog wants local file paths, | 57 |
56 // we should retrieve Drive files onto the local cache. | 58 if (!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( | 59 params->selected_files.push_back( |
60 ui::SelectedFileInfo(file_path, base::FilePath())); | 60 ui::SelectedFileInfo(file_path, base::FilePath())); |
61 } else { | 61 } else { |
62 drive::DriveIntegrationService* integration_service = | |
63 drive::DriveIntegrationServiceFactory::GetForProfile(profile); | |
64 // |integration_service| is NULL if Drive is disabled. | 62 // |integration_service| is NULL if Drive is disabled. |
65 if (!integration_service) { | 63 if (!integration_service) { |
66 ContinueGetSelectedFileInfo(profile, | 64 ContinueGetSelectedFileInfo(profile, |
67 params.Pass(), | 65 params.Pass(), |
68 drive::FILE_ERROR_FAILED, | 66 drive::FILE_ERROR_FAILED, |
69 base::FilePath(), | 67 base::FilePath(), |
70 scoped_ptr<drive::ResourceEntry>()); | 68 scoped_ptr<drive::ResourceEntry>()); |
71 return; | 69 return; |
72 } | 70 } |
73 // TODO(kinaba): crbug.com/140425 support FOR_SAVING | 71 // When the caller of the select file dialog wants local file paths, |
74 DCHECK(params->local_path_option == NEED_LOCAL_PATH_FOR_OPENING); | 72 // we should retrieve Drive files onto the local cache. |
75 integration_service->file_system()->GetFileByPath( | 73 switch (params->local_path_option) { |
76 drive::util::ExtractDrivePath(file_path), | 74 case NO_LOCAL_PATH_RESOLUTION: |
77 base::Bind(&ContinueGetSelectedFileInfo, | 75 params->selected_files.push_back( |
78 profile, | 76 ui::SelectedFileInfo(file_path, base::FilePath())); |
79 base::Passed(¶ms))); | 77 break; |
80 return; | 78 case NEED_LOCAL_PATH_FOR_OPENING: |
81 } | 79 integration_service->file_system()->GetFileByPath( |
| 80 drive::util::ExtractDrivePath(file_path), |
| 81 base::Bind(&ContinueGetSelectedFileInfo, |
| 82 profile, |
| 83 base::Passed(¶ms))); |
| 84 return; // Remaining work is done in ContinueGetSelectedFileInfo. |
| 85 case NEED_LOCAL_PATH_FOR_SAVING: |
| 86 integration_service->file_system()->GetFileByPathForSaving( |
| 87 drive::util::ExtractDrivePath(file_path), |
| 88 base::Bind(&ContinueGetSelectedFileInfo, |
| 89 profile, |
| 90 base::Passed(¶ms))); |
| 91 return; // Remaining work is done in ContinueGetSelectedFileInfo. |
| 92 } |
| 93 } |
82 } | 94 } |
83 params->callback.Run(params->selected_files); | 95 params->callback.Run(params->selected_files); |
84 } | 96 } |
85 | 97 |
86 // Part of GetSelectedFileInfo(). | 98 // Part of GetSelectedFileInfo(). |
87 void ContinueGetSelectedFileInfo(Profile* profile, | 99 void ContinueGetSelectedFileInfo(Profile* profile, |
88 scoped_ptr<GetSelectedFileInfoParams> params, | 100 scoped_ptr<GetSelectedFileInfoParams> params, |
89 drive::FileError error, | 101 drive::FileError error, |
90 const base::FilePath& local_file_path, | 102 const base::FilePath& local_file_path, |
91 scoped_ptr<drive::ResourceEntry> entry) { | 103 scoped_ptr<drive::ResourceEntry> entry) { |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 | 193 |
182 BrowserThread::PostTask( | 194 BrowserThread::PostTask( |
183 BrowserThread::UI, FROM_HERE, | 195 BrowserThread::UI, FROM_HERE, |
184 base::Bind(&GetSelectedFileInfoInternal, | 196 base::Bind(&GetSelectedFileInfoInternal, |
185 profile, | 197 profile, |
186 base::Passed(¶ms))); | 198 base::Passed(¶ms))); |
187 } | 199 } |
188 | 200 |
189 } // namespace util | 201 } // namespace util |
190 } // namespace file_manager | 202 } // namespace file_manager |
OLD | NEW |