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