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_GDATA_GDATA_SYNC_CLIENT_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_GDATA_GDATA_SYNC_CLIENT_H_ |
6 #define CHROME_BROWSER_CHROMEOS_GDATA_GDATA_SYNC_CLIENT_H_ | 6 #define CHROME_BROWSER_CHROMEOS_GDATA_GDATA_SYNC_CLIENT_H_ |
7 | 7 |
8 #include <deque> | 8 #include <deque> |
9 #include <string> | 9 #include <string> |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 // When the user unpins files on gdata, this client is notified about the | 34 // When the user unpins files on gdata, this client is notified about the |
35 // files that get unpinned, cancels tasks if these are still in the queue. | 35 // files that get unpinned, cancels tasks if these are still in the queue. |
36 // | 36 // |
37 // If the user logs out before fetching of the pinned files is complete, this | 37 // If the user logs out before fetching of the pinned files is complete, this |
38 // client resumes fetching operations next time the user logs in, based on | 38 // client resumes fetching operations next time the user logs in, based on |
39 // the states left in the cache. | 39 // the states left in the cache. |
40 // | 40 // |
41 // TODO(satorux): This client should also upload pinned but dirty (locally | 41 // TODO(satorux): This client should also upload pinned but dirty (locally |
42 // edited) files to gdata. Will work on this once downloading is done. | 42 // edited) files to gdata. Will work on this once downloading is done. |
43 // crosbug.com/27836. | 43 // crosbug.com/27836. |
44 // | 44 class GDataSyncClient : public GDataFileSystemInterface::Observer, |
45 // The interface class is defined to make GDataSyncClient mockable. | 45 public GDataCache::Observer, |
46 class GDataSyncClientInterface { | 46 public chromeos::NetworkLibrary::NetworkManagerObserver, |
47 public: | 47 public content::NotificationObserver { |
48 // Initializes the GDataSyncClient. | |
49 virtual void Initialize() = 0; | |
50 | |
51 virtual ~GDataSyncClientInterface() {} | |
52 }; | |
53 | |
54 // The production implementation of GDataSyncClientInterface. | |
55 class GDataSyncClient | |
56 : public GDataSyncClientInterface, | |
57 public GDataFileSystemInterface::Observer, | |
58 public GDataCache::Observer, | |
59 public chromeos::NetworkLibrary::NetworkManagerObserver, | |
60 public content::NotificationObserver { | |
61 public: | 48 public: |
62 // Types of sync tasks. | 49 // Types of sync tasks. |
63 enum SyncType { | 50 enum SyncType { |
64 FETCH, // Fetch a file from the gdata server. | 51 FETCH, // Fetch a file from the gdata server. |
65 UPLOAD, // Upload a file to the gdata server. | 52 UPLOAD, // Upload a file to the gdata server. |
66 }; | 53 }; |
67 | 54 |
68 // The struct is used to queue tasks for fetching and uploading. | 55 // The struct is used to queue tasks for fetching and uploading. |
69 struct SyncTask { | 56 struct SyncTask { |
70 SyncTask(SyncType in_sync_type, | 57 SyncTask(SyncType in_sync_type, |
71 const std::string& in_resource_id, | 58 const std::string& in_resource_id, |
72 const base::Time& in_timestamp); | 59 const base::Time& in_timestamp); |
73 | 60 |
74 SyncType sync_type; | 61 SyncType sync_type; |
75 std::string resource_id; | 62 std::string resource_id; |
76 base::Time timestamp; | 63 base::Time timestamp; |
77 }; | 64 }; |
78 | 65 |
79 // |profile| is used to access user preferences. | 66 // |profile| is used to access user preferences. |
80 // |file_system| is used access the | 67 // |file_system| is used access the |
81 // cache (ex. store a file to the cache when the file is downloaded). | 68 // cache (ex. store a file to the cache when the file is downloaded). |
82 GDataSyncClient(Profile* profile, | 69 GDataSyncClient(Profile* profile, |
83 GDataFileSystemInterface* file_system, | 70 GDataFileSystemInterface* file_system, |
84 GDataCache* cache); | 71 GDataCache* cache); |
85 virtual ~GDataSyncClient(); | 72 virtual ~GDataSyncClient(); |
86 | 73 |
87 // GDataSyncClientInterface overrides. | 74 // Initializes the GDataSyncClient. |
88 virtual void Initialize() OVERRIDE; | 75 void Initialize(); |
89 | 76 |
90 // GDataFileSystemInterface overrides. | 77 // GDataFileSystemInterface overrides. |
91 virtual void OnInitialLoadFinished() OVERRIDE; | 78 virtual void OnInitialLoadFinished() OVERRIDE; |
92 virtual void OnFeedFromServerLoaded() OVERRIDE; | 79 virtual void OnFeedFromServerLoaded() OVERRIDE; |
93 | 80 |
94 // GDataCache::Observer overrides. | 81 // GDataCache::Observer overrides. |
95 virtual void OnCachePinned(const std::string& resource_id, | 82 virtual void OnCachePinned(const std::string& resource_id, |
96 const std::string& md5) OVERRIDE; | 83 const std::string& md5) OVERRIDE; |
97 virtual void OnCacheUnpinned(const std::string& resource_id, | 84 virtual void OnCacheUnpinned(const std::string& resource_id, |
98 const std::string& md5) OVERRIDE; | 85 const std::string& md5) OVERRIDE; |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 bool sync_loop_is_running_; | 197 bool sync_loop_is_running_; |
211 | 198 |
212 base::WeakPtrFactory<GDataSyncClient> weak_ptr_factory_; | 199 base::WeakPtrFactory<GDataSyncClient> weak_ptr_factory_; |
213 | 200 |
214 DISALLOW_COPY_AND_ASSIGN(GDataSyncClient); | 201 DISALLOW_COPY_AND_ASSIGN(GDataSyncClient); |
215 }; | 202 }; |
216 | 203 |
217 } // namespace gdata | 204 } // namespace gdata |
218 | 205 |
219 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_SYNC_CLIENT_H_ | 206 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_SYNC_CLIENT_H_ |
OLD | NEW |