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

Side by Side Diff: chrome/browser/chromeos/extensions/file_browser_private_api.cc

Issue 9545006: This adds some GData private API to the file manager (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: One last SetBoolean Created 8 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 (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
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 property_dict->SetBoolean(
465 "isDirty",
466 static_cast<bool>(cache_state_ & gdata::GDataFile::CACHE_STATE_DIRTY));
467 }
468
469 void FilePropertiesDelegate::OnFileFound(gdata::GDataFile* file) {
470 DCHECK(!file->file_info().is_directory);
471 thumbnail_url_ = file->thumbnail_url();
472 edit_url_ = file->edit_url();
473 cache_state_ = file->cache_state();
474 }
475
476 void FilePropertiesDelegate::OnDirectoryFound(const FilePath&,
477 gdata::GDataDirectory* dir) {
478 DCHECK(dir->file_info().is_directory);
479 // We don't set anything here because we don't have any properties for
480 // directories yet.
481 }
482
483 gdata::FindFileDelegate::FindFileTraversalCommand
484 FilePropertiesDelegate::OnEnterDirectory(const FilePath&,
485 gdata::GDataDirectory*) {
486 // Keep traversing while doing read only lookups.
487 return FIND_FILE_CONTINUES;
488 }
489
490 void FilePropertiesDelegate::OnError(base::PlatformFileError error) {
491 error_ = error;
492 }
493
390 } // namespace 494 } // namespace
391 495
392 class RequestLocalFileSystemFunction::LocalFileSystemCallbackDispatcher { 496 class RequestLocalFileSystemFunction::LocalFileSystemCallbackDispatcher {
393 public: 497 public:
394 static fileapi::FileSystemContext::OpenFileSystemCallback CreateCallback( 498 static fileapi::FileSystemContext::OpenFileSystemCallback CreateCallback(
395 RequestLocalFileSystemFunction* function, 499 RequestLocalFileSystemFunction* function,
396 Profile* profile, 500 Profile* profile,
397 int child_id, 501 int child_id,
398 scoped_refptr<const Extension> extension) { 502 scoped_refptr<const Extension> extension) {
399 return base::Bind( 503 return base::Bind(
(...skipping 1405 matching lines...) Expand 10 before | Expand all | Expand 10 after
1805 ChromeURLDataManager::DataSource::SetFontAndTextDirection(dict); 1909 ChromeURLDataManager::DataSource::SetFontAndTextDirection(dict);
1806 1910
1807 dict->SetString("PLAY_MEDIA", 1911 dict->SetString("PLAY_MEDIA",
1808 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_PLAY)); 1912 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_PLAY));
1809 1913
1810 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableGData)) 1914 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableGData))
1811 dict->SetString("ENABLE_GDATA", "1"); 1915 dict->SetString("ENABLE_GDATA", "1");
1812 1916
1813 return true; 1917 return true;
1814 } 1918 }
1919
1920 GetGDataFilePropertiesFunction::GetGDataFilePropertiesFunction() {
1921 }
1922
1923 GetGDataFilePropertiesFunction::~GetGDataFilePropertiesFunction() {
1924 }
1925
1926 bool GetGDataFilePropertiesFunction::DoOperation(const FilePath& /*path*/) {
1927 return false; // Terminate loop early by default.
1928 }
1929
1930 bool GetGDataFilePropertiesFunction::RunImpl() {
1931 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1932 if (args_->GetSize() != 1)
1933 return false;
1934
1935 ListValue* path_list = NULL;
1936 args_->GetList(0, &path_list);
1937 DCHECK(path_list);
1938 std::vector<GURL> file_urls;
1939 std::vector<FilePath> file_paths;
1940
1941 size_t len = path_list->GetSize();
1942 file_paths.reserve(len);
1943 file_urls.reserve(len);
1944 std::string file_str;
1945 GURL file_url;
1946 for (size_t i = 0; i < len; ++i) {
1947 path_list->GetString(i, &file_str);
1948 file_url = GURL(file_str);
1949 file_urls.push_back(file_url);
1950 file_paths.push_back(GetVirtualPathFromURL(file_url));
1951 }
1952
1953 for (std::vector<FilePath>::iterator iter = file_paths.begin();
1954 iter != file_paths.end(); ++iter) {
1955 if (!DoOperation(*iter))
1956 break;
1957 }
1958
1959 base::ListValue* file_properties = new base::ListValue;
1960 gdata::GDataFileSystem* file_system =
1961 gdata::GDataFileSystemFactory::GetForProfile(profile_);
1962 DCHECK(file_system);
1963 for (std::vector<FilePath>::size_type i = 0; i < file_paths.size(); ++i) {
1964 scoped_refptr<FilePropertiesDelegate> property_delegate(
1965 new FilePropertiesDelegate());
1966 file_system->FindFileByPath(file_paths[i], property_delegate);
1967 base::DictionaryValue* property_dict = new base::DictionaryValue;
1968 property_delegate->CopyProperties(property_dict);
1969 property_dict->SetString("fileUrl", file_urls[i].spec());
1970 file_properties->Append(property_dict);
1971 }
1972
1973 result_.reset(file_properties);
1974
1975 return true;
1976 }
1977
1978 PinGDataFileFunction::PinGDataFileFunction() {
1979 }
1980
1981 PinGDataFileFunction::~PinGDataFileFunction() {
1982 }
1983
1984 bool PinGDataFileFunction::DoOperation(const FilePath& /*path*/) {
1985 // TODO(gspencer): Actually pin the file here.
1986 return true;
1987 }
1988
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/extensions/file_browser_private_api.h ('k') | chrome/common/extensions/api/fileBrowserPrivate.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698