fake_drive_service_helper.h revision eb525c5499e34cc9c4b825d6d9e75bb07cc06ace
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_DRIVE_SERVICE_HELPER_H_
6#define CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_FAKE_DRIVE_SERVICE_HELPER_H_
7
8#include <string>
9
10#include "base/files/scoped_temp_dir.h"
11#include "chrome/browser/drive/drive_uploader.h"
12#include "chrome/browser/drive/fake_drive_service.h"
13#include "chrome/browser/google_apis/gdata_wapi_parser.h"
14
15namespace base {
16class FilePath;
17}
18
19namespace sync_file_system {
20namespace drive_backend {
21
22class FakeDriveServiceHelper {
23 public:
24  FakeDriveServiceHelper(drive::FakeDriveService* fake_drive_service,
25                         drive::DriveUploaderInterface* drive_uploader);
26  virtual ~FakeDriveServiceHelper();
27
28  google_apis::GDataErrorCode AddOrphanedFolder(
29      const std::string& title,
30      std::string* folder_id);
31  google_apis::GDataErrorCode AddFolder(
32      const std::string& parent_folder_id,
33      const std::string& title,
34      std::string* folder_id);
35  google_apis::GDataErrorCode AddFile(
36      const std::string& parent_folder_id,
37      const std::string& title,
38      const std::string& content,
39      std::string* file_id);
40  google_apis::GDataErrorCode UpdateFile(
41      const std::string& file_id,
42      const std::string& content);
43  google_apis::GDataErrorCode RemoveResource(
44      const std::string& file_id);
45  google_apis::GDataErrorCode GetSyncRootFolderID(
46      std::string* sync_root_folder_id);
47  google_apis::GDataErrorCode ListFilesInFolder(
48      const std::string& folder_id,
49      ScopedVector<google_apis::ResourceEntry>* entries);
50  google_apis::GDataErrorCode SearchByTitle(
51      const std::string& folder_id,
52      const std::string& title,
53      ScopedVector<google_apis::ResourceEntry>* entries);
54  google_apis::GDataErrorCode GetResourceEntry(
55      const std::string& file_id,
56      scoped_ptr<google_apis::ResourceEntry>* entry);
57  google_apis::GDataErrorCode ReadFile(
58      const std::string& file_id,
59      std::string* file_content);
60
61  base::FilePath base_dir_path() { return base_dir_.path(); }
62
63 private:
64  google_apis::GDataErrorCode CompleteListing(
65      scoped_ptr<google_apis::ResourceList> list,
66      ScopedVector<google_apis::ResourceEntry> * entries);
67
68  void Initialize();
69
70  base::FilePath WriteToTempFile(const std::string& content);
71  void FlushMessageLoop();
72
73  base::ScopedTempDir base_dir_;
74  base::FilePath temp_dir_;
75
76  // Not own.
77  drive::FakeDriveService* fake_drive_service_;
78  drive::DriveUploaderInterface* drive_uploader_;
79};
80
81}  // namespace drive_backend
82}  // namespace sync_file_system
83
84#endif  // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_FAKE_DRIVE_SERVICE_HELPER_H_
85