1 // Copyright (c) 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.
5 #ifndef CHROME_BROWSER_SYNC_FILE_SYSTEM_FAKE_DRIVE_FILE_SYNC_CLIENT_H_
6 #define CHROME_BROWSER_SYNC_FILE_SYSTEM_FAKE_DRIVE_FILE_SYNC_CLIENT_H_
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_file_sync_client_interface.h"
19 namespace google_apis
{
23 namespace sync_file_system
{
25 class FakeDriveFileSyncClient
26 : public DriveFileSyncClientInterface
{
28 struct RemoteResource
{
29 std::string parent_resource_id
;
30 std::string parent_title
;
32 std::string resource_id
;
33 std::string md5_checksum
;
38 RemoteResource(const std::string
& parent_resource_id
,
39 const std::string
& parent_title
,
40 const std::string
& title
,
41 const std::string
& resource_id
,
42 const std::string
& md5_checksum
,
48 struct RemoteResourceComparator
{
49 // Returns lexicographical order referring all members.
50 bool operator()(const RemoteResource
& left
,
51 const RemoteResource
& right
);
54 typedef std::map
<std::string
, RemoteResource
> RemoteResourceByResourceId
;
56 FakeDriveFileSyncClient();
57 virtual ~FakeDriveFileSyncClient();
59 // DriveFileSyncClientInterface overrides.
60 virtual void AddObserver(DriveFileSyncClientObserver
* observer
) OVERRIDE
;
61 virtual void RemoveObserver(DriveFileSyncClientObserver
* observer
) OVERRIDE
;
62 virtual void GetDriveDirectoryForSyncRoot(
63 const ResourceIdCallback
& callback
) OVERRIDE
;
64 virtual void GetDriveDirectoryForOrigin(
65 const std::string
& sync_root_resource_id
,
67 const ResourceIdCallback
& callback
) OVERRIDE
;
68 virtual void GetLargestChangeStamp(
69 const ChangeStampCallback
& callback
) OVERRIDE
;
70 virtual void GetResourceEntry(
71 const std::string
& resource_id
,
72 const ResourceEntryCallback
& callback
) OVERRIDE
;
73 virtual void ListFiles(
74 const std::string
& directory_resource_id
,
75 const ResourceListCallback
& callback
) OVERRIDE
;
76 virtual void ListChanges(
77 int64 start_changestamp
,
78 const ResourceListCallback
& callback
) OVERRIDE
;
79 virtual void ContinueListing(
81 const ResourceListCallback
& callback
) OVERRIDE
;
82 virtual void DownloadFile(
83 const std::string
& resource_id
,
84 const std::string
& local_file_md5
,
85 const base::FilePath
& local_file_path
,
86 const DownloadFileCallback
& callback
) OVERRIDE
;
87 virtual void UploadNewFile(
88 const std::string
& directory_resource_id
,
89 const base::FilePath
& local_file_path
,
90 const std::string
& title
,
91 const UploadFileCallback
& callback
) OVERRIDE
;
92 virtual void UploadExistingFile(
93 const std::string
& resource_id
,
94 const std::string
& remote_file_md5
,
95 const base::FilePath
& local_file_path
,
96 const UploadFileCallback
& callback
) OVERRIDE
;
97 virtual bool IsAuthenticated() const OVERRIDE
;
98 virtual void DeleteFile(
99 const std::string
& resource_id
,
100 const std::string
& remote_file_md5
,
101 const GDataErrorCallback
& callback
) OVERRIDE
;
102 virtual GURL
ResourceIdToResourceLink(
103 const std::string
& resource_id
) const OVERRIDE
;
104 virtual void EnsureSyncRootIsNotInMyDrive(
105 const std::string
& sync_root_resource_id
) const OVERRIDE
;
107 void PushRemoteChange(const std::string
& parent_resource_id
,
108 const std::string
& parent_title
,
109 const std::string
& title
,
110 const std::string
& resource_id
,
111 const std::string
& md5
,
114 const RemoteResourceByResourceId
& remote_resources() const {
115 return remote_resources_
;
119 struct ChangeStampComparator
;
120 RemoteResourceByResourceId remote_resources_
;
122 scoped_ptr
<google_apis::ResourceEntry
> CreateResourceEntry(
123 const RemoteResource
& resource_id
) const;
125 int64 largest_changestamp_
;
126 google_apis::GDataWapiUrlGenerator url_generator_
;
128 DISALLOW_COPY_AND_ASSIGN(FakeDriveFileSyncClient
);
131 } // namespace sync_file_system
133 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_FAKE_DRIVE_FILE_SYNC_CLIENT_H_