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_drive.h" | 5 #include "chrome/browser/chromeos/extensions/file_manager/private_api_drive.h" |
6 | 6 |
7 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
9 #include "chrome/browser/chromeos/drive/drive_app_registry.h" | 9 #include "chrome/browser/chromeos/drive/drive_app_registry.h" |
10 #include "chrome/browser/chromeos/drive/drive_integration_service.h" | 10 #include "chrome/browser/chromeos/drive/drive_integration_service.h" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
58 | 58 |
59 property_dict->SetString("thumbnailUrl", file_specific_info.thumbnail_url()); | 59 property_dict->SetString("thumbnailUrl", file_specific_info.thumbnail_url()); |
60 property_dict->SetBoolean("isHosted", | 60 property_dict->SetBoolean("isHosted", |
61 file_specific_info.is_hosted_document()); | 61 file_specific_info.is_hosted_document()); |
62 property_dict->SetString("contentMimeType", | 62 property_dict->SetString("contentMimeType", |
63 file_specific_info.content_mime_type()); | 63 file_specific_info.content_mime_type()); |
64 } | 64 } |
65 | 65 |
66 } // namespace | 66 } // namespace |
67 | 67 |
68 GetDriveEntryPropertiesFunction::GetDriveEntryPropertiesFunction() { | 68 FileBrowserPrivateGetDriveEntryPropertiesFunction:: |
69 FileBrowserPrivateGetDriveEntryPropertiesFunction() { | |
69 } | 70 } |
70 | 71 |
71 GetDriveEntryPropertiesFunction::~GetDriveEntryPropertiesFunction() { | 72 FileBrowserPrivateGetDriveEntryPropertiesFunction:: |
73 ~FileBrowserPrivateGetDriveEntryPropertiesFunction() { | |
72 } | 74 } |
73 | 75 |
74 bool GetDriveEntryPropertiesFunction::RunImpl() { | 76 bool FileBrowserPrivateGetDriveEntryPropertiesFunction::RunImpl() { |
75 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 77 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
76 | 78 |
77 std::string file_url_str; | 79 std::string file_url_str; |
78 if (args_->GetSize() != 1 || !args_->GetString(0, &file_url_str)) | 80 if (args_->GetSize() != 1 || !args_->GetString(0, &file_url_str)) |
79 return false; | 81 return false; |
80 | 82 |
81 GURL file_url = GURL(file_url_str); | 83 GURL file_url = GURL(file_url_str); |
82 file_path_ = drive::util::ExtractDrivePath( | 84 file_path_ = drive::util::ExtractDrivePath( |
83 file_manager::util::GetLocalPathFromURL( | 85 file_manager::util::GetLocalPathFromURL( |
84 render_view_host(), profile(), file_url)); | 86 render_view_host(), profile(), file_url)); |
85 | 87 |
86 properties_.reset(new base::DictionaryValue); | 88 properties_.reset(new base::DictionaryValue); |
87 properties_->SetString("fileUrl", file_url.spec()); | 89 properties_->SetString("fileUrl", file_url.spec()); |
88 | 90 |
89 // Start getting the file info. | 91 // Start getting the file info. |
90 drive::DriveIntegrationService* integration_service = | 92 drive::DriveIntegrationService* integration_service = |
91 drive::DriveIntegrationServiceFactory::GetForProfile(profile_); | 93 drive::DriveIntegrationServiceFactory::GetForProfile(profile_); |
92 // |integration_service| is NULL if Drive is disabled. | 94 // |integration_service| is NULL if Drive is disabled. |
93 if (!integration_service) { | 95 if (!integration_service) { |
94 CompleteGetFileProperties(drive::FILE_ERROR_FAILED); | 96 CompleteGetFileProperties(drive::FILE_ERROR_FAILED); |
95 return true; | 97 return true; |
96 } | 98 } |
97 | 99 |
98 integration_service->file_system()->GetResourceEntryByPath( | 100 integration_service->file_system()->GetResourceEntryByPath( |
99 file_path_, | 101 file_path_, |
100 base::Bind(&GetDriveEntryPropertiesFunction::OnGetFileInfo, this)); | 102 base::Bind(&FileBrowserPrivateGetDriveEntryPropertiesFunction:: |
103 OnGetFileInfo, this)); | |
101 return true; | 104 return true; |
102 } | 105 } |
103 | 106 |
104 void GetDriveEntryPropertiesFunction::OnGetFileInfo( | 107 void FileBrowserPrivateGetDriveEntryPropertiesFunction::OnGetFileInfo( |
105 drive::FileError error, | 108 drive::FileError error, |
106 scoped_ptr<drive::ResourceEntry> entry) { | 109 scoped_ptr<drive::ResourceEntry> entry) { |
107 DCHECK(properties_); | 110 DCHECK(properties_); |
108 | 111 |
109 if (error != drive::FILE_ERROR_OK) { | 112 if (error != drive::FILE_ERROR_OK) { |
110 CompleteGetFileProperties(error); | 113 CompleteGetFileProperties(error); |
111 return; | 114 return; |
112 } | 115 } |
113 DCHECK(entry); | 116 DCHECK(entry); |
114 | 117 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
153 const GURL doc_icon = | 156 const GURL doc_icon = |
154 drive::util::FindPreferredIcon(app_info->document_icons, | 157 drive::util::FindPreferredIcon(app_info->document_icons, |
155 drive::util::kPreferredIconSize); | 158 drive::util::kPreferredIconSize); |
156 properties_->SetString("customIconUrl", doc_icon.spec()); | 159 properties_->SetString("customIconUrl", doc_icon.spec()); |
157 } | 160 } |
158 } | 161 } |
159 } | 162 } |
160 | 163 |
161 integration_service->file_system()->GetCacheEntryByPath( | 164 integration_service->file_system()->GetCacheEntryByPath( |
162 file_path_, | 165 file_path_, |
163 base::Bind(&GetDriveEntryPropertiesFunction::CacheStateReceived, this)); | 166 base::Bind(&FileBrowserPrivateGetDriveEntryPropertiesFunction:: |
167 CacheStateReceived, this)); | |
164 } | 168 } |
165 | 169 |
166 void GetDriveEntryPropertiesFunction::CacheStateReceived( | 170 void FileBrowserPrivateGetDriveEntryPropertiesFunction::CacheStateReceived( |
167 bool /* success */, | 171 bool /* success */, |
168 const drive::FileCacheEntry& cache_entry) { | 172 const drive::FileCacheEntry& cache_entry) { |
169 // In case of an error (i.e. success is false), cache_entry.is_*() all | 173 // In case of an error (i.e. success is false), cache_entry.is_*() all |
170 // returns false. | 174 // returns false. |
171 properties_->SetBoolean("isPinned", cache_entry.is_pinned()); | 175 properties_->SetBoolean("isPinned", cache_entry.is_pinned()); |
172 properties_->SetBoolean("isPresent", cache_entry.is_present()); | 176 properties_->SetBoolean("isPresent", cache_entry.is_present()); |
173 properties_->SetBoolean("isDirty", cache_entry.is_dirty()); | 177 properties_->SetBoolean("isDirty", cache_entry.is_dirty()); |
174 | 178 |
175 CompleteGetFileProperties(drive::FILE_ERROR_OK); | 179 CompleteGetFileProperties(drive::FILE_ERROR_OK); |
176 } | 180 } |
177 | 181 |
178 void GetDriveEntryPropertiesFunction::CompleteGetFileProperties( | 182 void FileBrowserPrivateGetDriveEntryPropertiesFunction:: |
183 CompleteGetFileProperties( | |
179 drive::FileError error) { | 184 drive::FileError error) { |
180 if (error != drive::FILE_ERROR_OK) | 185 if (error != drive::FILE_ERROR_OK) |
181 properties_->SetInteger("errorCode", error); | 186 properties_->SetInteger("errorCode", error); |
182 SetResult(properties_.release()); | 187 SetResult(properties_.release()); |
183 SendResponse(true); | 188 SendResponse(true); |
184 } | 189 } |
185 | 190 |
186 PinDriveFileFunction::PinDriveFileFunction() { | 191 FileBrowserPrivatePinDriveFileFunction:: |
192 FileBrowserPrivatePinDriveFileFunction() { | |
187 } | 193 } |
188 | 194 |
189 PinDriveFileFunction::~PinDriveFileFunction() { | 195 FileBrowserPrivatePinDriveFileFunction::~ |
196 FileBrowserPrivatePinDriveFileFunction() { | |
190 } | 197 } |
191 | 198 |
192 bool PinDriveFileFunction::RunImpl() { | 199 bool FileBrowserPrivatePinDriveFileFunction::RunImpl() { |
193 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 200 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
194 std::string url; | 201 std::string url; |
195 bool set_pin = false; | 202 bool set_pin = false; |
196 if (args_->GetSize() != 2 || | 203 if (args_->GetSize() != 2 || |
197 !args_->GetString(0, &url) || | 204 !args_->GetString(0, &url) || |
198 !args_->GetBoolean(1, &set_pin)) | 205 !args_->GetBoolean(1, &set_pin)) |
199 return false; | 206 return false; |
200 | 207 |
201 drive::DriveIntegrationService* integration_service = | 208 drive::DriveIntegrationService* integration_service = |
202 drive::DriveIntegrationServiceFactory::GetForProfile(profile_); | 209 drive::DriveIntegrationServiceFactory::GetForProfile(profile_); |
203 drive::FileSystemInterface* file_system = | 210 drive::FileSystemInterface* file_system = |
204 integration_service ? integration_service->file_system() : NULL; | 211 integration_service ? integration_service->file_system() : NULL; |
205 if (!file_system) // |file_system| is NULL if Drive is disabled. | 212 if (!file_system) // |file_system| is NULL if Drive is disabled. |
206 return false; | 213 return false; |
207 | 214 |
208 base::FilePath drive_path = | 215 base::FilePath drive_path = |
209 drive::util::ExtractDrivePath(file_manager::util::GetLocalPathFromURL( | 216 drive::util::ExtractDrivePath(file_manager::util::GetLocalPathFromURL( |
210 render_view_host(), profile(), GURL(url))); | 217 render_view_host(), profile(), GURL(url))); |
211 if (set_pin) { | 218 if (set_pin) { |
212 file_system->Pin(drive_path, | 219 file_system->Pin(drive_path, |
213 base::Bind(&PinDriveFileFunction::OnPinStateSet, this)); | 220 base::Bind(&FileBrowserPrivatePinDriveFileFunction:: |
221 OnPinStateSet, this)); | |
214 } else { | 222 } else { |
215 file_system->Unpin(drive_path, | 223 file_system->Unpin(drive_path, |
216 base::Bind(&PinDriveFileFunction::OnPinStateSet, this)); | 224 base::Bind(&FileBrowserPrivatePinDriveFileFunction:: |
225 OnPinStateSet, this)); | |
217 } | 226 } |
218 return true; | 227 return true; |
219 } | 228 } |
220 | 229 |
221 void PinDriveFileFunction::OnPinStateSet(drive::FileError error) { | 230 void FileBrowserPrivatePinDriveFileFunction:: |
231 OnPinStateSet(drive::FileError error) { | |
222 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 232 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
223 | 233 |
224 if (error == drive::FILE_ERROR_OK) { | 234 if (error == drive::FILE_ERROR_OK) { |
225 SendResponse(true); | 235 SendResponse(true); |
226 } else { | 236 } else { |
227 error_ = drive::FileErrorToString(error); | 237 error_ = drive::FileErrorToString(error); |
228 SendResponse(false); | 238 SendResponse(false); |
229 } | 239 } |
230 } | 240 } |
231 | 241 |
232 GetDriveFilesFunction::GetDriveFilesFunction() | 242 FileBrowserPrivateGetDriveFilesFunction:: |
243 FileBrowserPrivateGetDriveFilesFunction() | |
233 : local_paths_(NULL) { | 244 : local_paths_(NULL) { |
234 } | 245 } |
235 | 246 |
236 GetDriveFilesFunction::~GetDriveFilesFunction() { | 247 FileBrowserPrivateGetDriveFilesFunction:: |
248 ~FileBrowserPrivateGetDriveFilesFunction() { | |
237 } | 249 } |
238 | 250 |
239 bool GetDriveFilesFunction::RunImpl() { | 251 bool FileBrowserPrivateGetDriveFilesFunction::RunImpl() { |
240 ListValue* file_urls_as_strings = NULL; | 252 ListValue* file_urls_as_strings = NULL; |
241 if (!args_->GetList(0, &file_urls_as_strings)) | 253 if (!args_->GetList(0, &file_urls_as_strings)) |
242 return false; | 254 return false; |
243 | 255 |
244 // Convert the list of strings to a list of GURLs. | 256 // Convert the list of strings to a list of GURLs. |
245 for (size_t i = 0; i < file_urls_as_strings->GetSize(); ++i) { | 257 for (size_t i = 0; i < file_urls_as_strings->GetSize(); ++i) { |
246 std::string file_url_as_string; | 258 std::string file_url_as_string; |
247 if (!file_urls_as_strings->GetString(i, &file_url_as_string)) | 259 if (!file_urls_as_strings->GetString(i, &file_url_as_string)) |
248 return false; | 260 return false; |
249 const base::FilePath path = file_manager::util::GetLocalPathFromURL( | 261 const base::FilePath path = file_manager::util::GetLocalPathFromURL( |
250 render_view_host(), profile(), GURL(file_url_as_string)); | 262 render_view_host(), profile(), GURL(file_url_as_string)); |
251 DCHECK(drive::util::IsUnderDriveMountPoint(path)); | 263 DCHECK(drive::util::IsUnderDriveMountPoint(path)); |
252 base::FilePath drive_path = drive::util::ExtractDrivePath(path); | 264 base::FilePath drive_path = drive::util::ExtractDrivePath(path); |
253 remaining_drive_paths_.push(drive_path); | 265 remaining_drive_paths_.push(drive_path); |
254 } | 266 } |
255 | 267 |
256 local_paths_ = new ListValue; | 268 local_paths_ = new ListValue; |
257 GetFileOrSendResponse(); | 269 GetFileOrSendResponse(); |
258 return true; | 270 return true; |
259 } | 271 } |
260 | 272 |
261 void GetDriveFilesFunction::GetFileOrSendResponse() { | 273 void FileBrowserPrivateGetDriveFilesFunction::GetFileOrSendResponse() { |
262 // Send the response if all files are obtained. | 274 // Send the response if all files are obtained. |
263 if (remaining_drive_paths_.empty()) { | 275 if (remaining_drive_paths_.empty()) { |
264 SetResult(local_paths_); | 276 SetResult(local_paths_); |
265 SendResponse(true); | 277 SendResponse(true); |
266 return; | 278 return; |
267 } | 279 } |
268 | 280 |
269 // Get the file on the top of the queue. | 281 // Get the file on the top of the queue. |
270 base::FilePath drive_path = remaining_drive_paths_.front(); | 282 base::FilePath drive_path = remaining_drive_paths_.front(); |
271 | 283 |
272 drive::DriveIntegrationService* integration_service = | 284 drive::DriveIntegrationService* integration_service = |
273 drive::DriveIntegrationServiceFactory::GetForProfile(profile_); | 285 drive::DriveIntegrationServiceFactory::GetForProfile(profile_); |
274 // |integration_service| is NULL if Drive is disabled. | 286 // |integration_service| is NULL if Drive is disabled. |
275 if (!integration_service) { | 287 if (!integration_service) { |
276 OnFileReady(drive::FILE_ERROR_FAILED, drive_path, | 288 OnFileReady(drive::FILE_ERROR_FAILED, drive_path, |
277 scoped_ptr<drive::ResourceEntry>()); | 289 scoped_ptr<drive::ResourceEntry>()); |
278 return; | 290 return; |
279 } | 291 } |
280 | 292 |
281 integration_service->file_system()->GetFileByPath( | 293 integration_service->file_system()->GetFileByPath( |
282 drive_path, | 294 drive_path, |
283 base::Bind(&GetDriveFilesFunction::OnFileReady, this)); | 295 base::Bind(&FileBrowserPrivateGetDriveFilesFunction::OnFileReady, this)); |
284 } | 296 } |
285 | 297 |
286 | 298 |
287 void GetDriveFilesFunction::OnFileReady( | 299 void FileBrowserPrivateGetDriveFilesFunction::OnFileReady( |
288 drive::FileError error, | 300 drive::FileError error, |
289 const base::FilePath& local_path, | 301 const base::FilePath& local_path, |
290 scoped_ptr<drive::ResourceEntry> entry) { | 302 scoped_ptr<drive::ResourceEntry> entry) { |
291 base::FilePath drive_path = remaining_drive_paths_.front(); | 303 base::FilePath drive_path = remaining_drive_paths_.front(); |
292 | 304 |
293 if (error == drive::FILE_ERROR_OK) { | 305 if (error == drive::FILE_ERROR_OK) { |
294 local_paths_->Append(new base::StringValue(local_path.value())); | 306 local_paths_->Append(new base::StringValue(local_path.value())); |
295 DVLOG(1) << "Got " << drive_path.value() << " as " << local_path.value(); | 307 DVLOG(1) << "Got " << drive_path.value() << " as " << local_path.value(); |
296 | 308 |
297 // TODO(benchan): If the file is a hosted document, a temporary JSON file | 309 // TODO(benchan): If the file is a hosted document, a temporary JSON file |
298 // is created to represent the document. The JSON file is not cached and | 310 // is created to represent the document. The JSON file is not cached and |
299 // should be deleted after use. We need to somehow communicate with | 311 // should be deleted after use. We need to somehow communicate with |
300 // file_manager.js to manage the lifetime of the temporary file. | 312 // file_manager.js to manage the lifetime of the temporary file. |
301 // See crosbug.com/28058. | 313 // See crosbug.com/28058. |
302 } else { | 314 } else { |
303 local_paths_->Append(new base::StringValue("")); | 315 local_paths_->Append(new base::StringValue("")); |
304 DVLOG(1) << "Failed to get " << drive_path.value() | 316 DVLOG(1) << "Failed to get " << drive_path.value() |
305 << " with error code: " << error; | 317 << " with error code: " << error; |
306 } | 318 } |
307 | 319 |
308 remaining_drive_paths_.pop(); | 320 remaining_drive_paths_.pop(); |
309 | 321 |
310 // Start getting the next file. | 322 // Start getting the next file. |
311 GetFileOrSendResponse(); | 323 GetFileOrSendResponse(); |
312 } | 324 } |
313 | 325 |
314 CancelFileTransfersFunction::CancelFileTransfersFunction() { | 326 FileBrowserPrivateCancelFileTransfersFunction:: |
327 FileBrowserPrivateCancelFileTransfersFunction() { | |
315 } | 328 } |
316 | 329 |
317 CancelFileTransfersFunction::~CancelFileTransfersFunction() { | 330 FileBrowserPrivateCancelFileTransfersFunction:: |
331 ~FileBrowserPrivateCancelFileTransfersFunction() { | |
318 } | 332 } |
319 | 333 |
320 bool CancelFileTransfersFunction::RunImpl() { | 334 bool FileBrowserPrivateCancelFileTransfersFunction::RunImpl() { |
321 ListValue* url_list = NULL; | 335 ListValue* url_list = NULL; |
322 if (!args_->GetList(0, &url_list)) | 336 if (!args_->GetList(0, &url_list)) |
323 return false; | 337 return false; |
324 | 338 |
325 drive::DriveIntegrationService* integration_service = | 339 drive::DriveIntegrationService* integration_service = |
326 drive::DriveIntegrationServiceFactory::GetForProfile(profile_); | 340 drive::DriveIntegrationServiceFactory::GetForProfile(profile_); |
327 // |integration_service| is NULL if Drive is disabled. | 341 // |integration_service| is NULL if Drive is disabled. |
328 if (!integration_service) | 342 if (!integration_service) |
329 return false; | 343 return false; |
330 | 344 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
365 // TODO(kinaba): simplify cancelFileTransfer() to take single URL each time, | 379 // TODO(kinaba): simplify cancelFileTransfer() to take single URL each time, |
366 // and eliminate this field; it is just returning a copy of the argument. | 380 // and eliminate this field; it is just returning a copy of the argument. |
367 result->SetString("fileUrl", url_as_string); | 381 result->SetString("fileUrl", url_as_string); |
368 responses->Append(result.release()); | 382 responses->Append(result.release()); |
369 } | 383 } |
370 SetResult(responses.release()); | 384 SetResult(responses.release()); |
371 SendResponse(true); | 385 SendResponse(true); |
372 return true; | 386 return true; |
373 } | 387 } |
374 | 388 |
375 SearchDriveFunction::SearchDriveFunction() { | 389 FileBrowserPrivateSearchDriveFunction:: |
390 FileBrowserPrivateSearchDriveFunction() { | |
376 } | 391 } |
377 | 392 |
378 SearchDriveFunction::~SearchDriveFunction() { | 393 FileBrowserPrivateSearchDriveFunction:: |
394 ~FileBrowserPrivateSearchDriveFunction() { | |
379 } | 395 } |
380 | 396 |
381 bool SearchDriveFunction::RunImpl() { | 397 bool FileBrowserPrivateSearchDriveFunction::RunImpl() { |
382 DictionaryValue* search_params; | 398 DictionaryValue* search_params; |
383 if (!args_->GetDictionary(0, &search_params)) | 399 if (!args_->GetDictionary(0, &search_params)) |
384 return false; | 400 return false; |
385 | 401 |
386 std::string query; | 402 std::string query; |
387 if (!search_params->GetString("query", &query)) | 403 if (!search_params->GetString("query", &query)) |
388 return false; | 404 return false; |
389 | 405 |
390 std::string next_feed; | 406 std::string next_feed; |
391 if (!search_params->GetString("nextFeed", &next_feed)) | 407 if (!search_params->GetString("nextFeed", &next_feed)) |
392 return false; | 408 return false; |
393 | 409 |
394 drive::DriveIntegrationService* integration_service = | 410 drive::DriveIntegrationService* integration_service = |
395 drive::DriveIntegrationServiceFactory::GetForProfile(profile_); | 411 drive::DriveIntegrationServiceFactory::GetForProfile(profile_); |
396 // |integration_service| is NULL if Drive is disabled. | 412 // |integration_service| is NULL if Drive is disabled. |
397 if (!integration_service || !integration_service->file_system()) | 413 if (!integration_service || !integration_service->file_system()) |
398 return false; | 414 return false; |
399 | 415 |
400 integration_service->file_system()->Search( | 416 integration_service->file_system()->Search( |
401 query, next_feed, | 417 query, next_feed, |
402 base::Bind(&SearchDriveFunction::OnSearch, this)); | 418 base::Bind(&FileBrowserPrivateSearchDriveFunction::OnSearch, this)); |
403 return true; | 419 return true; |
404 } | 420 } |
405 | 421 |
406 void SearchDriveFunction::OnSearch( | 422 void FileBrowserPrivateSearchDriveFunction::OnSearch( |
407 drive::FileError error, | 423 drive::FileError error, |
408 const std::string& next_feed, | 424 const std::string& next_feed, |
409 scoped_ptr<std::vector<drive::SearchResultInfo> > results) { | 425 scoped_ptr<std::vector<drive::SearchResultInfo> > results) { |
410 if (error != drive::FILE_ERROR_OK) { | 426 if (error != drive::FILE_ERROR_OK) { |
411 SendResponse(false); | 427 SendResponse(false); |
412 return; | 428 return; |
413 } | 429 } |
414 | 430 |
415 DCHECK(results.get()); | 431 DCHECK(results.get()); |
416 | 432 |
(...skipping 17 matching lines...) Expand all Loading... | |
434 } | 450 } |
435 | 451 |
436 base::DictionaryValue* result = new DictionaryValue(); | 452 base::DictionaryValue* result = new DictionaryValue(); |
437 result->Set("entries", entries); | 453 result->Set("entries", entries); |
438 result->SetString("nextFeed", next_feed); | 454 result->SetString("nextFeed", next_feed); |
439 | 455 |
440 SetResult(result); | 456 SetResult(result); |
441 SendResponse(true); | 457 SendResponse(true); |
442 } | 458 } |
443 | 459 |
444 SearchDriveMetadataFunction::SearchDriveMetadataFunction() { | 460 FileBrowserPrivateSearchDriveMetadataFunction:: |
461 FileBrowserPrivateSearchDriveMetadataFunction() { | |
445 } | 462 } |
446 | 463 |
447 SearchDriveMetadataFunction::~SearchDriveMetadataFunction() { | 464 FileBrowserPrivateSearchDriveMetadataFunction:: |
465 ~FileBrowserPrivateSearchDriveMetadataFunction() { | |
448 } | 466 } |
449 | 467 |
450 bool SearchDriveMetadataFunction::RunImpl() { | 468 bool FileBrowserPrivateSearchDriveMetadataFunction::RunImpl() { |
451 DictionaryValue* search_params; | 469 DictionaryValue* search_params; |
452 if (!args_->GetDictionary(0, &search_params)) | 470 if (!args_->GetDictionary(0, &search_params)) |
453 return false; | 471 return false; |
454 | 472 |
455 std::string query; | 473 std::string query; |
456 if (!search_params->GetString("query", &query)) | 474 if (!search_params->GetString("query", &query)) |
457 return false; | 475 return false; |
458 | 476 |
459 std::string types; | 477 std::string types; |
460 if (!search_params->GetString("types", &types)) | 478 if (!search_params->GetString("types", &types)) |
(...skipping 25 matching lines...) Expand all Loading... | |
486 options = drive::SEARCH_METADATA_SHARED_WITH_ME; | 504 options = drive::SEARCH_METADATA_SHARED_WITH_ME; |
487 else if (types == "OFFLINE") | 505 else if (types == "OFFLINE") |
488 options = drive::SEARCH_METADATA_OFFLINE; | 506 options = drive::SEARCH_METADATA_OFFLINE; |
489 else | 507 else |
490 DCHECK_EQ("ALL", types); | 508 DCHECK_EQ("ALL", types); |
491 | 509 |
492 integration_service->file_system()->SearchMetadata( | 510 integration_service->file_system()->SearchMetadata( |
493 query, | 511 query, |
494 options, | 512 options, |
495 max_results, | 513 max_results, |
496 base::Bind(&SearchDriveMetadataFunction::OnSearchMetadata, this)); | 514 base::Bind(&FileBrowserPrivateSearchDriveMetadataFunction:: |
515 OnSearchMetadata, this)); | |
497 return true; | 516 return true; |
498 } | 517 } |
499 | 518 |
500 void SearchDriveMetadataFunction::OnSearchMetadata( | 519 void FileBrowserPrivateSearchDriveMetadataFunction::OnSearchMetadata( |
501 drive::FileError error, | 520 drive::FileError error, |
502 scoped_ptr<drive::MetadataSearchResultVector> results) { | 521 scoped_ptr<drive::MetadataSearchResultVector> results) { |
503 if (error != drive::FILE_ERROR_OK) { | 522 if (error != drive::FILE_ERROR_OK) { |
504 SendResponse(false); | 523 SendResponse(false); |
505 return; | 524 return; |
506 } | 525 } |
507 | 526 |
508 DCHECK(results.get()); | 527 DCHECK(results.get()); |
509 | 528 |
510 base::ListValue* results_list = new ListValue(); | 529 base::ListValue* results_list = new ListValue(); |
(...skipping 22 matching lines...) Expand all Loading... | |
533 result_dict->Set("entry", entry); | 552 result_dict->Set("entry", entry); |
534 result_dict->SetString("highlightedBaseName", | 553 result_dict->SetString("highlightedBaseName", |
535 results->at(i).highlighted_base_name); | 554 results->at(i).highlighted_base_name); |
536 results_list->Append(result_dict); | 555 results_list->Append(result_dict); |
537 } | 556 } |
538 | 557 |
539 SetResult(results_list); | 558 SetResult(results_list); |
540 SendResponse(true); | 559 SendResponse(true); |
541 } | 560 } |
542 | 561 |
543 ClearDriveCacheFunction::ClearDriveCacheFunction() { | 562 FileBrowserPrivateClearDriveCacheFunction:: |
563 FileBrowserPrivateClearDriveCacheFunction() { | |
544 } | 564 } |
545 | 565 |
546 ClearDriveCacheFunction::~ClearDriveCacheFunction() { | 566 FileBrowserPrivateClearDriveCacheFunction:: |
567 ~FileBrowserPrivateClearDriveCacheFunction() { | |
547 } | 568 } |
548 | 569 |
549 bool ClearDriveCacheFunction::RunImpl() { | 570 bool FileBrowserPrivateClearDriveCacheFunction::RunImpl() { |
550 drive::DriveIntegrationService* integration_service = | 571 drive::DriveIntegrationService* integration_service = |
551 drive::DriveIntegrationServiceFactory::GetForProfile(profile_); | 572 drive::DriveIntegrationServiceFactory::GetForProfile(profile_); |
552 // |integration_service| is NULL if Drive is disabled. | 573 // |integration_service| is NULL if Drive is disabled. |
553 if (!integration_service || !integration_service->file_system()) | 574 if (!integration_service || !integration_service->file_system()) |
554 return false; | 575 return false; |
555 | 576 |
556 // TODO(yoshiki): Receive a callback from JS-side and pass it to | 577 // TODO(yoshiki): Receive a callback from JS-side and pass it to |
557 // ClearCacheAndRemountFileSystem(). http://crbug.com/140511 | 578 // ClearCacheAndRemountFileSystem(). http://crbug.com/140511 |
558 integration_service->ClearCacheAndRemountFileSystem( | 579 integration_service->ClearCacheAndRemountFileSystem( |
559 base::Bind(&DoNothingWithBool)); | 580 base::Bind(&DoNothingWithBool)); |
560 | 581 |
561 SendResponse(true); | 582 SendResponse(true); |
562 return true; | 583 return true; |
563 } | 584 } |
564 | 585 |
565 GetDriveConnectionStateFunction::GetDriveConnectionStateFunction() { | 586 FileBrowserPrivateGetDriveConnectionStateFunction:: |
587 FileBrowserPrivateGetDriveConnectionStateFunction() { | |
566 } | 588 } |
567 | 589 |
568 GetDriveConnectionStateFunction::~GetDriveConnectionStateFunction() { | 590 FileBrowserPrivateGetDriveConnectionStateFunction:: |
591 ~FileBrowserPrivateGetDriveConnectionStateFunction() { | |
569 } | 592 } |
570 | 593 |
571 bool GetDriveConnectionStateFunction::RunImpl() { | 594 bool FileBrowserPrivateGetDriveConnectionStateFunction::RunImpl() { |
572 scoped_ptr<DictionaryValue> value(new DictionaryValue()); | 595 scoped_ptr<DictionaryValue> value(new DictionaryValue()); |
573 scoped_ptr<ListValue> reasons(new ListValue()); | 596 scoped_ptr<ListValue> reasons(new ListValue()); |
574 | 597 |
575 std::string type_string; | 598 std::string type_string; |
576 drive::DriveIntegrationService* integration_service = | 599 drive::DriveIntegrationService* integration_service = |
577 drive::DriveIntegrationServiceFactory::GetForProfile(profile_); | 600 drive::DriveIntegrationServiceFactory::GetForProfile(profile_); |
578 | 601 |
579 bool ready = integration_service && | 602 bool ready = integration_service && |
580 integration_service->drive_service()->CanSendRequest(); | 603 integration_service->drive_service()->CanSendRequest(); |
581 bool is_connection_cellular = | 604 bool is_connection_cellular = |
(...skipping 17 matching lines...) Expand all Loading... | |
599 } | 622 } |
600 | 623 |
601 value->SetString("type", type_string); | 624 value->SetString("type", type_string); |
602 value->Set("reasons", reasons.release()); | 625 value->Set("reasons", reasons.release()); |
603 SetResult(value.release()); | 626 SetResult(value.release()); |
604 | 627 |
605 drive::util::Log(logging::LOG_INFO, "%s succeeded.", name().c_str()); | 628 drive::util::Log(logging::LOG_INFO, "%s succeeded.", name().c_str()); |
606 return true; | 629 return true; |
607 } | 630 } |
608 | 631 |
609 RequestAccessTokenFunction::RequestAccessTokenFunction() { | 632 FileBrowserPrivateRequestAccessTokenFunction:: |
633 FileBrowserPrivateRequestAccessTokenFunction() { | |
610 } | 634 } |
611 | 635 |
612 RequestAccessTokenFunction::~RequestAccessTokenFunction() { | 636 FileBrowserPrivateRequestAccessTokenFunction:: |
637 ~FileBrowserPrivateRequestAccessTokenFunction() { | |
613 } | 638 } |
614 | 639 |
615 bool RequestAccessTokenFunction::RunImpl() { | 640 bool FileBrowserPrivateRequestAccessTokenFunction::RunImpl() { |
616 drive::DriveIntegrationService* integration_service = | 641 drive::DriveIntegrationService* integration_service = |
617 drive::DriveIntegrationServiceFactory::GetForProfile(profile_); | 642 drive::DriveIntegrationServiceFactory::GetForProfile(profile_); |
618 bool refresh; | 643 bool refresh; |
619 args_->GetBoolean(0, &refresh); | 644 args_->GetBoolean(0, &refresh); |
620 | 645 |
621 if (!integration_service) { | 646 if (!integration_service) { |
622 SetResult(new base::StringValue("")); | 647 SetResult(new base::StringValue("")); |
623 SendResponse(true); | 648 SendResponse(true); |
624 return true; | 649 return true; |
625 } | 650 } |
626 | 651 |
627 // If refreshing is requested, then clear the token to refetch it. | 652 // If refreshing is requested, then clear the token to refetch it. |
628 if (refresh) | 653 if (refresh) |
629 integration_service->drive_service()->ClearAccessToken(); | 654 integration_service->drive_service()->ClearAccessToken(); |
630 | 655 |
631 // Retrieve the cached auth token (if available), otherwise the AuthService | 656 // Retrieve the cached auth token (if available), otherwise the AuthService |
632 // instance will try to refetch it. | 657 // instance will try to refetch it. |
633 integration_service->drive_service()->RequestAccessToken( | 658 integration_service->drive_service()->RequestAccessToken( |
634 base::Bind(&RequestAccessTokenFunction::OnAccessTokenFetched, this)); | 659 base::Bind(&FileBrowserPrivateRequestAccessTokenFunction:: |
660 OnAccessTokenFetched, this)); | |
635 return true; | 661 return true; |
636 } | 662 } |
637 | 663 |
638 void RequestAccessTokenFunction::OnAccessTokenFetched( | 664 void FileBrowserPrivateRequestAccessTokenFunction::OnAccessTokenFetched( |
639 google_apis::GDataErrorCode code, const std::string& access_token) { | 665 google_apis::GDataErrorCode code, const std::string& access_token) { |
640 SetResult(new base::StringValue(access_token)); | 666 SetResult(new base::StringValue(access_token)); |
641 SendResponse(true); | 667 SendResponse(true); |
642 } | 668 } |
643 | 669 |
644 GetShareUrlFunction::GetShareUrlFunction() { | 670 FileBrowserPrivateGetShareUrlFunction::FileBrowserPrivateGetShareUrlFunction() { |
645 } | 671 } |
646 | 672 |
647 GetShareUrlFunction::~GetShareUrlFunction() { | 673 FileBrowserPrivateGetShareUrlFunction:: |
674 ~FileBrowserPrivateGetShareUrlFunction() { | |
648 } | 675 } |
649 | 676 |
650 bool GetShareUrlFunction::RunImpl() { | 677 bool FileBrowserPrivateGetShareUrlFunction::RunImpl() { |
651 std::string file_url; | 678 std::string file_url; |
652 if (!args_->GetString(0, &file_url)) | 679 if (!args_->GetString(0, &file_url)) |
653 return false; | 680 return false; |
654 | 681 |
655 const base::FilePath path = file_manager::util::GetLocalPathFromURL( | 682 const base::FilePath path = file_manager::util::GetLocalPathFromURL( |
656 render_view_host(), profile(), GURL(file_url)); | 683 render_view_host(), profile(), GURL(file_url)); |
657 DCHECK(drive::util::IsUnderDriveMountPoint(path)); | 684 DCHECK(drive::util::IsUnderDriveMountPoint(path)); |
658 | 685 |
659 base::FilePath drive_path = drive::util::ExtractDrivePath(path); | 686 base::FilePath drive_path = drive::util::ExtractDrivePath(path); |
660 | 687 |
661 drive::DriveIntegrationService* integration_service = | 688 drive::DriveIntegrationService* integration_service = |
662 drive::DriveIntegrationServiceFactory::GetForProfile(profile_); | 689 drive::DriveIntegrationServiceFactory::GetForProfile(profile_); |
663 // |integration_service| is NULL if Drive is disabled. | 690 // |integration_service| is NULL if Drive is disabled. |
664 if (!integration_service) | 691 if (!integration_service) |
665 return false; | 692 return false; |
666 | 693 |
667 integration_service->file_system()->GetShareUrl( | 694 integration_service->file_system()->GetShareUrl( |
668 drive_path, | 695 drive_path, |
669 file_manager::util::GetFileManagerBaseUrl(), // embed origin | 696 file_manager::util::GetFileManagerBaseUrl(), // embed origin |
670 base::Bind(&GetShareUrlFunction::OnGetShareUrl, this)); | 697 base::Bind(&FileBrowserPrivateGetShareUrlFunction::OnGetShareUrl, this)); |
671 return true; | 698 return true; |
672 } | 699 } |
673 | 700 |
674 | 701 |
675 void GetShareUrlFunction::OnGetShareUrl(drive::FileError error, | 702 void FileBrowserPrivateGetShareUrlFunction::OnGetShareUrl( |
676 const GURL& share_url) { | 703 drive::FileError error, const GURL& share_url) { |
hashimoto
2013/08/30 06:03:14
nit: These arguments may better be placed in a one
hirono
2013/08/30 06:26:46
Done.
| |
677 if (error != drive::FILE_ERROR_OK) { | 704 if (error != drive::FILE_ERROR_OK) { |
678 error_ = "Share Url for this item is not available."; | 705 error_ = "Share Url for this item is not available."; |
679 SendResponse(false); | 706 SendResponse(false); |
680 return; | 707 return; |
681 } | 708 } |
682 | 709 |
683 SetResult(new base::StringValue(share_url.spec())); | 710 SetResult(new base::StringValue(share_url.spec())); |
684 SendResponse(true); | 711 SendResponse(true); |
685 } | 712 } |
686 | 713 |
687 } // namespace extensions | 714 } // namespace extensions |
OLD | NEW |