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 3 // found in the LICENSE file. 4 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_SYNC_FILE_SYSTEM_SYNC_FILE_SYSTEM_API_H_ 6 #define CHROME_BROWSER_EXTENSIONS_API_SYNC_FILE_SYSTEM_SYNC_FILE_SYSTEM_API_H_ 7 8 #include <map> 9 10 #include "base/platform_file.h" 11 #include "chrome/browser/extensions/extension_function.h" 12 #include "chrome/browser/sync_file_system/conflict_resolution_policy.h" 13 #include "chrome/browser/sync_file_system/sync_file_status.h" 14 #include "chrome/browser/sync_file_system/sync_status_code.h" 15 #include "chrome/common/extensions/api/sync_file_system.h" 16 #include "webkit/browser/fileapi/file_system_url.h" 17 #include "webkit/common/quota/quota_types.h" 18 19 namespace fileapi { 20 class FileSystemContext; 21 } 22 23 namespace extensions { 24 25 class SyncFileSystemDeleteFileSystemFunction 26 : public AsyncExtensionFunction { 27 public: 28 // TODO(kinuko,calvinlo): Uncomment this or delete this class when 29 // we decide if we want to revive this function. 30 // DECLARE_EXTENSION_FUNCTION("syncFileSystem.deleteFileSystem", 31 // SYNCFILESYSTEM_DELETEFILESYSTEM) 32 33 protected: 34 virtual ~SyncFileSystemDeleteFileSystemFunction() {} 35 virtual bool RunImpl() OVERRIDE; 36 37 private: 38 void DidDeleteFileSystem(base::PlatformFileError error); 39 }; 40 41 42 class SyncFileSystemGetFileStatusFunction 43 : public AsyncExtensionFunction { 44 public: 45 DECLARE_EXTENSION_FUNCTION("syncFileSystem.getFileStatus", 46 SYNCFILESYSTEM_GETFILESYNCSTATUS) 47 48 protected: 49 virtual ~SyncFileSystemGetFileStatusFunction() {} 50 virtual bool RunImpl() OVERRIDE; 51 52 private: 53 void DidGetFileStatus( 54 const sync_file_system::SyncStatusCode sync_service_status, 55 const sync_file_system::SyncFileStatus sync_file_status); 56 }; 57 58 class SyncFileSystemGetFileStatusesFunction 59 : public AsyncExtensionFunction { 60 public: 61 DECLARE_EXTENSION_FUNCTION("syncFileSystem.getFileStatuses", 62 SYNCFILESYSTEM_GETFILESYNCSTATUSES) 63 SyncFileSystemGetFileStatusesFunction(); 64 65 protected: 66 virtual ~SyncFileSystemGetFileStatusesFunction(); 67 virtual bool RunImpl() OVERRIDE; 68 69 private: 70 typedef std::pair<sync_file_system::SyncStatusCode, 71 sync_file_system::SyncFileStatus> FileStatusPair; 72 typedef std::map<fileapi::FileSystemURL, FileStatusPair, 73 fileapi::FileSystemURL::Comparator> URLToStatusMap; 74 75 void DidGetFileStatus( 76 const fileapi::FileSystemURL& file_system_url, 77 sync_file_system::SyncStatusCode sync_status_code, 78 sync_file_system::SyncFileStatus sync_file_statuses); 79 80 unsigned int num_expected_results_; 81 unsigned int num_results_received_; 82 URLToStatusMap file_sync_statuses_; 83 }; 84 85 class SyncFileSystemGetUsageAndQuotaFunction 86 : public AsyncExtensionFunction { 87 public: 88 DECLARE_EXTENSION_FUNCTION("syncFileSystem.getUsageAndQuota", 89 SYNCFILESYSTEM_GETUSAGEANDQUOTA) 90 91 protected: 92 virtual ~SyncFileSystemGetUsageAndQuotaFunction() {} 93 virtual bool RunImpl() OVERRIDE; 94 95 private: 96 void DidGetUsageAndQuota(quota::QuotaStatusCode status, 97 int64 usage, 98 int64 quota); 99 }; 100 101 class SyncFileSystemRequestFileSystemFunction 102 : public AsyncExtensionFunction { 103 public: 104 DECLARE_EXTENSION_FUNCTION("syncFileSystem.requestFileSystem", 105 SYNCFILESYSTEM_REQUESTFILESYSTEM) 106 107 protected: 108 virtual ~SyncFileSystemRequestFileSystemFunction() {} 109 virtual bool RunImpl() OVERRIDE; 110 111 private: 112 typedef SyncFileSystemRequestFileSystemFunction self; 113 114 // Returns the file system context for this extension. 115 fileapi::FileSystemContext* GetFileSystemContext(); 116 117 void DidInitializeFileSystemContext(sync_file_system::SyncStatusCode status); 118 void DidOpenFileSystem(base::PlatformFileError error, 119 const std::string& file_system_name, 120 const GURL& root_url); 121 }; 122 123 class SyncFileSystemSetConflictResolutionPolicyFunction 124 : public SyncExtensionFunction { 125 public: 126 DECLARE_EXTENSION_FUNCTION("syncFileSystem.setConflictResolutionPolicy", 127 SYNCFILESYSTEM_SETCONFLICTRESOLUTIONPOLICY) 128 129 protected: 130 virtual ~SyncFileSystemSetConflictResolutionPolicyFunction() {} 131 virtual bool RunImpl() OVERRIDE; 132 }; 133 134 class SyncFileSystemGetConflictResolutionPolicyFunction 135 : public SyncExtensionFunction { 136 public: 137 DECLARE_EXTENSION_FUNCTION("syncFileSystem.getConflictResolutionPolicy", 138 SYNCFILESYSTEM_GETCONFLICTRESOLUTIONPOLICY) 139 140 protected: 141 virtual ~SyncFileSystemGetConflictResolutionPolicyFunction() {} 142 virtual bool RunImpl() OVERRIDE; 143 }; 144 145 } // namespace extensions 146 147 #endif // CHROME_BROWSER_EXTENSIONS_API_SYNC_FILE_SYSTEM_SYNC_FILE_SYSTEM_API_H_ 148