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

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

Issue 1036723003: favor DCHECK_CURRENTLY_ON for better logs in chrome/browser/chromeos/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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
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_drive.h" 5 #include "chrome/browser/chromeos/extensions/file_manager/private_api_drive.h"
6 6
7 #include <map> 7 #include <map>
8 #include <set> 8 #include <set>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 class SingleEntryPropertiesGetterForDrive { 165 class SingleEntryPropertiesGetterForDrive {
166 public: 166 public:
167 typedef base::Callback<void(scoped_ptr<EntryProperties> properties, 167 typedef base::Callback<void(scoped_ptr<EntryProperties> properties,
168 base::File::Error error)> ResultCallback; 168 base::File::Error error)> ResultCallback;
169 169
170 // Creates an instance and starts the process. 170 // Creates an instance and starts the process.
171 static void Start(const base::FilePath local_path, 171 static void Start(const base::FilePath local_path,
172 const std::set<EntryPropertyName>& names, 172 const std::set<EntryPropertyName>& names,
173 Profile* const profile, 173 Profile* const profile,
174 const ResultCallback& callback) { 174 const ResultCallback& callback) {
175 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 175 DCHECK_CURRENTLY_ON(BrowserThread::UI);
176 176
177 SingleEntryPropertiesGetterForDrive* instance = 177 SingleEntryPropertiesGetterForDrive* instance =
178 new SingleEntryPropertiesGetterForDrive(local_path, names, profile, 178 new SingleEntryPropertiesGetterForDrive(local_path, names, profile,
179 callback); 179 callback);
180 instance->StartProcess(); 180 instance->StartProcess();
181 181
182 // The instance will be destroyed by itself. 182 // The instance will be destroyed by itself.
183 } 183 }
184 184
185 virtual ~SingleEntryPropertiesGetterForDrive() {} 185 virtual ~SingleEntryPropertiesGetterForDrive() {}
186 186
187 private: 187 private:
188 SingleEntryPropertiesGetterForDrive( 188 SingleEntryPropertiesGetterForDrive(
189 const base::FilePath local_path, 189 const base::FilePath local_path,
190 const std::set<EntryPropertyName>& /* names */, 190 const std::set<EntryPropertyName>& /* names */,
191 Profile* const profile, 191 Profile* const profile,
192 const ResultCallback& callback) 192 const ResultCallback& callback)
193 : callback_(callback), 193 : callback_(callback),
194 local_path_(local_path), 194 local_path_(local_path),
195 running_profile_(profile), 195 running_profile_(profile),
196 properties_(new EntryProperties), 196 properties_(new EntryProperties),
197 file_owner_profile_(NULL), 197 file_owner_profile_(NULL),
198 weak_ptr_factory_(this) { 198 weak_ptr_factory_(this) {
199 DCHECK(!callback_.is_null()); 199 DCHECK(!callback_.is_null());
200 DCHECK(profile); 200 DCHECK(profile);
201 } 201 }
202 202
203 void StartProcess() { 203 void StartProcess() {
204 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 204 DCHECK_CURRENTLY_ON(BrowserThread::UI);
205 205
206 file_path_ = drive::util::ExtractDrivePath(local_path_); 206 file_path_ = drive::util::ExtractDrivePath(local_path_);
207 file_owner_profile_ = drive::util::ExtractProfileFromPath(local_path_); 207 file_owner_profile_ = drive::util::ExtractProfileFromPath(local_path_);
208 208
209 if (!file_owner_profile_ || 209 if (!file_owner_profile_ ||
210 !g_browser_process->profile_manager()->IsValidProfile( 210 !g_browser_process->profile_manager()->IsValidProfile(
211 file_owner_profile_)) { 211 file_owner_profile_)) {
212 CompleteGetEntryProperties(drive::FILE_ERROR_FAILED); 212 CompleteGetEntryProperties(drive::FILE_ERROR_FAILED);
213 return; 213 return;
214 } 214 }
215 215
216 // Start getting the file info. 216 // Start getting the file info.
217 drive::FileSystemInterface* const file_system = 217 drive::FileSystemInterface* const file_system =
218 drive::util::GetFileSystemByProfile(file_owner_profile_); 218 drive::util::GetFileSystemByProfile(file_owner_profile_);
219 if (!file_system) { 219 if (!file_system) {
220 // |file_system| is NULL if Drive is disabled or not mounted. 220 // |file_system| is NULL if Drive is disabled or not mounted.
221 CompleteGetEntryProperties(drive::FILE_ERROR_FAILED); 221 CompleteGetEntryProperties(drive::FILE_ERROR_FAILED);
222 return; 222 return;
223 } 223 }
224 224
225 file_system->GetResourceEntry( 225 file_system->GetResourceEntry(
226 file_path_, 226 file_path_,
227 base::Bind(&SingleEntryPropertiesGetterForDrive::OnGetFileInfo, 227 base::Bind(&SingleEntryPropertiesGetterForDrive::OnGetFileInfo,
228 weak_ptr_factory_.GetWeakPtr())); 228 weak_ptr_factory_.GetWeakPtr()));
229 } 229 }
230 230
231 void OnGetFileInfo(drive::FileError error, 231 void OnGetFileInfo(drive::FileError error,
232 scoped_ptr<drive::ResourceEntry> entry) { 232 scoped_ptr<drive::ResourceEntry> entry) {
233 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 233 DCHECK_CURRENTLY_ON(BrowserThread::UI);
234 234
235 if (error != drive::FILE_ERROR_OK) { 235 if (error != drive::FILE_ERROR_OK) {
236 CompleteGetEntryProperties(error); 236 CompleteGetEntryProperties(error);
237 return; 237 return;
238 } 238 }
239 239
240 DCHECK(entry); 240 DCHECK(entry);
241 owner_resource_entry_.swap(entry); 241 owner_resource_entry_.swap(entry);
242 242
243 if (running_profile_->IsSameProfile(file_owner_profile_)) { 243 if (running_profile_->IsSameProfile(file_owner_profile_)) {
(...skipping 10 matching lines...) Expand all
254 return; 254 return;
255 } 255 }
256 file_system->GetPathFromResourceId( 256 file_system->GetPathFromResourceId(
257 owner_resource_entry_->resource_id(), 257 owner_resource_entry_->resource_id(),
258 base::Bind(&SingleEntryPropertiesGetterForDrive::OnGetRunningPath, 258 base::Bind(&SingleEntryPropertiesGetterForDrive::OnGetRunningPath,
259 weak_ptr_factory_.GetWeakPtr())); 259 weak_ptr_factory_.GetWeakPtr()));
260 } 260 }
261 261
262 void OnGetRunningPath(drive::FileError error, 262 void OnGetRunningPath(drive::FileError error,
263 const base::FilePath& file_path) { 263 const base::FilePath& file_path) {
264 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 264 DCHECK_CURRENTLY_ON(BrowserThread::UI);
265 265
266 if (error != drive::FILE_ERROR_OK) { 266 if (error != drive::FILE_ERROR_OK) {
267 // The running profile does not know the file. 267 // The running profile does not know the file.
268 StartParseFileInfo(false); 268 StartParseFileInfo(false);
269 return; 269 return;
270 } 270 }
271 271
272 drive::FileSystemInterface* const file_system = 272 drive::FileSystemInterface* const file_system =
273 drive::util::GetFileSystemByProfile(running_profile_); 273 drive::util::GetFileSystemByProfile(running_profile_);
274 if (!file_system) { 274 if (!file_system) {
275 // The drive is disable for the running profile. 275 // The drive is disable for the running profile.
276 StartParseFileInfo(false); 276 StartParseFileInfo(false);
277 return; 277 return;
278 } 278 }
279 279
280 file_system->GetResourceEntry( 280 file_system->GetResourceEntry(
281 file_path, 281 file_path,
282 base::Bind(&SingleEntryPropertiesGetterForDrive::OnGetShareInfo, 282 base::Bind(&SingleEntryPropertiesGetterForDrive::OnGetShareInfo,
283 weak_ptr_factory_.GetWeakPtr())); 283 weak_ptr_factory_.GetWeakPtr()));
284 } 284 }
285 285
286 void OnGetShareInfo(drive::FileError error, 286 void OnGetShareInfo(drive::FileError error,
287 scoped_ptr<drive::ResourceEntry> entry) { 287 scoped_ptr<drive::ResourceEntry> entry) {
288 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 288 DCHECK_CURRENTLY_ON(BrowserThread::UI);
289 289
290 if (error != drive::FILE_ERROR_OK) { 290 if (error != drive::FILE_ERROR_OK) {
291 CompleteGetEntryProperties(error); 291 CompleteGetEntryProperties(error);
292 return; 292 return;
293 } 293 }
294 294
295 DCHECK(entry.get()); 295 DCHECK(entry.get());
296 StartParseFileInfo(entry->shared_with_me()); 296 StartParseFileInfo(entry->shared_with_me());
297 } 297 }
298 298
299 void StartParseFileInfo(bool shared_with_me) { 299 void StartParseFileInfo(bool shared_with_me) {
300 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 300 DCHECK_CURRENTLY_ON(BrowserThread::UI);
301 301
302 FillEntryPropertiesValueForDrive( 302 FillEntryPropertiesValueForDrive(
303 *owner_resource_entry_, shared_with_me, properties_.get()); 303 *owner_resource_entry_, shared_with_me, properties_.get());
304 304
305 drive::FileSystemInterface* const file_system = 305 drive::FileSystemInterface* const file_system =
306 drive::util::GetFileSystemByProfile(file_owner_profile_); 306 drive::util::GetFileSystemByProfile(file_owner_profile_);
307 drive::DriveAppRegistry* const app_registry = 307 drive::DriveAppRegistry* const app_registry =
308 drive::util::GetDriveAppRegistryByProfile(file_owner_profile_); 308 drive::util::GetDriveAppRegistryByProfile(file_owner_profile_);
309 if (!file_system || !app_registry) { 309 if (!file_system || !app_registry) {
310 // |file_system| or |app_registry| is NULL if Drive is disabled. 310 // |file_system| or |app_registry| is NULL if Drive is disabled.
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 app_info.document_icons, drive::util::kPreferredIconSize); 345 app_info.document_icons, drive::util::kPreferredIconSize);
346 properties_->custom_icon_url.reset(new std::string(doc_icon.spec())); 346 properties_->custom_icon_url.reset(new std::string(doc_icon.spec()));
347 } 347 }
348 } 348 }
349 } 349 }
350 350
351 CompleteGetEntryProperties(drive::FILE_ERROR_OK); 351 CompleteGetEntryProperties(drive::FILE_ERROR_OK);
352 } 352 }
353 353
354 void CompleteGetEntryProperties(drive::FileError error) { 354 void CompleteGetEntryProperties(drive::FileError error) {
355 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 355 DCHECK_CURRENTLY_ON(BrowserThread::UI);
356 DCHECK(!callback_.is_null()); 356 DCHECK(!callback_.is_null());
357 357
358 callback_.Run(properties_.Pass(), drive::FileErrorToBaseFileError(error)); 358 callback_.Run(properties_.Pass(), drive::FileErrorToBaseFileError(error));
359 BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, this); 359 BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, this);
360 } 360 }
361 361
362 // Given parameters. 362 // Given parameters.
363 const ResultCallback callback_; 363 const ResultCallback callback_;
364 const base::FilePath local_path_; 364 const base::FilePath local_path_;
365 Profile* const running_profile_; 365 Profile* const running_profile_;
366 366
367 // Values used in the process. 367 // Values used in the process.
368 scoped_ptr<EntryProperties> properties_; 368 scoped_ptr<EntryProperties> properties_;
369 Profile* file_owner_profile_; 369 Profile* file_owner_profile_;
370 base::FilePath file_path_; 370 base::FilePath file_path_;
371 scoped_ptr<drive::ResourceEntry> owner_resource_entry_; 371 scoped_ptr<drive::ResourceEntry> owner_resource_entry_;
372 372
373 base::WeakPtrFactory<SingleEntryPropertiesGetterForDrive> weak_ptr_factory_; 373 base::WeakPtrFactory<SingleEntryPropertiesGetterForDrive> weak_ptr_factory_;
374 }; // class SingleEntryPropertiesGetterForDrive 374 }; // class SingleEntryPropertiesGetterForDrive
375 375
376 class SingleEntryPropertiesGetterForFileSystemProvider { 376 class SingleEntryPropertiesGetterForFileSystemProvider {
377 public: 377 public:
378 typedef base::Callback<void(scoped_ptr<EntryProperties> properties, 378 typedef base::Callback<void(scoped_ptr<EntryProperties> properties,
379 base::File::Error error)> ResultCallback; 379 base::File::Error error)> ResultCallback;
380 380
381 // Creates an instance and starts the process. 381 // Creates an instance and starts the process.
382 static void Start(const storage::FileSystemURL file_system_url, 382 static void Start(const storage::FileSystemURL file_system_url,
383 const std::set<EntryPropertyName>& names, 383 const std::set<EntryPropertyName>& names,
384 const ResultCallback& callback) { 384 const ResultCallback& callback) {
385 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 385 DCHECK_CURRENTLY_ON(BrowserThread::UI);
386 386
387 SingleEntryPropertiesGetterForFileSystemProvider* instance = 387 SingleEntryPropertiesGetterForFileSystemProvider* instance =
388 new SingleEntryPropertiesGetterForFileSystemProvider(file_system_url, 388 new SingleEntryPropertiesGetterForFileSystemProvider(file_system_url,
389 names, callback); 389 names, callback);
390 instance->StartProcess(); 390 instance->StartProcess();
391 391
392 // The instance will be destroyed by itself. 392 // The instance will be destroyed by itself.
393 } 393 }
394 394
395 virtual ~SingleEntryPropertiesGetterForFileSystemProvider() {} 395 virtual ~SingleEntryPropertiesGetterForFileSystemProvider() {}
396 396
397 private: 397 private:
398 SingleEntryPropertiesGetterForFileSystemProvider( 398 SingleEntryPropertiesGetterForFileSystemProvider(
399 const storage::FileSystemURL& file_system_url, 399 const storage::FileSystemURL& file_system_url,
400 const std::set<EntryPropertyName>& names, 400 const std::set<EntryPropertyName>& names,
401 const ResultCallback& callback) 401 const ResultCallback& callback)
402 : callback_(callback), 402 : callback_(callback),
403 file_system_url_(file_system_url), 403 file_system_url_(file_system_url),
404 names_(names), 404 names_(names),
405 properties_(new EntryProperties), 405 properties_(new EntryProperties),
406 weak_ptr_factory_(this) { 406 weak_ptr_factory_(this) {
407 DCHECK(!callback_.is_null()); 407 DCHECK(!callback_.is_null());
408 } 408 }
409 409
410 void StartProcess() { 410 void StartProcess() {
411 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 411 DCHECK_CURRENTLY_ON(BrowserThread::UI);
412 412
413 FileSystemURLParser parser(file_system_url_); 413 FileSystemURLParser parser(file_system_url_);
414 if (!parser.Parse()) { 414 if (!parser.Parse()) {
415 CompleteGetEntryProperties(base::File::FILE_ERROR_NOT_FOUND); 415 CompleteGetEntryProperties(base::File::FILE_ERROR_NOT_FOUND);
416 return; 416 return;
417 } 417 }
418 418
419 ProvidedFileSystemInterface::MetadataFieldMask field_mask = 419 ProvidedFileSystemInterface::MetadataFieldMask field_mask =
420 ProvidedFileSystemInterface::METADATA_FIELD_DEFAULT; 420 ProvidedFileSystemInterface::METADATA_FIELD_DEFAULT;
421 // TODO(mtomasz): Add other fields. All of them should be requested on 421 // TODO(mtomasz): Add other fields. All of them should be requested on
422 // demand. crbug.com/413161. 422 // demand. crbug.com/413161.
423 if (names_.find( 423 if (names_.find(
424 api::file_manager_private::ENTRY_PROPERTY_NAME_THUMBNAILURL) != 424 api::file_manager_private::ENTRY_PROPERTY_NAME_THUMBNAILURL) !=
425 names_.end()) 425 names_.end())
426 field_mask |= ProvidedFileSystemInterface::METADATA_FIELD_THUMBNAIL; 426 field_mask |= ProvidedFileSystemInterface::METADATA_FIELD_THUMBNAIL;
427 427
428 parser.file_system()->GetMetadata( 428 parser.file_system()->GetMetadata(
429 parser.file_path(), field_mask, 429 parser.file_path(), field_mask,
430 base::Bind(&SingleEntryPropertiesGetterForFileSystemProvider:: 430 base::Bind(&SingleEntryPropertiesGetterForFileSystemProvider::
431 OnGetMetadataCompleted, 431 OnGetMetadataCompleted,
432 weak_ptr_factory_.GetWeakPtr())); 432 weak_ptr_factory_.GetWeakPtr()));
433 } 433 }
434 434
435 void OnGetMetadataCompleted(scoped_ptr<EntryMetadata> metadata, 435 void OnGetMetadataCompleted(scoped_ptr<EntryMetadata> metadata,
436 base::File::Error result) { 436 base::File::Error result) {
437 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 437 DCHECK_CURRENTLY_ON(BrowserThread::UI);
438 438
439 if (result != base::File::FILE_OK) { 439 if (result != base::File::FILE_OK) {
440 CompleteGetEntryProperties(result); 440 CompleteGetEntryProperties(result);
441 return; 441 return;
442 } 442 }
443 443
444 properties_->size.reset(new double(metadata->size)); 444 properties_->size.reset(new double(metadata->size));
445 properties_->modification_time.reset( 445 properties_->modification_time.reset(
446 new double(metadata->modification_time.ToJsTime())); 446 new double(metadata->modification_time.ToJsTime()));
447 447
448 if (!metadata->thumbnail.empty()) 448 if (!metadata->thumbnail.empty())
449 properties_->thumbnail_url.reset(new std::string(metadata->thumbnail)); 449 properties_->thumbnail_url.reset(new std::string(metadata->thumbnail));
450 450
451 CompleteGetEntryProperties(base::File::FILE_OK); 451 CompleteGetEntryProperties(base::File::FILE_OK);
452 } 452 }
453 453
454 void CompleteGetEntryProperties(base::File::Error result) { 454 void CompleteGetEntryProperties(base::File::Error result) {
455 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 455 DCHECK_CURRENTLY_ON(BrowserThread::UI);
456 DCHECK(!callback_.is_null()); 456 DCHECK(!callback_.is_null());
457 457
458 callback_.Run(properties_.Pass(), result); 458 callback_.Run(properties_.Pass(), result);
459 BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, this); 459 BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, this);
460 } 460 }
461 461
462 // Given parameters. 462 // Given parameters.
463 const ResultCallback callback_; 463 const ResultCallback callback_;
464 const storage::FileSystemURL file_system_url_; 464 const storage::FileSystemURL file_system_url_;
465 const std::set<EntryPropertyName> names_; 465 const std::set<EntryPropertyName> names_;
(...skipping 10 matching lines...) Expand all
476 FileManagerPrivateGetEntryPropertiesFunction:: 476 FileManagerPrivateGetEntryPropertiesFunction::
477 FileManagerPrivateGetEntryPropertiesFunction() 477 FileManagerPrivateGetEntryPropertiesFunction()
478 : processed_count_(0) { 478 : processed_count_(0) {
479 } 479 }
480 480
481 FileManagerPrivateGetEntryPropertiesFunction:: 481 FileManagerPrivateGetEntryPropertiesFunction::
482 ~FileManagerPrivateGetEntryPropertiesFunction() { 482 ~FileManagerPrivateGetEntryPropertiesFunction() {
483 } 483 }
484 484
485 bool FileManagerPrivateGetEntryPropertiesFunction::RunAsync() { 485 bool FileManagerPrivateGetEntryPropertiesFunction::RunAsync() {
486 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 486 DCHECK_CURRENTLY_ON(BrowserThread::UI);
487 487
488 using api::file_manager_private::GetEntryProperties::Params; 488 using api::file_manager_private::GetEntryProperties::Params;
489 const scoped_ptr<Params> params(Params::Create(*args_)); 489 const scoped_ptr<Params> params(Params::Create(*args_));
490 EXTENSION_FUNCTION_VALIDATE(params); 490 EXTENSION_FUNCTION_VALIDATE(params);
491 491
492 scoped_refptr<storage::FileSystemContext> file_system_context = 492 scoped_refptr<storage::FileSystemContext> file_system_context =
493 file_manager::util::GetFileSystemContextForRenderViewHost( 493 file_manager::util::GetFileSystemContextForRenderViewHost(
494 GetProfile(), render_view_host()); 494 GetProfile(), render_view_host());
495 495
496 properties_list_.resize(params->file_urls.size()); 496 properties_list_.resize(params->file_urls.size());
(...skipping 29 matching lines...) Expand all
526 } 526 }
527 527
528 return true; 528 return true;
529 } 529 }
530 530
531 void FileManagerPrivateGetEntryPropertiesFunction::CompleteGetEntryProperties( 531 void FileManagerPrivateGetEntryPropertiesFunction::CompleteGetEntryProperties(
532 size_t index, 532 size_t index,
533 const storage::FileSystemURL& url, 533 const storage::FileSystemURL& url,
534 scoped_ptr<EntryProperties> properties, 534 scoped_ptr<EntryProperties> properties,
535 base::File::Error error) { 535 base::File::Error error) {
536 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 536 DCHECK_CURRENTLY_ON(BrowserThread::UI);
537 DCHECK(0 <= processed_count_ && processed_count_ < properties_list_.size()); 537 DCHECK(0 <= processed_count_ && processed_count_ < properties_list_.size());
538 538
539 properties_list_[index] = make_linked_ptr(properties.release()); 539 properties_list_[index] = make_linked_ptr(properties.release());
540 if (error == base::File::FILE_OK) { 540 if (error == base::File::FILE_OK) {
541 properties_list_[index]->external_file_url.reset( 541 properties_list_[index]->external_file_url.reset(
542 new std::string(chromeos::FileSystemURLToExternalFileURL(url).spec())); 542 new std::string(chromeos::FileSystemURLToExternalFileURL(url).spec()));
543 } 543 }
544 544
545 processed_count_++; 545 processed_count_++;
546 if (processed_count_ < properties_list_.size()) 546 if (processed_count_ < properties_list_.size())
547 return; 547 return;
548 548
549 results_ = extensions::api::file_manager_private::GetEntryProperties:: 549 results_ = extensions::api::file_manager_private::GetEntryProperties::
550 Results::Create(properties_list_); 550 Results::Create(properties_list_);
551 SendResponse(true); 551 SendResponse(true);
552 } 552 }
553 553
554 bool FileManagerPrivatePinDriveFileFunction::RunAsync() { 554 bool FileManagerPrivatePinDriveFileFunction::RunAsync() {
555 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 555 DCHECK_CURRENTLY_ON(BrowserThread::UI);
556 556
557 using extensions::api::file_manager_private::PinDriveFile::Params; 557 using extensions::api::file_manager_private::PinDriveFile::Params;
558 const scoped_ptr<Params> params(Params::Create(*args_)); 558 const scoped_ptr<Params> params(Params::Create(*args_));
559 EXTENSION_FUNCTION_VALIDATE(params); 559 EXTENSION_FUNCTION_VALIDATE(params);
560 560
561 drive::FileSystemInterface* const file_system = 561 drive::FileSystemInterface* const file_system =
562 drive::util::GetFileSystemByProfile(GetProfile()); 562 drive::util::GetFileSystemByProfile(GetProfile());
563 if (!file_system) // |file_system| is NULL if Drive is disabled. 563 if (!file_system) // |file_system| is NULL if Drive is disabled.
564 return false; 564 return false;
565 565
566 const base::FilePath drive_path = 566 const base::FilePath drive_path =
567 drive::util::ExtractDrivePath(file_manager::util::GetLocalPathFromURL( 567 drive::util::ExtractDrivePath(file_manager::util::GetLocalPathFromURL(
568 render_view_host(), GetProfile(), GURL(params->file_url))); 568 render_view_host(), GetProfile(), GURL(params->file_url)));
569 if (params->pin) { 569 if (params->pin) {
570 file_system->Pin(drive_path, 570 file_system->Pin(drive_path,
571 base::Bind(&FileManagerPrivatePinDriveFileFunction:: 571 base::Bind(&FileManagerPrivatePinDriveFileFunction::
572 OnPinStateSet, this)); 572 OnPinStateSet, this));
573 } else { 573 } else {
574 file_system->Unpin(drive_path, 574 file_system->Unpin(drive_path,
575 base::Bind(&FileManagerPrivatePinDriveFileFunction:: 575 base::Bind(&FileManagerPrivatePinDriveFileFunction::
576 OnPinStateSet, this)); 576 OnPinStateSet, this));
577 } 577 }
578 return true; 578 return true;
579 } 579 }
580 580
581 void FileManagerPrivatePinDriveFileFunction:: 581 void FileManagerPrivatePinDriveFileFunction::
582 OnPinStateSet(drive::FileError error) { 582 OnPinStateSet(drive::FileError error) {
583 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 583 DCHECK_CURRENTLY_ON(BrowserThread::UI);
584 584
585 if (error == drive::FILE_ERROR_OK) { 585 if (error == drive::FILE_ERROR_OK) {
586 SendResponse(true); 586 SendResponse(true);
587 } else { 587 } else {
588 SetError(drive::FileErrorToString(error)); 588 SetError(drive::FileErrorToString(error));
589 SendResponse(false); 589 SendResponse(false);
590 } 590 }
591 } 591 }
592 592
593 bool FileManagerPrivateCancelFileTransfersFunction::RunAsync() { 593 bool FileManagerPrivateCancelFileTransfersFunction::RunAsync() {
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after
1018 file_system->GetResourceEntry( 1018 file_system->GetResourceEntry(
1019 file_path, 1019 file_path,
1020 base::Bind(&FileManagerPrivateGetDownloadUrlFunction::OnGetResourceEntry, 1020 base::Bind(&FileManagerPrivateGetDownloadUrlFunction::OnGetResourceEntry,
1021 this)); 1021 this));
1022 return true; 1022 return true;
1023 } 1023 }
1024 1024
1025 void FileManagerPrivateGetDownloadUrlFunction::OnGetResourceEntry( 1025 void FileManagerPrivateGetDownloadUrlFunction::OnGetResourceEntry(
1026 drive::FileError error, 1026 drive::FileError error,
1027 scoped_ptr<drive::ResourceEntry> entry) { 1027 scoped_ptr<drive::ResourceEntry> entry) {
1028 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1028 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1029 1029
1030 if (error != drive::FILE_ERROR_OK) { 1030 if (error != drive::FILE_ERROR_OK) {
1031 SetError("Download Url for this item is not available."); 1031 SetError("Download Url for this item is not available.");
1032 SetResult(new base::StringValue("")); // Intentionally returns a blank. 1032 SetResult(new base::StringValue("")); // Intentionally returns a blank.
1033 SendResponse(false); 1033 SendResponse(false);
1034 return; 1034 return;
1035 } 1035 }
1036 1036
1037 download_url_ = 1037 download_url_ =
1038 google_apis::DriveApiUrlGenerator::kBaseDownloadUrlForProduction + 1038 google_apis::DriveApiUrlGenerator::kBaseDownloadUrlForProduction +
(...skipping 26 matching lines...) Expand all
1065 return; 1065 return;
1066 } 1066 }
1067 1067
1068 const std::string url = download_url_ + "?access_token=" + access_token; 1068 const std::string url = download_url_ + "?access_token=" + access_token;
1069 SetResult(new base::StringValue(url)); 1069 SetResult(new base::StringValue(url));
1070 1070
1071 SendResponse(true); 1071 SendResponse(true);
1072 } 1072 }
1073 1073
1074 } // namespace extensions 1074 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698