OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_CHROMEOS_DRIVE_DRIVE_SYNC_CLIENT_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_SYNC_CLIENT_H_ |
6 #define CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_SYNC_CLIENT_H_ | 6 #define CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_SYNC_CLIENT_H_ |
7 | 7 |
8 #include <deque> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/callback_forward.h" | |
13 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
14 #include "base/time.h" | 13 #include "base/time.h" |
15 #include "chrome/browser/chromeos/drive/drive_cache.h" | |
16 #include "chrome/browser/chromeos/drive/drive_cache_observer.h" | 14 #include "chrome/browser/chromeos/drive/drive_cache_observer.h" |
17 #include "chrome/browser/chromeos/drive/drive_file_system_observer.h" | 15 #include "chrome/browser/chromeos/drive/drive_file_system_observer.h" |
18 #include "chrome/browser/chromeos/drive/drive_resource_metadata.h" | 16 #include "chrome/browser/chromeos/drive/drive_resource_metadata.h" |
19 #include "net/base/network_change_notifier.h" | |
20 | |
21 class Profile; | |
22 class PrefChangeRegistrar; | |
23 | 17 |
24 namespace drive { | 18 namespace drive { |
25 | 19 |
20 class DriveCache; | |
21 class DriveCacheEntry; | |
26 class DriveEntryProto; | 22 class DriveEntryProto; |
27 class DriveFileSystemInterface; | 23 class DriveFileSystemInterface; |
28 class DrivePrefetcher; | |
29 | 24 |
30 // The DriveSyncClient is used to synchronize pinned files on Drive and the | 25 // The DriveSyncClient is used to synchronize pinned files on Drive and the |
31 // cache on the local drive. The sync client works as follows. | 26 // cache on the local drive. The sync client works as follows. |
32 // | 27 // |
33 // When the user pins files on Drive, this client is notified about the files | 28 // When the user pins files on Drive, this client is notified about the files |
34 // that get pinned, and queues tasks and starts fetching these files in the | 29 // that get pinned, and queues tasks and starts fetching these files in the |
35 // background. | 30 // background. |
36 // | 31 // |
37 // When the user unpins files on Drive, this client is notified about the | 32 // When the user unpins files on Drive, this client is notified about the |
38 // files that get unpinned, cancels tasks if these are still in the queue. | 33 // files that get unpinned, cancels tasks if these are still in the queue. |
39 // | 34 // |
40 // If the user logs out before fetching of the pinned files is complete, this | 35 // If the user logs out before fetching of the pinned files is complete, this |
41 // client resumes fetching operations next time the user logs in, based on | 36 // client resumes fetching operations next time the user logs in, based on |
42 // the states left in the cache. | 37 // the states left in the cache. |
43 class DriveSyncClient | 38 class DriveSyncClient : public DriveFileSystemObserver, |
44 : public DriveFileSystemObserver, | 39 public DriveCacheObserver { |
45 public DriveCacheObserver { | |
46 public: | 40 public: |
47 // Types of sync tasks. | 41 // Types of sync tasks. |
48 enum SyncType { | 42 enum SyncType { |
49 FETCH, // Fetch a file from the Drive server. | 43 FETCH, // Fetch a file from the Drive server. |
50 UPLOAD, // Upload a file to the Drive server. | 44 UPLOAD, // Upload a file to the Drive server. |
51 }; | 45 }; |
52 | 46 |
53 // |profile| is used to access user preferences. | |
54 // |file_system| is used access the | 47 // |file_system| is used access the |
hashimoto
2013/04/19 03:59:06
nit: This comment is quite wrong. (what is used to
kinaba
2013/04/19 04:10:17
Done.
| |
55 // cache (ex. store a file to the cache when the file is downloaded). | 48 // cache (ex. store a file to the cache when the file is downloaded). |
56 DriveSyncClient(Profile* profile, | 49 DriveSyncClient(DriveFileSystemInterface* file_system, |
57 DriveFileSystemInterface* file_system, | |
58 DriveCache* cache); | 50 DriveCache* cache); |
59 virtual ~DriveSyncClient(); | 51 virtual ~DriveSyncClient(); |
60 | 52 |
61 // Initializes the DriveSyncClient. | 53 // Initializes the DriveSyncClient. |
62 void Initialize(); | 54 void Initialize(); |
63 | 55 |
64 // DriveFileSystemInterface::Observer overrides. | 56 // DriveFileSystemInterface::Observer overrides. |
65 virtual void OnInitialLoadFinished() OVERRIDE; | 57 virtual void OnInitialLoadFinished() OVERRIDE; |
66 virtual void OnFeedFromServerLoaded() OVERRIDE; | 58 virtual void OnFeedFromServerLoaded() OVERRIDE; |
67 | 59 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
143 DriveFileError error, | 135 DriveFileError error, |
144 const base::FilePath& local_path, | 136 const base::FilePath& local_path, |
145 const std::string& ununsed_mime_type, | 137 const std::string& ununsed_mime_type, |
146 DriveFileType file_type); | 138 DriveFileType file_type); |
147 | 139 |
148 // Called when the file for |resource_id| is uploaded. | 140 // Called when the file for |resource_id| is uploaded. |
149 // Calls DoSyncLoop() to go back to the sync loop. | 141 // Calls DoSyncLoop() to go back to the sync loop. |
150 void OnUploadFileComplete(const std::string& resource_id, | 142 void OnUploadFileComplete(const std::string& resource_id, |
151 DriveFileError error); | 143 DriveFileError error); |
152 | 144 |
153 Profile* profile_; | |
154 DriveFileSystemInterface* file_system_; // Owned by DriveSystemService. | 145 DriveFileSystemInterface* file_system_; // Owned by DriveSystemService. |
155 DriveCache* cache_; // Owned by DriveSystemService. | 146 DriveCache* cache_; // Owned by DriveSystemService. |
156 | 147 |
157 // List of the resource ids of resources which have a fetch task created. | 148 // List of the resource ids of resources which have a fetch task created. |
158 std::set<std::string> fetch_list_; | 149 std::set<std::string> fetch_list_; |
159 | 150 |
160 // List of the resource ids of resources which have a upload task created. | 151 // List of the resource ids of resources which have a upload task created. |
161 std::set<std::string> upload_list_; | 152 std::set<std::string> upload_list_; |
162 | 153 |
163 // Fetch tasks which have been created, but not started yet. If they are | 154 // Fetch tasks which have been created, but not started yet. If they are |
164 // removed before starting, they will be cancelled. | 155 // removed before starting, they will be cancelled. |
165 std::set<std::string> pending_fetch_list_; | 156 std::set<std::string> pending_fetch_list_; |
166 | 157 |
167 // The delay is used for delaying processing SyncTasks in DoSyncLoop(). | 158 // The delay is used for delaying processing SyncTasks in DoSyncLoop(). |
168 base::TimeDelta delay_; | 159 base::TimeDelta delay_; |
169 | 160 |
170 // Note: This should remain the last member so it'll be destroyed and | 161 // Note: This should remain the last member so it'll be destroyed and |
171 // invalidate its weak pointers before any other members are destroyed. | 162 // invalidate its weak pointers before any other members are destroyed. |
172 base::WeakPtrFactory<DriveSyncClient> weak_ptr_factory_; | 163 base::WeakPtrFactory<DriveSyncClient> weak_ptr_factory_; |
173 | 164 |
174 DISALLOW_COPY_AND_ASSIGN(DriveSyncClient); | 165 DISALLOW_COPY_AND_ASSIGN(DriveSyncClient); |
175 }; | 166 }; |
176 | 167 |
177 } // namespace drive | 168 } // namespace drive |
178 | 169 |
179 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_SYNC_CLIENT_H_ | 170 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_SYNC_CLIENT_H_ |
OLD | NEW |