Home | History | Annotate | Download | only in drive_backend
      1 // Copyright 2014 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_DRIVE_SERVICE_ON_WORKER_H_
      6 #define CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_DRIVE_SERVICE_ON_WORKER_H_
      7 
      8 #include "base/memory/ref_counted.h"
      9 #include "base/memory/weak_ptr.h"
     10 #include "base/sequence_checker.h"
     11 #include "chrome/browser/drive/drive_service_interface.h"
     12 
     13 namespace base {
     14 class SingleThreadTaskRunner;
     15 class SequencedTaskRunner;
     16 }
     17 
     18 namespace sync_file_system {
     19 namespace drive_backend {
     20 
     21 class DriveServiceWrapper;
     22 
     23 // This class wraps a part of DriveServiceInterface class to post actual
     24 // tasks to DriveServiceWrapper which lives in another thread.
     25 // Each method wraps corresponding name method of DriveServiceInterface.
     26 // See comments in drive_service_interface.h for details.
     27 class DriveServiceOnWorker : public drive::DriveServiceInterface {
     28  public:
     29   DriveServiceOnWorker(
     30       const base::WeakPtr<DriveServiceWrapper>& wrapper,
     31       base::SingleThreadTaskRunner* ui_task_runner,
     32       base::SequencedTaskRunner* worker_task_runner);
     33   virtual ~DriveServiceOnWorker();
     34 
     35   virtual google_apis::CancelCallback AddNewDirectory(
     36       const std::string& parent_resource_id,
     37       const std::string& directory_title,
     38       const AddNewDirectoryOptions& options,
     39       const google_apis::FileResourceCallback& callback) OVERRIDE;
     40 
     41   virtual google_apis::CancelCallback DeleteResource(
     42       const std::string& resource_id,
     43       const std::string& etag,
     44       const google_apis::EntryActionCallback& callback) OVERRIDE;
     45 
     46   virtual google_apis::CancelCallback DownloadFile(
     47       const base::FilePath& local_cache_path,
     48       const std::string& resource_id,
     49       const google_apis::DownloadActionCallback& download_action_callback,
     50       const google_apis::GetContentCallback& get_content_callback,
     51       const google_apis::ProgressCallback& progress_callback) OVERRIDE;
     52 
     53   virtual google_apis::CancelCallback GetAboutResource(
     54       const google_apis::AboutResourceCallback& callback) OVERRIDE;
     55 
     56   virtual google_apis::CancelCallback GetChangeList(
     57       int64 start_changestamp,
     58       const google_apis::ChangeListCallback& callback) OVERRIDE;
     59 
     60   virtual google_apis::CancelCallback GetRemainingChangeList(
     61       const GURL& next_link,
     62       const google_apis::ChangeListCallback& callback) OVERRIDE;
     63 
     64   virtual std::string GetRootResourceId() const OVERRIDE;
     65 
     66   virtual google_apis::CancelCallback GetRemainingFileList(
     67       const GURL& next_link,
     68       const google_apis::FileListCallback& callback) OVERRIDE;
     69 
     70   virtual google_apis::CancelCallback GetFileResource(
     71       const std::string& resource_id,
     72       const google_apis::FileResourceCallback& callback) OVERRIDE;
     73 
     74   virtual google_apis::CancelCallback GetFileListInDirectory(
     75       const std::string& directory_resource_id,
     76       const google_apis::FileListCallback& callback) OVERRIDE;
     77 
     78   virtual google_apis::CancelCallback RemoveResourceFromDirectory(
     79       const std::string& parent_resource_id,
     80       const std::string& resource_id,
     81       const google_apis::EntryActionCallback& callback) OVERRIDE;
     82 
     83   virtual google_apis::CancelCallback SearchByTitle(
     84       const std::string& title,
     85       const std::string& directory_resource_id,
     86       const google_apis::FileListCallback& callback) OVERRIDE;
     87 
     88   virtual bool HasRefreshToken() const OVERRIDE;
     89 
     90   // Following virtual methods are expected not to be accessed at all.
     91   virtual void Initialize(const std::string& account_id) OVERRIDE;
     92   virtual void AddObserver(drive::DriveServiceObserver* observer) OVERRIDE;
     93   virtual void RemoveObserver(drive::DriveServiceObserver* observer) OVERRIDE;
     94   virtual bool CanSendRequest() const OVERRIDE;
     95   virtual drive::ResourceIdCanonicalizer GetResourceIdCanonicalizer()
     96       const OVERRIDE;
     97   virtual bool HasAccessToken() const OVERRIDE;
     98   virtual void RequestAccessToken(
     99       const google_apis::AuthStatusCallback& callback) OVERRIDE;
    100   virtual void ClearAccessToken() OVERRIDE;
    101   virtual void ClearRefreshToken() OVERRIDE;
    102   virtual google_apis::CancelCallback GetAllFileList(
    103       const google_apis::FileListCallback& callback) OVERRIDE;
    104   virtual google_apis::CancelCallback Search(
    105       const std::string& search_query,
    106       const google_apis::FileListCallback& callback) OVERRIDE;
    107   virtual google_apis::CancelCallback GetShareUrl(
    108       const std::string& resource_id,
    109       const GURL& embed_origin,
    110       const google_apis::GetShareUrlCallback& callback) OVERRIDE;
    111   virtual google_apis::CancelCallback GetAppList(
    112       const google_apis::AppListCallback& callback) OVERRIDE;
    113   virtual google_apis::CancelCallback TrashResource(
    114       const std::string& resource_id,
    115       const google_apis::EntryActionCallback& callback) OVERRIDE;
    116   virtual google_apis::CancelCallback CopyResource(
    117       const std::string& resource_id,
    118       const std::string& parent_resource_id,
    119       const std::string& new_title,
    120       const base::Time& last_modified,
    121       const google_apis::FileResourceCallback& callback) OVERRIDE;
    122   virtual google_apis::CancelCallback UpdateResource(
    123       const std::string& resource_id,
    124       const std::string& parent_resource_id,
    125       const std::string& new_title,
    126       const base::Time& last_modified,
    127       const base::Time& last_viewed_by_me,
    128       const google_apis::FileResourceCallback& callback) OVERRIDE;
    129   virtual google_apis::CancelCallback RenameResource(
    130       const std::string& resource_id,
    131       const std::string& new_title,
    132       const google_apis::EntryActionCallback& callback) OVERRIDE;
    133   virtual google_apis::CancelCallback AddResourceToDirectory(
    134       const std::string& parent_resource_id,
    135       const std::string& resource_id,
    136       const google_apis::EntryActionCallback& callback) OVERRIDE;
    137   virtual google_apis::CancelCallback InitiateUploadNewFile(
    138       const std::string& content_type,
    139       int64 content_length,
    140       const std::string& parent_resource_id,
    141       const std::string& title,
    142       const InitiateUploadNewFileOptions& options,
    143       const google_apis::InitiateUploadCallback& callback) OVERRIDE;
    144   virtual google_apis::CancelCallback InitiateUploadExistingFile(
    145       const std::string& content_type,
    146       int64 content_length,
    147       const std::string& resource_id,
    148       const InitiateUploadExistingFileOptions& options,
    149       const google_apis::InitiateUploadCallback& callback) OVERRIDE;
    150   virtual google_apis::CancelCallback ResumeUpload(
    151       const GURL& upload_url,
    152       int64 start_position,
    153       int64 end_position,
    154       int64 content_length,
    155       const std::string& content_type,
    156       const base::FilePath& local_file_path,
    157       const google_apis::drive::UploadRangeCallback& callback,
    158       const google_apis::ProgressCallback& progress_callback) OVERRIDE;
    159   virtual google_apis::CancelCallback GetUploadStatus(
    160       const GURL& upload_url,
    161       int64 content_length,
    162       const google_apis::drive::UploadRangeCallback& callback) OVERRIDE;
    163   virtual google_apis::CancelCallback AuthorizeApp(
    164       const std::string& resource_id,
    165       const std::string& app_id,
    166       const google_apis::AuthorizeAppCallback& callback) OVERRIDE;
    167   virtual google_apis::CancelCallback UninstallApp(
    168       const std::string& app_id,
    169       const google_apis::EntryActionCallback& callback) OVERRIDE;
    170   virtual google_apis::CancelCallback AddPermission(
    171       const std::string& resource_id,
    172       const std::string& email,
    173       google_apis::drive::PermissionRole role,
    174       const google_apis::EntryActionCallback& callback) OVERRIDE;
    175 
    176  private:
    177   base::WeakPtr<DriveServiceWrapper> wrapper_;
    178   scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_;
    179   scoped_refptr<base::SequencedTaskRunner> worker_task_runner_;
    180 
    181   base::SequenceChecker sequence_checker_;
    182 
    183   DISALLOW_COPY_AND_ASSIGN(DriveServiceOnWorker);
    184 };
    185 
    186 }  // namespace drive_backend
    187 }  // namespace sync_file_system
    188 
    189 #endif  // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_DRIVE_SERVICE_ON_WORKER_H_
    190