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 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
380 } | 380 } |
381 | 381 |
382 mount_info->SetString("mountCondition", | 382 mount_info->SetString("mountCondition", |
383 DiskMountManager::MountConditionToString( | 383 DiskMountManager::MountConditionToString( |
384 mount_point_info.mount_condition)); | 384 mount_point_info.mount_condition)); |
385 | 385 |
386 return mount_info; | 386 return mount_info; |
387 } | 387 } |
388 #endif // defined(OS_CHROMEOS) | 388 #endif // defined(OS_CHROMEOS) |
389 | 389 |
390 // Given a file url, find the virtual FilePath associated with it. | |
391 FilePath GetVirtualPathFromURL(const GURL& file_url) { | |
392 FilePath virtual_path; | |
393 fileapi::FileSystemType type = fileapi::kFileSystemTypeUnknown; | |
394 GURL file_origin_url; | |
395 if (!CrackFileSystemURL(file_url, &file_origin_url, &type, &virtual_path) || | |
396 type != fileapi::kFileSystemTypeExternal) { | |
397 NOTREACHED(); | |
398 return FilePath(); | |
399 } | |
400 return virtual_path; | |
401 } | |
402 | |
403 // Delegate used to find file properties. | |
404 class FilePropertiesDelegate : public gdata::FindFileDelegate { | |
405 public: | |
406 FilePropertiesDelegate(); | |
407 virtual ~FilePropertiesDelegate(); | |
408 | |
409 // Builds a dictionary from the GDataFile file property information | |
410 void CopyProperties(base::DictionaryValue* property_dict); | |
411 | |
412 base::PlatformFileError error() const { return error_; } | |
413 | |
414 private: | |
415 // GDataFileSystem::FindFileDelegate overrides. | |
416 virtual void OnFileFound(gdata::GDataFile* file) OVERRIDE; | |
417 virtual void OnDirectoryFound(const FilePath&, | |
418 gdata::GDataDirectory* dir) OVERRIDE; | |
419 virtual FindFileTraversalCommand OnEnterDirectory( | |
420 const FilePath&, | |
421 gdata::GDataDirectory*) OVERRIDE; | |
422 virtual void OnError(base::PlatformFileError error) OVERRIDE; | |
423 | |
424 GURL thumbnail_url_; | |
425 GURL edit_url_; | |
426 int cache_state_; | |
427 base::PlatformFileError error_; | |
428 }; | |
429 | |
430 // FilePropertiesDelegate class implementation. | |
431 | |
432 FilePropertiesDelegate::FilePropertiesDelegate() | |
433 : cache_state_(0), error_(base::PLATFORM_FILE_OK) { | |
434 } | |
435 | |
436 FilePropertiesDelegate::~FilePropertiesDelegate() { } | |
437 | |
438 void FilePropertiesDelegate::CopyProperties( | |
439 base::DictionaryValue* property_dict) { | |
440 DCHECK(property_dict); | |
441 DCHECK(!property_dict->HasKey("thumbnailUrl")); | |
442 DCHECK(!property_dict->HasKey("editUrl")); | |
443 DCHECK(!property_dict->HasKey("isPinned")); | |
444 DCHECK(!property_dict->HasKey("isPresent")); | |
445 DCHECK(!property_dict->HasKey("isDirty")); | |
446 DCHECK(!property_dict->HasKey("errorCode")); | |
447 | |
448 if (error_ != base::PLATFORM_FILE_OK) { | |
449 property_dict->SetInteger("errorCode", error_); | |
450 return; | |
451 } | |
452 | |
453 property_dict->SetString("thumbnailUrl", thumbnail_url_.spec()); | |
454 if (!edit_url_.is_empty()) | |
455 property_dict->SetString("editUrl", edit_url_.spec()); | |
456 property_dict->SetBoolean( | |
457 "isPinned", | |
458 static_cast<bool>(cache_state_ & gdata::GDataFile::CACHE_STATE_PINNED)); | |
459 | |
460 property_dict->SetBoolean( | |
461 "isPresent", | |
462 static_cast<bool>(cache_state_ & gdata::GDataFile::CACHE_STATE_PRESENT)); | |
463 | |
464 base::FundamentalValue* dirty = | |
zel
2012/03/03 00:47:59
one more left
| |
465 new base::FundamentalValue(static_cast<bool>(cache_state_ & | |
466 gdata::GDataFile::CACHE_STATE_DIRTY)); | |
467 property_dict->Set("isDirty", dirty); | |
468 } | |
469 | |
470 void FilePropertiesDelegate::OnFileFound(gdata::GDataFile* file) { | |
471 DCHECK(!file->file_info().is_directory); | |
472 thumbnail_url_ = file->thumbnail_url(); | |
473 edit_url_ = file->edit_url(); | |
474 cache_state_ = file->cache_state(); | |
475 } | |
476 | |
477 void FilePropertiesDelegate::OnDirectoryFound(const FilePath&, | |
478 gdata::GDataDirectory* dir) { | |
479 DCHECK(dir->file_info().is_directory); | |
480 // We don't set anything here because we don't have any properties for | |
481 // directories yet. | |
482 } | |
483 | |
484 gdata::FindFileDelegate::FindFileTraversalCommand | |
485 FilePropertiesDelegate::OnEnterDirectory(const FilePath&, | |
486 gdata::GDataDirectory*) { | |
487 // Keep traversing while doing read only lookups. | |
488 return FIND_FILE_CONTINUES; | |
489 } | |
490 | |
491 void FilePropertiesDelegate::OnError(base::PlatformFileError error) { | |
492 error_ = error; | |
493 } | |
494 | |
390 } // namespace | 495 } // namespace |
391 | 496 |
392 class RequestLocalFileSystemFunction::LocalFileSystemCallbackDispatcher { | 497 class RequestLocalFileSystemFunction::LocalFileSystemCallbackDispatcher { |
393 public: | 498 public: |
394 static fileapi::FileSystemContext::OpenFileSystemCallback CreateCallback( | 499 static fileapi::FileSystemContext::OpenFileSystemCallback CreateCallback( |
395 RequestLocalFileSystemFunction* function, | 500 RequestLocalFileSystemFunction* function, |
396 Profile* profile, | 501 Profile* profile, |
397 int child_id, | 502 int child_id, |
398 scoped_refptr<const Extension> extension) { | 503 scoped_refptr<const Extension> extension) { |
399 return base::Bind( | 504 return base::Bind( |
(...skipping 1405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1805 ChromeURLDataManager::DataSource::SetFontAndTextDirection(dict); | 1910 ChromeURLDataManager::DataSource::SetFontAndTextDirection(dict); |
1806 | 1911 |
1807 dict->SetString("PLAY_MEDIA", | 1912 dict->SetString("PLAY_MEDIA", |
1808 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_PLAY)); | 1913 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_PLAY)); |
1809 | 1914 |
1810 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableGData)) | 1915 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableGData)) |
1811 dict->SetString("ENABLE_GDATA", "1"); | 1916 dict->SetString("ENABLE_GDATA", "1"); |
1812 | 1917 |
1813 return true; | 1918 return true; |
1814 } | 1919 } |
1920 | |
1921 GetGDataFilePropertiesFunction::GetGDataFilePropertiesFunction() { | |
1922 } | |
1923 | |
1924 GetGDataFilePropertiesFunction::~GetGDataFilePropertiesFunction() { | |
1925 } | |
1926 | |
1927 bool GetGDataFilePropertiesFunction::DoOperation(const FilePath& /*path*/) { | |
1928 return false; // Terminate loop early by default. | |
1929 } | |
1930 | |
1931 bool GetGDataFilePropertiesFunction::RunImpl() { | |
1932 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
1933 if (args_->GetSize() != 1) | |
1934 return false; | |
1935 | |
1936 ListValue* path_list = NULL; | |
1937 args_->GetList(0, &path_list); | |
1938 DCHECK(path_list); | |
1939 std::vector<GURL> file_urls; | |
1940 std::vector<FilePath> file_paths; | |
1941 | |
1942 size_t len = path_list->GetSize(); | |
1943 file_paths.reserve(len); | |
1944 file_urls.reserve(len); | |
1945 std::string file_str; | |
1946 GURL file_url; | |
1947 for (size_t i = 0; i < len; ++i) { | |
1948 path_list->GetString(i, &file_str); | |
1949 file_url = GURL(file_str); | |
1950 file_urls.push_back(file_url); | |
1951 file_paths.push_back(GetVirtualPathFromURL(file_url)); | |
1952 } | |
1953 | |
1954 for (std::vector<FilePath>::iterator iter = file_paths.begin(); | |
1955 iter != file_paths.end(); ++iter) { | |
1956 if (!DoOperation(*iter)) | |
1957 break; | |
1958 } | |
1959 | |
1960 base::ListValue* file_properties = new base::ListValue; | |
1961 gdata::GDataFileSystem* file_system = | |
1962 gdata::GDataFileSystemFactory::GetForProfile(profile_); | |
1963 DCHECK(file_system); | |
1964 for (std::vector<FilePath>::size_type i = 0; i < file_paths.size(); ++i) { | |
1965 scoped_refptr<FilePropertiesDelegate> property_delegate( | |
1966 new FilePropertiesDelegate()); | |
1967 file_system->FindFileByPath(file_paths[i], property_delegate); | |
1968 base::DictionaryValue* property_dict = new base::DictionaryValue; | |
1969 property_delegate->CopyProperties(property_dict); | |
1970 property_dict->SetString("fileUrl", file_urls[i].spec()); | |
1971 file_properties->Append(property_dict); | |
1972 } | |
1973 | |
1974 result_.reset(file_properties); | |
1975 | |
1976 return true; | |
1977 } | |
1978 | |
1979 PinGDataFileFunction::PinGDataFileFunction() { | |
1980 } | |
1981 | |
1982 PinGDataFileFunction::~PinGDataFileFunction() { | |
1983 } | |
1984 | |
1985 bool PinGDataFileFunction::DoOperation(const FilePath& /*path*/) { | |
1986 // TODO(gspencer): Actually pin the file here. | |
1987 return true; | |
1988 } | |
1989 | |
OLD | NEW |