| 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 #ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_BROWSER_PRIVATE_API_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_BROWSER_PRIVATE_API_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_BROWSER_PRIVATE_API_H_ | 6 #define CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_BROWSER_PRIVATE_API_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <queue> | 10 #include <queue> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/platform_file.h" | 15 #include "base/platform_file.h" |
| 16 #include "chrome/browser/chromeos/extensions/file_browser_event_router.h" | 16 #include "chrome/browser/chromeos/extensions/file_browser_event_router.h" |
| 17 #include "chrome/browser/chromeos/gdata/drive_cache.h" | 17 #include "chrome/browser/chromeos/gdata/drive_cache.h" |
| 18 #include "chrome/browser/chromeos/gdata/gdata_errorcode.h" | 18 #include "chrome/browser/chromeos/gdata/drive_errorcode.h" |
| 19 #include "chrome/browser/extensions/extension_function.h" | 19 #include "chrome/browser/extensions/extension_function.h" |
| 20 #include "chrome/browser/prefs/pref_service.h" | 20 #include "chrome/browser/prefs/pref_service.h" |
| 21 #include "googleurl/src/url_util.h" | 21 #include "googleurl/src/url_util.h" |
| 22 | 22 |
| 23 class GURL; | 23 class GURL; |
| 24 | 24 |
| 25 namespace fileapi { | 25 namespace fileapi { |
| 26 class FileSystemContext; | 26 class FileSystemContext; |
| 27 } | 27 } |
| 28 | 28 |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 virtual bool RunImpl() OVERRIDE; | 275 virtual bool RunImpl() OVERRIDE; |
| 276 | 276 |
| 277 private: | 277 private: |
| 278 // A callback method to handle the result of | 278 // A callback method to handle the result of |
| 279 // GetLocalPathsOnFileThreadAndRunCallbackOnUIThread. | 279 // GetLocalPathsOnFileThreadAndRunCallbackOnUIThread. |
| 280 void GetLocalPathsResponseOnUIThread(const std::string& mount_type_str, | 280 void GetLocalPathsResponseOnUIThread(const std::string& mount_type_str, |
| 281 const SelectedFileInfoList& files); | 281 const SelectedFileInfoList& files); |
| 282 // A callback method to handle the result of SetMountedState. | 282 // A callback method to handle the result of SetMountedState. |
| 283 void OnMountedStateSet(const std::string& mount_type, | 283 void OnMountedStateSet(const std::string& mount_type, |
| 284 const FilePath::StringType& file_name, | 284 const FilePath::StringType& file_name, |
| 285 gdata::GDataFileError error, | 285 gdata::DriveFileError error, |
| 286 const FilePath& file_path); | 286 const FilePath& file_path); |
| 287 }; | 287 }; |
| 288 | 288 |
| 289 // Unmounts selected device. Expects mount point path as an argument. | 289 // Unmounts selected device. Expects mount point path as an argument. |
| 290 class RemoveMountFunction : public FileBrowserFunction { | 290 class RemoveMountFunction : public FileBrowserFunction { |
| 291 public: | 291 public: |
| 292 DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.removeMount"); | 292 DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.removeMount"); |
| 293 | 293 |
| 294 RemoveMountFunction(); | 294 RemoveMountFunction(); |
| 295 | 295 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 virtual ~GetSizeStatsFunction(); | 347 virtual ~GetSizeStatsFunction(); |
| 348 | 348 |
| 349 // AsyncExtensionFunction overrides. | 349 // AsyncExtensionFunction overrides. |
| 350 virtual bool RunImpl() OVERRIDE; | 350 virtual bool RunImpl() OVERRIDE; |
| 351 | 351 |
| 352 private: | 352 private: |
| 353 // A callback method to handle the result of | 353 // A callback method to handle the result of |
| 354 // GetLocalPathsOnFileThreadAndRunCallbackOnUIThread. | 354 // GetLocalPathsOnFileThreadAndRunCallbackOnUIThread. |
| 355 void GetLocalPathsResponseOnUIThread(const SelectedFileInfoList& files); | 355 void GetLocalPathsResponseOnUIThread(const SelectedFileInfoList& files); |
| 356 | 356 |
| 357 void GetGDataAvailableSpaceCallback(gdata::GDataFileError error, | 357 void GetGDataAvailableSpaceCallback(gdata::DriveFileError error, |
| 358 int64 bytes_total, | 358 int64 bytes_total, |
| 359 int64 bytes_used); | 359 int64 bytes_used); |
| 360 | 360 |
| 361 void GetSizeStatsCallbackOnUIThread(size_t total_size_kb, | 361 void GetSizeStatsCallbackOnUIThread(size_t total_size_kb, |
| 362 size_t remaining_size_kb); | 362 size_t remaining_size_kb); |
| 363 void CallGetSizeStatsOnFileThread(const std::string& mount_path); | 363 void CallGetSizeStatsOnFileThread(const std::string& mount_path); |
| 364 }; | 364 }; |
| 365 | 365 |
| 366 // Retrieves devices meta-data. Expects volume's device path as an argument. | 366 // Retrieves devices meta-data. Expects volume's device path as an argument. |
| 367 class GetVolumeMetadataFunction : public FileBrowserFunction { | 367 class GetVolumeMetadataFunction : public FileBrowserFunction { |
| 368 public: | 368 public: |
| 369 DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.getVolumeMetadata"); | 369 DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.getVolumeMetadata"); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 protected: | 416 protected: |
| 417 virtual ~FileDialogStringsFunction() {} | 417 virtual ~FileDialogStringsFunction() {} |
| 418 | 418 |
| 419 // SyncExtensionFunction overrides. | 419 // SyncExtensionFunction overrides. |
| 420 virtual bool RunImpl() OVERRIDE; | 420 virtual bool RunImpl() OVERRIDE; |
| 421 }; | 421 }; |
| 422 | 422 |
| 423 // Retrieve property information for multiple files, returning a list of the | 423 // Retrieve property information for multiple files, returning a list of the |
| 424 // same length as the input list of file URLs. If a particular file has an | 424 // same length as the input list of file URLs. If a particular file has an |
| 425 // error, then return a dictionary with the key "error" set to the error number | 425 // error, then return a dictionary with the key "error" set to the error number |
| 426 // (gdata::GDataFileError) for that entry in the returned list. | 426 // (gdata::DriveFileError) for that entry in the returned list. |
| 427 class GetGDataFilePropertiesFunction : public FileBrowserFunction { | 427 class GetGDataFilePropertiesFunction : public FileBrowserFunction { |
| 428 public: | 428 public: |
| 429 DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.getGDataFileProperties"); | 429 DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.getGDataFileProperties"); |
| 430 | 430 |
| 431 GetGDataFilePropertiesFunction(); | 431 GetGDataFilePropertiesFunction(); |
| 432 | 432 |
| 433 protected: | 433 protected: |
| 434 virtual ~GetGDataFilePropertiesFunction(); | 434 virtual ~GetGDataFilePropertiesFunction(); |
| 435 | 435 |
| 436 void GetNextFileProperties(); | 436 void GetNextFileProperties(); |
| 437 void CompleteGetFileProperties(); | 437 void CompleteGetFileProperties(); |
| 438 | 438 |
| 439 // Virtual function that can be overridden to do operations on each virtual | 439 // Virtual function that can be overridden to do operations on each virtual |
| 440 // file path and update its the properties. | 440 // file path and update its the properties. |
| 441 virtual void DoOperation(const FilePath& file_path, | 441 virtual void DoOperation(const FilePath& file_path, |
| 442 base::DictionaryValue* properties, | 442 base::DictionaryValue* properties, |
| 443 scoped_ptr<gdata::DriveEntryProto> entry_proto); | 443 scoped_ptr<gdata::DriveEntryProto> entry_proto); |
| 444 | 444 |
| 445 void OnOperationComplete(const FilePath& file_path, | 445 void OnOperationComplete(const FilePath& file_path, |
| 446 base::DictionaryValue* properties, | 446 base::DictionaryValue* properties, |
| 447 gdata::GDataFileError error, | 447 gdata::DriveFileError error, |
| 448 scoped_ptr<gdata::DriveEntryProto> entry_proto); | 448 scoped_ptr<gdata::DriveEntryProto> entry_proto); |
| 449 | 449 |
| 450 // AsyncExtensionFunction overrides. | 450 // AsyncExtensionFunction overrides. |
| 451 virtual bool RunImpl() OVERRIDE; | 451 virtual bool RunImpl() OVERRIDE; |
| 452 | 452 |
| 453 // Builds list of file properies. Calls DoOperation for each file. | 453 // Builds list of file properies. Calls DoOperation for each file. |
| 454 void PrepareResults(); | 454 void PrepareResults(); |
| 455 | 455 |
| 456 private: | 456 private: |
| 457 void OnGetFileInfo(const FilePath& file_path, | 457 void OnGetFileInfo(const FilePath& file_path, |
| 458 base::DictionaryValue* property_dict, | 458 base::DictionaryValue* property_dict, |
| 459 gdata::GDataFileError error, | 459 gdata::DriveFileError error, |
| 460 scoped_ptr<gdata::DriveEntryProto> entry_proto); | 460 scoped_ptr<gdata::DriveEntryProto> entry_proto); |
| 461 | 461 |
| 462 void CacheStateReceived(base::DictionaryValue* property_dict, | 462 void CacheStateReceived(base::DictionaryValue* property_dict, |
| 463 bool success, | 463 bool success, |
| 464 const gdata::DriveCacheEntry& cache_entry); | 464 const gdata::DriveCacheEntry& cache_entry); |
| 465 | 465 |
| 466 size_t current_index_; | 466 size_t current_index_; |
| 467 base::ListValue* path_list_; | 467 base::ListValue* path_list_; |
| 468 scoped_ptr<base::ListValue> file_properties_; | 468 scoped_ptr<base::ListValue> file_properties_; |
| 469 }; | 469 }; |
| 470 | 470 |
| 471 // Pin/unpin multiple files in the cache, returning a list of file | 471 // Pin/unpin multiple files in the cache, returning a list of file |
| 472 // properties with the updated cache state. The returned array is the | 472 // properties with the updated cache state. The returned array is the |
| 473 // same length as the input list of file URLs. If a particular file | 473 // same length as the input list of file URLs. If a particular file |
| 474 // has an error, then return a dictionary with the key "error" set to | 474 // has an error, then return a dictionary with the key "error" set to |
| 475 // the error number (gdata::GDataFileError) for that entry in the | 475 // the error number (gdata::DriveFileError) for that entry in the |
| 476 // returned list. | 476 // returned list. |
| 477 class PinGDataFileFunction : public GetGDataFilePropertiesFunction { | 477 class PinGDataFileFunction : public GetGDataFilePropertiesFunction { |
| 478 public: | 478 public: |
| 479 DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.pinGDataFile"); | 479 DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.pinGDataFile"); |
| 480 | 480 |
| 481 PinGDataFileFunction(); | 481 PinGDataFileFunction(); |
| 482 | 482 |
| 483 protected: | 483 protected: |
| 484 virtual ~PinGDataFileFunction(); | 484 virtual ~PinGDataFileFunction(); |
| 485 | 485 |
| 486 // AsyncExtensionFunction overrides. | 486 // AsyncExtensionFunction overrides. |
| 487 virtual bool RunImpl() OVERRIDE; | 487 virtual bool RunImpl() OVERRIDE; |
| 488 | 488 |
| 489 private: | 489 private: |
| 490 // Actually do the pinning/unpinning of each file. | 490 // Actually do the pinning/unpinning of each file. |
| 491 virtual void DoOperation( | 491 virtual void DoOperation( |
| 492 const FilePath& file_path, | 492 const FilePath& file_path, |
| 493 base::DictionaryValue* properties, | 493 base::DictionaryValue* properties, |
| 494 scoped_ptr<gdata::DriveEntryProto> entry_proto) OVERRIDE; | 494 scoped_ptr<gdata::DriveEntryProto> entry_proto) OVERRIDE; |
| 495 | 495 |
| 496 // Callback for SetPinState. Updates properties with error. | 496 // Callback for SetPinState. Updates properties with error. |
| 497 void OnPinStateSet(const FilePath& path, | 497 void OnPinStateSet(const FilePath& path, |
| 498 base::DictionaryValue* properties, | 498 base::DictionaryValue* properties, |
| 499 scoped_ptr<gdata::DriveEntryProto> entry_proto, | 499 scoped_ptr<gdata::DriveEntryProto> entry_proto, |
| 500 gdata::GDataFileError error, | 500 gdata::DriveFileError error, |
| 501 const std::string& resource_id, | 501 const std::string& resource_id, |
| 502 const std::string& md5); | 502 const std::string& md5); |
| 503 | 503 |
| 504 // True for pin, false for unpin. | 504 // True for pin, false for unpin. |
| 505 bool set_pin_; | 505 bool set_pin_; |
| 506 }; | 506 }; |
| 507 | 507 |
| 508 // Get file locations for the given list of file URLs. Returns a list of | 508 // Get file locations for the given list of file URLs. Returns a list of |
| 509 // location idenfitiers, like ['drive', 'local'], where 'drive' means the | 509 // location idenfitiers, like ['drive', 'local'], where 'drive' means the |
| 510 // file is on gdata, and 'local' means the file is on the local drive. | 510 // file is on gdata, and 'local' means the file is on the local drive. |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 550 // A callback method to handle the result of | 550 // A callback method to handle the result of |
| 551 // GetLocalPathsOnFileThreadAndRunCallbackOnUIThread. | 551 // GetLocalPathsOnFileThreadAndRunCallbackOnUIThread. |
| 552 void GetLocalPathsResponseOnUIThread(const SelectedFileInfoList& files); | 552 void GetLocalPathsResponseOnUIThread(const SelectedFileInfoList& files); |
| 553 | 553 |
| 554 // Gets the file on the top of the |remaining_gdata_paths_| or sends the | 554 // Gets the file on the top of the |remaining_gdata_paths_| or sends the |
| 555 // response if the queue is empty. | 555 // response if the queue is empty. |
| 556 void GetFileOrSendResponse(); | 556 void GetFileOrSendResponse(); |
| 557 | 557 |
| 558 // Called by GDataFileSystem::GetFile(). Pops the file from | 558 // Called by GDataFileSystem::GetFile(). Pops the file from |
| 559 // |remaining_gdata_paths_|, and calls GetFileOrSendResponse(). | 559 // |remaining_gdata_paths_|, and calls GetFileOrSendResponse(). |
| 560 void OnFileReady(gdata::GDataFileError error, | 560 void OnFileReady(gdata::DriveFileError error, |
| 561 const FilePath& local_path, | 561 const FilePath& local_path, |
| 562 const std::string& unused_mime_type, | 562 const std::string& unused_mime_type, |
| 563 gdata::DriveFileType file_type); | 563 gdata::DriveFileType file_type); |
| 564 | 564 |
| 565 std::queue<FilePath> remaining_gdata_paths_; | 565 std::queue<FilePath> remaining_gdata_paths_; |
| 566 ListValue* local_paths_; | 566 ListValue* local_paths_; |
| 567 }; | 567 }; |
| 568 | 568 |
| 569 // Implements the chrome.fileBrowserPrivate.executeTask method. | 569 // Implements the chrome.fileBrowserPrivate.executeTask method. |
| 570 class GetFileTransfersFunction : public AsyncExtensionFunction { | 570 class GetFileTransfersFunction : public AsyncExtensionFunction { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 611 | 611 |
| 612 // AsyncExtensionFunction overrides. | 612 // AsyncExtensionFunction overrides. |
| 613 virtual bool RunImpl() OVERRIDE; | 613 virtual bool RunImpl() OVERRIDE; |
| 614 | 614 |
| 615 private: | 615 private: |
| 616 // Helper callback for handling response from | 616 // Helper callback for handling response from |
| 617 // GetLocalPathsOnFileThreadAndRunCallbackOnUIThread() | 617 // GetLocalPathsOnFileThreadAndRunCallbackOnUIThread() |
| 618 void GetLocalPathsResponseOnUIThread(const SelectedFileInfoList& files); | 618 void GetLocalPathsResponseOnUIThread(const SelectedFileInfoList& files); |
| 619 | 619 |
| 620 // Helper callback for handling response from GDataFileSystem::TransferFile(). | 620 // Helper callback for handling response from GDataFileSystem::TransferFile(). |
| 621 void OnTransferCompleted(gdata::GDataFileError error); | 621 void OnTransferCompleted(gdata::DriveFileError error); |
| 622 }; | 622 }; |
| 623 | 623 |
| 624 // Read setting value. | 624 // Read setting value. |
| 625 class GetGDataPreferencesFunction : public SyncExtensionFunction { | 625 class GetGDataPreferencesFunction : public SyncExtensionFunction { |
| 626 public: | 626 public: |
| 627 DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.getGDataPreferences"); | 627 DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.getGDataPreferences"); |
| 628 | 628 |
| 629 protected: | 629 protected: |
| 630 virtual ~GetGDataPreferencesFunction() {} | 630 virtual ~GetGDataPreferencesFunction() {} |
| 631 | 631 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 653 virtual ~SearchDriveFunction(); | 653 virtual ~SearchDriveFunction(); |
| 654 | 654 |
| 655 virtual bool RunImpl() OVERRIDE; | 655 virtual bool RunImpl() OVERRIDE; |
| 656 | 656 |
| 657 private: | 657 private: |
| 658 // Callback fo OpenFileSystem called from RunImpl. | 658 // Callback fo OpenFileSystem called from RunImpl. |
| 659 void OnFileSystemOpened(base::PlatformFileError result, | 659 void OnFileSystemOpened(base::PlatformFileError result, |
| 660 const std::string& file_system_name, | 660 const std::string& file_system_name, |
| 661 const GURL& file_system_url); | 661 const GURL& file_system_url); |
| 662 // Callback for gdata::SearchAsync called after file system is opened. | 662 // Callback for gdata::SearchAsync called after file system is opened. |
| 663 void OnSearch(gdata::GDataFileError error, | 663 void OnSearch(gdata::DriveFileError error, |
| 664 const GURL& next_feed, | 664 const GURL& next_feed, |
| 665 scoped_ptr<std::vector<gdata::SearchResultInfo> > result_paths); | 665 scoped_ptr<std::vector<gdata::SearchResultInfo> > result_paths); |
| 666 | 666 |
| 667 // Query for which the search is being performed. | 667 // Query for which the search is being performed. |
| 668 std::string query_; | 668 std::string query_; |
| 669 std::string next_feed_; | 669 std::string next_feed_; |
| 670 // Information about remote file system we will need to create file entries | 670 // Information about remote file system we will need to create file entries |
| 671 // to represent search results. | 671 // to represent search results. |
| 672 std::string file_system_name_; | 672 std::string file_system_name_; |
| 673 GURL file_system_url_; | 673 GURL file_system_url_; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 701 DECLARE_EXTENSION_FUNCTION_NAME( | 701 DECLARE_EXTENSION_FUNCTION_NAME( |
| 702 "fileBrowserPrivate.requestDirectoryRefresh"); | 702 "fileBrowserPrivate.requestDirectoryRefresh"); |
| 703 | 703 |
| 704 protected: | 704 protected: |
| 705 virtual ~RequestDirectoryRefreshFunction() {} | 705 virtual ~RequestDirectoryRefreshFunction() {} |
| 706 | 706 |
| 707 virtual bool RunImpl() OVERRIDE; | 707 virtual bool RunImpl() OVERRIDE; |
| 708 }; | 708 }; |
| 709 | 709 |
| 710 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_BROWSER_PRIVATE_API_H_ | 710 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_BROWSER_PRIVATE_API_H_ |
| OLD | NEW |