OLD | NEW |
| (Empty) |
1 // Copyright 2013 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_SYNC_FILE_SYSTEM_DRIVE_BACKEND_FAKE_API_UTIL_H_ | |
6 #define CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_FAKE_API_UTIL_H_ | |
7 | |
8 #include <map> | |
9 #include <string> | |
10 | |
11 #include "chrome/browser/google_apis/drive_api_parser.h" | |
12 #include "chrome/browser/google_apis/gdata_wapi_parser.h" | |
13 #include "chrome/browser/google_apis/gdata_wapi_url_generator.h" | |
14 #include "chrome/browser/sync_file_system/drive_backend/api_util_interface.h" | |
15 #include "chrome/browser/sync_file_system/sync_file_type.h" | |
16 | |
17 class GURL; | |
18 class Profile; | |
19 | |
20 namespace google_apis { | |
21 class ResourceEntry; | |
22 } | |
23 | |
24 namespace sync_file_system { | |
25 namespace drive_backend { | |
26 | |
27 class FakeAPIUtil : public APIUtilInterface { | |
28 public: | |
29 struct RemoteResource { | |
30 std::string parent_resource_id; | |
31 std::string parent_title; | |
32 std::string title; | |
33 std::string resource_id; | |
34 std::string md5_checksum; | |
35 SyncFileType type; | |
36 bool deleted; | |
37 int64 changestamp; | |
38 | |
39 RemoteResource(); | |
40 RemoteResource(const std::string& parent_resource_id, | |
41 const std::string& parent_title, | |
42 const std::string& title, | |
43 const std::string& resource_id, | |
44 const std::string& md5_checksum, | |
45 SyncFileType type, | |
46 bool deleted, | |
47 int64 changestamp); | |
48 ~RemoteResource(); | |
49 }; | |
50 | |
51 struct RemoteResourceComparator { | |
52 // Returns lexicographical order referring all members. | |
53 bool operator()(const RemoteResource& left, const RemoteResource& right); | |
54 }; | |
55 | |
56 typedef std::map<std::string, RemoteResource> RemoteResourceByResourceId; | |
57 | |
58 FakeAPIUtil(); | |
59 virtual ~FakeAPIUtil(); | |
60 | |
61 // APIUtilInterface overrides. | |
62 virtual void AddObserver(APIUtilObserver* observer) OVERRIDE; | |
63 virtual void RemoveObserver(APIUtilObserver* observer) OVERRIDE; | |
64 virtual void GetDriveDirectoryForSyncRoot( | |
65 const ResourceIdCallback& callback) OVERRIDE; | |
66 virtual void GetDriveDirectoryForOrigin( | |
67 const std::string& sync_root_resource_id, | |
68 const GURL& origin, | |
69 const ResourceIdCallback& callback) OVERRIDE; | |
70 virtual void GetLargestChangeStamp( | |
71 const ChangeStampCallback& callback) OVERRIDE; | |
72 virtual void GetResourceEntry(const std::string& resource_id, | |
73 const ResourceEntryCallback& callback) OVERRIDE; | |
74 virtual void ListFiles(const std::string& directory_resource_id, | |
75 const ResourceListCallback& callback) OVERRIDE; | |
76 virtual void ListChanges(int64 start_changestamp, | |
77 const ResourceListCallback& callback) OVERRIDE; | |
78 virtual void ContinueListing(const GURL& next_link, | |
79 const ResourceListCallback& callback) OVERRIDE; | |
80 virtual void DownloadFile(const std::string& resource_id, | |
81 const std::string& local_file_md5, | |
82 const DownloadFileCallback& callback) OVERRIDE; | |
83 virtual void UploadNewFile(const std::string& directory_resource_id, | |
84 const base::FilePath& local_file_path, | |
85 const std::string& title, | |
86 const UploadFileCallback& callback) OVERRIDE; | |
87 virtual void UploadExistingFile(const std::string& resource_id, | |
88 const std::string& remote_file_md5, | |
89 const base::FilePath& local_file_path, | |
90 const UploadFileCallback& callback) OVERRIDE; | |
91 virtual void CreateDirectory(const std::string& parent_resource_id, | |
92 const std::string& title, | |
93 const ResourceIdCallback& callback) OVERRIDE; | |
94 virtual bool IsAuthenticated() const OVERRIDE; | |
95 virtual void DeleteFile(const std::string& resource_id, | |
96 const std::string& remote_file_md5, | |
97 const GDataErrorCallback& callback) OVERRIDE; | |
98 virtual GURL ResourceIdToResourceLink( | |
99 const std::string& resource_id) const OVERRIDE; | |
100 virtual void EnsureSyncRootIsNotInMyDrive( | |
101 const std::string& sync_root_resource_id) OVERRIDE; | |
102 | |
103 void PushRemoteChange(const std::string& parent_resource_id, | |
104 const std::string& parent_title, | |
105 const std::string& title, | |
106 const std::string& resource_id, | |
107 const std::string& md5, | |
108 SyncFileType type, | |
109 bool deleted); | |
110 | |
111 const RemoteResourceByResourceId& remote_resources() const { | |
112 return remote_resources_; | |
113 } | |
114 | |
115 private: | |
116 struct ChangeStampComparator; | |
117 RemoteResourceByResourceId remote_resources_; | |
118 | |
119 scoped_ptr<google_apis::ResourceEntry> CreateResourceEntry( | |
120 const RemoteResource& resource_id) const; | |
121 | |
122 int64 largest_changestamp_; | |
123 google_apis::GDataWapiUrlGenerator url_generator_; | |
124 | |
125 DISALLOW_COPY_AND_ASSIGN(FakeAPIUtil); | |
126 }; | |
127 | |
128 } // namespace drive_backend | |
129 } // namespace sync_file_system | |
130 | |
131 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_FAKE_API_UTIL_H_ | |
OLD | NEW |