Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_browser_private_api.h" | 5 #include "chrome/browser/chromeos/extensions/file_browser_private_api.h" |
| 6 | 6 |
| 7 #include "base/base64.h" | 7 #include "base/base64.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
| (...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 379 } | 379 } |
| 380 | 380 |
| 381 mount_info->SetString("mountCondition", | 381 mount_info->SetString("mountCondition", |
| 382 DiskMountManager::MountConditionToString( | 382 DiskMountManager::MountConditionToString( |
| 383 mount_point_info.mount_condition)); | 383 mount_point_info.mount_condition)); |
| 384 | 384 |
| 385 return mount_info; | 385 return mount_info; |
| 386 } | 386 } |
| 387 #endif // defined(OS_CHROMEOS) | 387 #endif // defined(OS_CHROMEOS) |
| 388 | 388 |
| 389 // Delegate used to find file properties. | |
| 390 class FilePropertiesDelegate : public gdata::FindFileDelegate { | |
| 391 public: | |
| 392 FilePropertiesDelegate(); | |
| 393 virtual ~FilePropertiesDelegate(); | |
| 394 | |
| 395 // Builds a dictionary from the GDataFile file property information | |
| 396 void CopyProperties(base::DictionaryValue* property_dict); | |
| 397 | |
| 398 base::PlatformFileError error() const { return error_; } | |
| 399 | |
| 400 private: | |
| 401 // GDataFileSystem::FindFileDelegate overrides. | |
| 402 virtual void OnFileFound(gdata::GDataFile* file) OVERRIDE; | |
| 403 virtual void OnDirectoryFound(const FilePath&, | |
| 404 gdata::GDataDirectory* dir) OVERRIDE; | |
| 405 virtual FindFileTraversalCommand OnEnterDirectory( | |
| 406 const FilePath&, | |
| 407 gdata::GDataDirectory*) OVERRIDE; | |
| 408 virtual void OnError(base::PlatformFileError error) OVERRIDE; | |
| 409 | |
| 410 GURL thumbnail_url_; | |
| 411 GURL edit_url_; | |
| 412 int cache_state_; | |
| 413 base::PlatformFileError error_; | |
| 414 }; | |
| 415 | |
| 416 // FilePropertiesDelegate class implementation. | |
| 417 | |
| 418 FilePropertiesDelegate::FilePropertiesDelegate() | |
| 419 : cache_state_(0), error_(base::PLATFORM_FILE_OK) { | |
| 420 } | |
| 421 | |
| 422 FilePropertiesDelegate::~FilePropertiesDelegate() { } | |
| 423 | |
| 424 void FilePropertiesDelegate::CopyProperties( | |
| 425 base::DictionaryValue* property_dict) { | |
| 426 DCHECK(property_dict); | |
| 427 DCHECK(!property_dict->HasKey("thumbnailUrl")); | |
| 428 DCHECK(!property_dict->HasKey("editUrl")); | |
| 429 DCHECK(!property_dict->HasKey("isPinned")); | |
| 430 DCHECK(!property_dict->HasKey("isPresent")); | |
| 431 DCHECK(!property_dict->HasKey("isDirty")); | |
| 432 DCHECK(!property_dict->HasKey("errorCode")); | |
| 433 | |
| 434 if (error_ != base::PLATFORM_FILE_OK) { | |
| 435 property_dict->SetInteger("errorCode", error_); | |
| 436 return; | |
| 437 } | |
| 438 | |
| 439 property_dict->SetString("thumbnailUrl", thumbnail_url_.spec()); | |
| 440 property_dict->SetString("editUrl", edit_url_.spec()); | |
|
zel
2012/03/01 22:16:12
let's check if we even have it - only hosted doc i
| |
| 441 | |
| 442 base::FundamentalValue* pinned = | |
| 443 new base::FundamentalValue(static_cast<bool>(cache_state_ & | |
| 444 gdata::GDataFile::CACHE_STATE_PINNED)); | |
| 445 property_dict->Set("isPinned", pinned); | |
| 446 | |
| 447 base::FundamentalValue* present = | |
| 448 new base::FundamentalValue(static_cast<bool>(cache_state_ & | |
| 449 gdata::GDataFile::CACHE_STATE_PRESENT)); | |
| 450 property_dict->Set("isPresent", present); | |
| 451 | |
| 452 base::FundamentalValue* dirty = | |
| 453 new base::FundamentalValue(static_cast<bool>(cache_state_ & | |
| 454 gdata::GDataFile::CACHE_STATE_DIRTY)); | |
| 455 property_dict->Set("isDirty", dirty); | |
| 456 } | |
| 457 | |
| 458 void FilePropertiesDelegate::OnFileFound(gdata::GDataFile* file) { | |
| 459 DCHECK(!file->file_info().is_directory); | |
| 460 thumbnail_url_ = file->thumbnail_url(); | |
| 461 edit_url_ = file->edit_url(); | |
| 462 cache_state_ = file->cache_state(); | |
| 463 } | |
| 464 | |
| 465 void FilePropertiesDelegate::OnDirectoryFound(const FilePath&, | |
| 466 gdata::GDataDirectory* dir) { | |
| 467 DCHECK(dir->file_info().is_directory); | |
| 468 // We don't set anything here because we don't have any properties for | |
| 469 // directories yet. | |
| 470 } | |
| 471 | |
| 472 gdata::FindFileDelegate::FindFileTraversalCommand | |
| 473 FilePropertiesDelegate::OnEnterDirectory(const FilePath&, | |
| 474 gdata::GDataDirectory*) { | |
| 475 // Keep traversing while doing read only lookups. | |
| 476 return FIND_FILE_CONTINUES; | |
| 477 } | |
| 478 | |
| 479 void FilePropertiesDelegate::OnError(base::PlatformFileError error) { | |
| 480 error_ = error; | |
| 481 } | |
| 482 | |
| 483 FilePath GetVirtualPathFromURL(const GURL& file_url) { | |
| 484 FilePath virtual_path; | |
| 485 fileapi::FileSystemType type = fileapi::kFileSystemTypeUnknown; | |
| 486 GURL file_origin_url; | |
| 487 if (!CrackFileSystemURL(file_url, &file_origin_url, &type, &virtual_path) || | |
| 488 type != fileapi::kFileSystemTypeExternal) { | |
| 489 NOTREACHED(); | |
| 490 return FilePath(); | |
| 491 } | |
| 492 return virtual_path; | |
| 493 } | |
| 494 | |
| 389 } // namespace | 495 } // namespace |
| 390 | 496 |
| 391 class RequestLocalFileSystemFunction::LocalFileSystemCallbackDispatcher { | 497 class RequestLocalFileSystemFunction::LocalFileSystemCallbackDispatcher { |
| 392 public: | 498 public: |
| 393 static fileapi::FileSystemContext::OpenFileSystemCallback CreateCallback( | 499 static fileapi::FileSystemContext::OpenFileSystemCallback CreateCallback( |
| 394 RequestLocalFileSystemFunction* function, | 500 RequestLocalFileSystemFunction* function, |
| 395 Profile* profile, | 501 Profile* profile, |
| 396 int child_id, | 502 int child_id, |
| 397 scoped_refptr<const Extension> extension) { | 503 scoped_refptr<const Extension> extension) { |
| 398 return base::Bind( | 504 return base::Bind( |
| (...skipping 1386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1785 ChromeURLDataManager::DataSource::SetFontAndTextDirection(dict); | 1891 ChromeURLDataManager::DataSource::SetFontAndTextDirection(dict); |
| 1786 | 1892 |
| 1787 dict->SetString("PLAY_MEDIA", | 1893 dict->SetString("PLAY_MEDIA", |
| 1788 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_PLAY)); | 1894 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_PLAY)); |
| 1789 | 1895 |
| 1790 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableGData)) | 1896 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableGData)) |
| 1791 dict->SetString("ENABLE_GDATA", "1"); | 1897 dict->SetString("ENABLE_GDATA", "1"); |
| 1792 | 1898 |
| 1793 return true; | 1899 return true; |
| 1794 } | 1900 } |
| 1901 | |
| 1902 GetGDataFilePropertiesFunction::GetGDataFilePropertiesFunction() { | |
| 1903 } | |
| 1904 | |
| 1905 GetGDataFilePropertiesFunction::~GetGDataFilePropertiesFunction() { | |
| 1906 } | |
| 1907 | |
| 1908 bool GetGDataFilePropertiesFunction::RunImpl() { | |
| 1909 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 1910 if (args_->GetSize() != 1) | |
| 1911 return false; | |
| 1912 | |
| 1913 ListValue* path_list = NULL; | |
| 1914 args_->GetList(0, &path_list); | |
| 1915 DCHECK(path_list); | |
| 1916 | |
| 1917 std::string file_url; | |
| 1918 size_t len = path_list->GetSize(); | |
| 1919 FilePathList files; | |
| 1920 files.reserve(len); | |
| 1921 for (size_t i = 0; i < len; ++i) { | |
| 1922 path_list->GetString(i, &file_url); | |
| 1923 files.push_back(GetVirtualPathFromURL(GURL(file_url))); | |
| 1924 } | |
| 1925 | |
| 1926 base::ListValue* file_info = new base::ListValue; | |
| 1927 result_.reset(file_info); | |
| 1928 | |
| 1929 gdata::GDataFileSystem* file_system = | |
| 1930 gdata::GDataFileSystemFactory::GetForProfile(profile_); | |
| 1931 DCHECK(file_system); | |
| 1932 | |
| 1933 for (FilePathList::const_iterator iter = files.begin(); | |
| 1934 iter != files.end(); ++iter) { | |
| 1935 scoped_refptr<FilePropertiesDelegate> property_delegate( | |
| 1936 new FilePropertiesDelegate()); | |
| 1937 file_system->FindFileByPath(*iter, property_delegate); | |
| 1938 base::DictionaryValue* property_dict = new base::DictionaryValue; | |
| 1939 property_delegate->CopyProperties(property_dict); | |
| 1940 file_info->Append(property_dict); | |
| 1941 } | |
| 1942 | |
| 1943 return true; | |
| 1944 } | |
| OLD | NEW |