Upstream version 11.40.277.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / extensions / api / sync_file_system / sync_file_system_api.h
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 "storage/browser/fileapi/file_system_url.h"
16 #include "storage/common/quota/quota_types.h"
17
18 namespace storage {
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   ~SyncFileSystemDeleteFileSystemFunction() override {}
34   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   ~SyncFileSystemGetFileStatusFunction() override {}
48   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   ~SyncFileSystemGetFileStatusesFunction() override;
65   bool RunAsync() override;
66
67  private:
68   typedef std::pair<sync_file_system::SyncStatusCode,
69                     sync_file_system::SyncFileStatus> FileStatusPair;
70   typedef std::map<storage::FileSystemURL,
71                    FileStatusPair,
72                    storage::FileSystemURL::Comparator> URLToStatusMap;
73
74   void DidGetFileStatus(const storage::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   ~SyncFileSystemGetUsageAndQuotaFunction() override {}
91   bool RunAsync() override;
92
93  private:
94   void DidGetUsageAndQuota(storage::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   ~SyncFileSystemRequestFileSystemFunction() override {}
107   bool RunAsync() override;
108
109  private:
110   typedef SyncFileSystemRequestFileSystemFunction self;
111
112   // Returns the file system context for this extension.
113   storage::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   ~SyncFileSystemSetConflictResolutionPolicyFunction() override {}
128   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   ~SyncFileSystemGetConflictResolutionPolicyFunction() override {}
139   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   ~SyncFileSystemGetServiceStatusFunction() override {}
150   bool RunSync() override;
151 };
152
153 }  // namespace extensions
154
155 #endif  // CHROME_BROWSER_EXTENSIONS_API_SYNC_FILE_SYSTEM_SYNC_FILE_SYSTEM_API_H_