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

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: Added pinning API 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 // Delegate used to find file properties.
391 class FilePropertiesDelegate : public gdata::FindFileDelegate {
392 public:
393 FilePropertiesDelegate();
394 virtual ~FilePropertiesDelegate();
395
396 // Builds a dictionary from the GDataFile file property information
397 void CopyProperties(base::DictionaryValue* property_dict);
398
399 base::PlatformFileError error() const { return error_; }
400
401 private:
402 // GDataFileSystem::FindFileDelegate overrides.
403 virtual void OnFileFound(gdata::GDataFile* file) OVERRIDE;
404 virtual void OnDirectoryFound(const FilePath&,
405 gdata::GDataDirectory* dir) OVERRIDE;
406 virtual FindFileTraversalCommand OnEnterDirectory(
407 const FilePath&,
408 gdata::GDataDirectory*) OVERRIDE;
409 virtual void OnError(base::PlatformFileError error) OVERRIDE;
410
411 GURL thumbnail_url_;
412 GURL edit_url_;
413 int cache_state_;
414 base::PlatformFileError error_;
415 };
416
417 // FilePropertiesDelegate class implementation.
418
419 FilePropertiesDelegate::FilePropertiesDelegate()
420 : cache_state_(0), error_(base::PLATFORM_FILE_OK) {
421 }
422
423 FilePropertiesDelegate::~FilePropertiesDelegate() { }
424
425 void FilePropertiesDelegate::CopyProperties(
426 base::DictionaryValue* property_dict) {
427 DCHECK(property_dict);
428 DCHECK(!property_dict->HasKey("thumbnailUrl"));
429 DCHECK(!property_dict->HasKey("editUrl"));
430 DCHECK(!property_dict->HasKey("isPinned"));
431 DCHECK(!property_dict->HasKey("isPresent"));
432 DCHECK(!property_dict->HasKey("isDirty"));
433 DCHECK(!property_dict->HasKey("errorCode"));
434
435 if (error_ != base::PLATFORM_FILE_OK) {
436 property_dict->SetInteger("errorCode", error_);
437 return;
438 }
439
440 property_dict->SetString("thumbnailUrl", thumbnail_url_.spec());
441 if (!edit_url_.is_empty())
442 property_dict->SetString("editUrl", edit_url_.spec());
443
444 base::FundamentalValue* pinned =
zel 2012/03/02 22:32:11 no need for pinned declaration, just use Dictionar
445 new base::FundamentalValue(static_cast<bool>(cache_state_ &
446 gdata::GDataFile::CACHE_STATE_PINNED));
447 property_dict->Set("isPinned", pinned);
448
449 base::FundamentalValue* present =
zel 2012/03/02 22:32:11 same as above
450 new base::FundamentalValue(static_cast<bool>(cache_state_ &
451 gdata::GDataFile::CACHE_STATE_PRESENT));
452 property_dict->Set("isPresent", present);
453
454 base::FundamentalValue* dirty =
zel 2012/03/02 22:32:11 same as above
455 new base::FundamentalValue(static_cast<bool>(cache_state_ &
456 gdata::GDataFile::CACHE_STATE_DIRTY));
457 property_dict->Set("isDirty", dirty);
458 }
459
460 void FilePropertiesDelegate::OnFileFound(gdata::GDataFile* file) {
461 DCHECK(!file->file_info().is_directory);
462 thumbnail_url_ = file->thumbnail_url();
463 edit_url_ = file->edit_url();
464 cache_state_ = file->cache_state();
465 }
466
467 void FilePropertiesDelegate::OnDirectoryFound(const FilePath&,
468 gdata::GDataDirectory* dir) {
469 DCHECK(dir->file_info().is_directory);
470 // We don't set anything here because we don't have any properties for
471 // directories yet.
472 }
473
474 gdata::FindFileDelegate::FindFileTraversalCommand
475 FilePropertiesDelegate::OnEnterDirectory(const FilePath&,
476 gdata::GDataDirectory*) {
477 // Keep traversing while doing read only lookups.
478 return FIND_FILE_CONTINUES;
479 }
480
481 void FilePropertiesDelegate::OnError(base::PlatformFileError error) {
482 error_ = error;
483 }
484
485 // Given a file url, find the virtual FilePath associated with it.
486 FilePath GetVirtualPathFromURL(const GURL& file_url) {
487 FilePath virtual_path;
488 fileapi::FileSystemType type = fileapi::kFileSystemTypeUnknown;
489 GURL file_origin_url;
490 if (!CrackFileSystemURL(file_url, &file_origin_url, &type, &virtual_path) ||
491 type != fileapi::kFileSystemTypeExternal) {
492 NOTREACHED();
493 return FilePath();
494 }
495 return virtual_path;
496 }
497
498 // Given a list of paths as a ListValue, transform it into two lists of files
499 // in different forms (URL and virtual FilePath).
500 void CollectFilePathsAndUrls(const ListValue* path_list,
501 std::vector<GURL>* file_urls,
502 std::vector<FilePath>* file_paths) {
503 size_t len = path_list->GetSize();
504 file_paths->reserve(len);
505 file_urls->reserve(len);
506 std::string file_str;
507 GURL file_url;
508 for (size_t i = 0; i < len; ++i) {
509 path_list->GetString(i, &file_str);
510 file_url = GURL(file_str);
511 file_urls->push_back(file_url);
512 file_paths->push_back(GetVirtualPathFromURL(file_url));
513 }
514 }
515
516 // Given a list of FilePaths, get the GData attributes for each file,
517 // inserting the given file URL for each one.
518 void CollectFileProperties(const std::vector<GURL>& file_urls,
519 const std::vector<FilePath>& file_paths,
520 gdata::GDataFileSystem* file_system,
521 ListValue* file_properties) {
522 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
523 DCHECK(file_system);
524
525 for (std::vector<FilePath>::size_type i = 0; i < file_paths.size(); ++i) {
526 scoped_refptr<FilePropertiesDelegate> property_delegate(
527 new FilePropertiesDelegate());
528 file_system->FindFileByPath(file_paths[i], property_delegate);
529 base::DictionaryValue* property_dict = new base::DictionaryValue;
530 property_delegate->CopyProperties(property_dict);
531 property_dict->SetString("fileUrl", file_urls[i].spec());
532 file_properties->Append(property_dict);
533 }
534 }
535
390 } // namespace 536 } // namespace
391 537
392 class RequestLocalFileSystemFunction::LocalFileSystemCallbackDispatcher { 538 class RequestLocalFileSystemFunction::LocalFileSystemCallbackDispatcher {
393 public: 539 public:
394 static fileapi::FileSystemContext::OpenFileSystemCallback CreateCallback( 540 static fileapi::FileSystemContext::OpenFileSystemCallback CreateCallback(
395 RequestLocalFileSystemFunction* function, 541 RequestLocalFileSystemFunction* function,
396 Profile* profile, 542 Profile* profile,
397 int child_id, 543 int child_id,
398 scoped_refptr<const Extension> extension) { 544 scoped_refptr<const Extension> extension) {
399 return base::Bind( 545 return base::Bind(
(...skipping 1405 matching lines...) Expand 10 before | Expand all | Expand 10 after
1805 ChromeURLDataManager::DataSource::SetFontAndTextDirection(dict); 1951 ChromeURLDataManager::DataSource::SetFontAndTextDirection(dict);
1806 1952
1807 dict->SetString("PLAY_MEDIA", 1953 dict->SetString("PLAY_MEDIA",
1808 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_PLAY)); 1954 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_PLAY));
1809 1955
1810 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableGData)) 1956 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableGData))
1811 dict->SetString("ENABLE_GDATA", "1"); 1957 dict->SetString("ENABLE_GDATA", "1");
1812 1958
1813 return true; 1959 return true;
1814 } 1960 }
1961
1962 GetGDataFilePropertiesFunction::GetGDataFilePropertiesFunction() {
1963 }
1964
1965 GetGDataFilePropertiesFunction::~GetGDataFilePropertiesFunction() {
1966 }
1967
1968 bool GetGDataFilePropertiesFunction::RunImpl() {
1969 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1970 if (args_->GetSize() != 1)
1971 return false;
1972
1973 ListValue* path_list = NULL;
1974 args_->GetList(0, &path_list);
1975 DCHECK(path_list);
1976 std::vector<GURL> file_urls;
1977 std::vector<FilePath> file_paths;
1978
1979 CollectFilePathsAndUrls(path_list, &file_urls, &file_paths);
1980
1981 base::ListValue* file_properties = new base::ListValue;
1982 gdata::GDataFileSystem* file_system =
1983 gdata::GDataFileSystemFactory::GetForProfile(profile_);
1984 DCHECK(file_system);
1985 CollectFileProperties(file_urls, file_paths, file_system, file_properties);
1986
1987 result_.reset(file_properties);
1988
1989 return true;
1990 }
1991
1992
1993 PinGDataFileFunction::PinGDataFileFunction() {
1994 }
1995
1996 PinGDataFileFunction::~PinGDataFileFunction() {
1997 }
1998
1999 void PinGDataFileFunction::PinFile(const FilePath& path) {
2000 // TODO(gspencer): Actually pin the file here.
2001 }
2002
2003 bool PinGDataFileFunction::RunImpl() {
2004 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2005 if (args_->GetSize() != 1)
2006 return false;
2007
2008 ListValue* path_list = NULL;
2009 args_->GetList(0, &path_list);
2010 DCHECK(path_list);
2011 std::vector<GURL> file_urls;
2012 std::vector<FilePath> file_paths;
2013
2014 CollectFilePathsAndUrls(path_list, &file_urls, &file_paths);
2015
2016 for (std::vector<FilePath>::iterator iter = file_paths.begin();
2017 iter != file_paths.end(); ++iter) {
2018 PinFile(*iter);
2019 }
2020
2021 base::ListValue* file_properties = new base::ListValue;
2022 gdata::GDataFileSystem* file_system =
2023 gdata::GDataFileSystemFactory::GetForProfile(profile_);
2024 DCHECK(file_system);
2025 CollectFileProperties(file_urls, file_paths, file_system, file_properties);
2026 result_.reset(file_properties);
2027
2028 return true;
2029 }
2030
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