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_REMOTE_CHANGE_PROCESSOR_ON_WORKER_H_
      6 #define CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_REMOTE_CHANGE_PROCESSOR_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/sync_file_system/remote_change_processor.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 RemoteChangeProcessorWrapper;
     22 
     23 // This class wraps a part of RemoteChangeProcessor class to post actual
     24 // tasks to RemoteChangeProcessorWrapper which lives in another thread.
     25 // Each method wraps corresponding name method of RemoteChangeProcessor.
     26 // See comments in remote_change_processor.h for details.
     27 class RemoteChangeProcessorOnWorker : public RemoteChangeProcessor {
     28  public:
     29   RemoteChangeProcessorOnWorker(
     30       const base::WeakPtr<RemoteChangeProcessorWrapper>& wrapper,
     31       base::SingleThreadTaskRunner* ui_task_runner,
     32       base::SequencedTaskRunner* worker_task_runner);
     33   virtual ~RemoteChangeProcessorOnWorker();
     34 
     35   virtual void PrepareForProcessRemoteChange(
     36       const fileapi::FileSystemURL& url,
     37       const PrepareChangeCallback& callback) OVERRIDE;
     38   virtual void ApplyRemoteChange(
     39       const FileChange& change,
     40       const base::FilePath& local_path,
     41       const fileapi::FileSystemURL& url,
     42       const SyncStatusCallback& callback) OVERRIDE;
     43   virtual void FinalizeRemoteSync(
     44       const fileapi::FileSystemURL& url,
     45       bool clear_local_changes,
     46       const base::Closure& completion_callback) OVERRIDE;
     47   virtual void RecordFakeLocalChange(
     48       const fileapi::FileSystemURL& url,
     49       const FileChange& change,
     50       const SyncStatusCallback& callback) OVERRIDE;
     51 
     52   void DetachFromSequence();
     53 
     54  private:
     55   base::WeakPtr<RemoteChangeProcessorWrapper> wrapper_;
     56   scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_;
     57   scoped_refptr<base::SequencedTaskRunner> worker_task_runner_;
     58 
     59   base::SequenceChecker sequence_checker_;
     60 
     61   DISALLOW_COPY_AND_ASSIGN(RemoteChangeProcessorOnWorker);
     62 };
     63 
     64 }  // namespace drive_backend
     65 }  // namespace sync_file_system
     66 
     67 #endif  // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_REMOTE_CHANGE_PROCESSOR_ON_WORKER_H_
     68