Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(74)

Side by Side Diff: chrome/browser/sync_file_system/sync_process_runner.h

Issue 377563002: [SyncFS] Eliminate SyncFileSystemService dependency from SyncProcessRunner (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_SYNC_FILE_SYSTEM_SYNC_PROCESS_RUNNER_H_ 5 #ifndef CHROME_BROWSER_SYNC_FILE_SYSTEM_SYNC_PROCESS_RUNNER_H_
6 #define CHROME_BROWSER_SYNC_FILE_SYSTEM_SYNC_PROCESS_RUNNER_H_ 6 #define CHROME_BROWSER_SYNC_FILE_SYSTEM_SYNC_PROCESS_RUNNER_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/memory/weak_ptr.h" 11 #include "base/memory/weak_ptr.h"
12 #include "base/timer/timer.h" 12 #include "base/timer/timer.h"
13 #include "chrome/browser/sync_file_system/sync_callbacks.h" 13 #include "chrome/browser/sync_file_system/sync_callbacks.h"
14 #include "chrome/browser/sync_file_system/sync_service_state.h" 14 #include "chrome/browser/sync_file_system/sync_service_state.h"
15 15
16 namespace sync_file_system { 16 namespace sync_file_system {
17 17
18 class SyncFileSystemService; 18 class SyncFileSystemService;
19 19
20 // A base class to schedule a sync. 20 // A base class to schedule a sync.
21 // Each subclass must implement StartSync(). 21 // Each subclass must implement StartSync().
22 // An instance of this class is supposed to be owned by SyncFileSystemService. 22 // An instance of this class is supposed to be owned by SyncFileSystemService.
23 // 23 //
24 // Note that multiple SyncProcessRunner doesn't coordinate its sync schedule 24 // Note that multiple SyncProcessRunner doesn't coordinate its sync schedule
25 // with each other. 25 // with each other.
26 class SyncProcessRunner { 26 class SyncProcessRunner {
27 public: 27 public:
28 class Client {
29 public:
30 virtual ~Client() {}
31 virtual void OnSyncIdle() {}
32 virtual SyncServiceState GetSyncServiceState() = 0;
33 virtual SyncFileSystemService* GetSyncService() = 0;
34 };
35
28 class TimerHelper { 36 class TimerHelper {
29 public: 37 public:
30 virtual ~TimerHelper() {} 38 virtual ~TimerHelper() {}
31 virtual bool IsRunning() = 0; 39 virtual bool IsRunning() = 0;
32 virtual void Start(const tracked_objects::Location& from_here, 40 virtual void Start(const tracked_objects::Location& from_here,
33 const base::TimeDelta& delay, 41 const base::TimeDelta& delay,
34 const base::Closure& closure) = 0; 42 const base::Closure& closure) = 0;
35 43
36 protected: 44 protected:
37 TimerHelper() {} 45 TimerHelper() {}
38 }; 46 };
39 47
40 SyncProcessRunner(const std::string& name, 48 SyncProcessRunner(const std::string& name,
41 SyncFileSystemService* sync_service, 49 Client* client,
42 scoped_ptr<TimerHelper> timer_helper, 50 scoped_ptr<TimerHelper> timer_helper,
43 int max_parallel_task); 51 int max_parallel_task);
44 virtual ~SyncProcessRunner(); 52 virtual ~SyncProcessRunner();
45 53
46 // Subclass must implement this. 54 // Subclass must implement this.
47 virtual void StartSync(const SyncStatusCallback& callback) = 0; 55 virtual void StartSync(const SyncStatusCallback& callback) = 0;
48 56
49 // Schedules a new sync. 57 // Schedules a new sync.
50 void Schedule(); 58 void Schedule();
51 void ScheduleIfNotRunning(); 59 void ScheduleIfNotRunning();
52 60
53 int64 pending_changes() const { return pending_changes_; } 61 int64 pending_changes() const { return pending_changes_; }
54 62
55 protected: 63 protected:
56 void OnChangesUpdated(int64 pending_changes); 64 void OnChangesUpdated(int64 pending_changes);
57 SyncFileSystemService* sync_service() { return sync_service_; } 65 SyncFileSystemService* GetSyncService();
58 66
59 // Returns the current service state. Default implementation returns 67 // Returns the current service state. Default implementation returns
60 // sync_service()->GetSyncServiceState(). 68 // sync_service()->GetSyncServiceState().
61 virtual SyncServiceState GetServiceState(); 69 virtual SyncServiceState GetServiceState();
62 70
63 private: 71 private:
64 void Finished(const base::TimeTicks& start_time, SyncStatusCode status); 72 void Finished(const base::TimeTicks& start_time, SyncStatusCode status);
65 void Run(); 73 void Run();
66 void ScheduleInternal(int64 delay); 74 void ScheduleInternal(int64 delay);
67 75
68 std::string name_; 76 std::string name_;
69 SyncFileSystemService* sync_service_; 77 Client* client_;
70 int max_parallel_task_; 78 int max_parallel_task_;
71 int running_tasks_; 79 int running_tasks_;
72 scoped_ptr<TimerHelper> timer_helper_; 80 scoped_ptr<TimerHelper> timer_helper_;
73 base::TimeTicks last_scheduled_; 81 base::TimeTicks last_scheduled_;
74 int64 current_delay_; 82 int64 current_delay_;
75 int64 last_delay_; 83 int64 last_delay_;
76 int64 pending_changes_; 84 int64 pending_changes_;
77 base::WeakPtrFactory<SyncProcessRunner> factory_; 85 base::WeakPtrFactory<SyncProcessRunner> factory_;
78 86
79 DISALLOW_COPY_AND_ASSIGN(SyncProcessRunner); 87 DISALLOW_COPY_AND_ASSIGN(SyncProcessRunner);
80 }; 88 };
81 89
82 } // namespace sync_file_system 90 } // namespace sync_file_system
83 91
84 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_SYNC_PROCESS_RUNNER_H_ 92 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_SYNC_PROCESS_RUNNER_H_
OLDNEW
« no previous file with comments | « chrome/browser/sync_file_system/sync_file_system_service.cc ('k') | chrome/browser/sync_file_system/sync_process_runner.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698