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

Side by Side Diff: chrome/browser/sync_file_system/drive_file_sync_service.cc

Issue 12391012: Sync FileSystem: Add simulated relaunch of DriveFileSyncService on its unit_tests (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove unused comparator Created 7 years, 9 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 (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 #include "chrome/browser/sync_file_system/drive_file_sync_service.h" 5 #include "chrome/browser/sync_file_system/drive_file_sync_service.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 base::Bind(&DriveFileSyncService::DidInitializeMetadataStore, 280 base::Bind(&DriveFileSyncService::DidInitializeMetadataStore,
281 AsWeakPtr(), 281 AsWeakPtr(),
282 base::Passed(GetToken(FROM_HERE, TASK_TYPE_DATABASE, 282 base::Passed(GetToken(FROM_HERE, TASK_TYPE_DATABASE,
283 "Metadata database initialization")))); 283 "Metadata database initialization"))));
284 } 284 }
285 285
286 DriveFileSyncService::~DriveFileSyncService() { 286 DriveFileSyncService::~DriveFileSyncService() {
287 // Invalidate WeakPtr instances here explicitly to notify TaskToken that we 287 // Invalidate WeakPtr instances here explicitly to notify TaskToken that we
288 // can safely discard the token. 288 // can safely discard the token.
289 weak_factory_.InvalidateWeakPtrs(); 289 weak_factory_.InvalidateWeakPtrs();
290 sync_client_->RemoveObserver(this); 290 if (sync_client_)
291 sync_client_->RemoveObserver(this);
291 token_.reset(); 292 token_.reset();
292 293
293 // Unregister for Drive notifications. 294 // Unregister for Drive notifications.
294 ProfileSyncService* profile_sync_service = 295 ProfileSyncService* profile_sync_service =
295 ProfileSyncServiceFactory::GetForProfile(profile_); 296 ProfileSyncServiceFactory::GetForProfile(profile_);
296 if (!profile_sync_service || !push_notification_registered_) { 297 if (!profile_sync_service || !push_notification_registered_) {
297 return; 298 return;
298 } 299 }
299 300
300 // TODO(calvinlo): Revisit this later in Consolidate Drive XMPP Notification 301 // TODO(calvinlo): Revisit this later in Consolidate Drive XMPP Notification
(...skipping 10 matching lines...) Expand all
311 // static 312 // static
312 scoped_ptr<DriveFileSyncService> DriveFileSyncService::CreateForTesting( 313 scoped_ptr<DriveFileSyncService> DriveFileSyncService::CreateForTesting(
313 Profile* profile, 314 Profile* profile,
314 const base::FilePath& base_dir, 315 const base::FilePath& base_dir,
315 scoped_ptr<DriveFileSyncClientInterface> sync_client, 316 scoped_ptr<DriveFileSyncClientInterface> sync_client,
316 scoped_ptr<DriveMetadataStore> metadata_store) { 317 scoped_ptr<DriveMetadataStore> metadata_store) {
317 return make_scoped_ptr(new DriveFileSyncService( 318 return make_scoped_ptr(new DriveFileSyncService(
318 profile, base_dir, sync_client.Pass(), metadata_store.Pass())); 319 profile, base_dir, sync_client.Pass(), metadata_store.Pass()));
319 } 320 }
320 321
322 scoped_ptr<DriveFileSyncClientInterface>
323 DriveFileSyncService::DestroyAndPassSyncClientForTesting(
324 scoped_ptr<DriveFileSyncService> sync_service) {
325 return sync_service->sync_client_.Pass();
326 }
327
321 void DriveFileSyncService::AddServiceObserver(Observer* observer) { 328 void DriveFileSyncService::AddServiceObserver(Observer* observer) {
322 service_observers_.AddObserver(observer); 329 service_observers_.AddObserver(observer);
323 } 330 }
324 331
325 void DriveFileSyncService::AddFileStatusObserver( 332 void DriveFileSyncService::AddFileStatusObserver(
326 FileStatusObserver* observer) { 333 FileStatusObserver* observer) {
327 file_status_observers_.AddObserver(observer); 334 file_status_observers_.AddObserver(observer);
328 } 335 }
329 336
330 void DriveFileSyncService::RegisterOriginForTrackingChanges( 337 void DriveFileSyncService::RegisterOriginForTrackingChanges(
(...skipping 1485 matching lines...) Expand 10 before | Expand all | Expand 10 after
1816 may_have_unfetched_changes_) { 1823 may_have_unfetched_changes_) {
1817 GURL origin = *pending_batch_sync_origins_.begin(); 1824 GURL origin = *pending_batch_sync_origins_.begin();
1818 pending_batch_sync_origins_.erase(pending_batch_sync_origins_.begin()); 1825 pending_batch_sync_origins_.erase(pending_batch_sync_origins_.begin());
1819 std::string resource_id = metadata_store_->GetResourceIdForOrigin(origin); 1826 std::string resource_id = metadata_store_->GetResourceIdForOrigin(origin);
1820 StartBatchSyncForOrigin(origin, resource_id); 1827 StartBatchSyncForOrigin(origin, resource_id);
1821 } 1828 }
1822 return; 1829 return;
1823 } 1830 }
1824 1831
1825 if (may_have_unfetched_changes_ && 1832 if (may_have_unfetched_changes_ &&
1826 !metadata_store_->incremental_sync_origins().empty() && 1833 !metadata_store_->incremental_sync_origins().empty()) {
1827 pending_changes_.empty()) {
1828 FetchChangesForIncrementalSync(); 1834 FetchChangesForIncrementalSync();
1829 } 1835 }
1830 } 1836 }
1831 1837
1832 void DriveFileSyncService::FetchChangesForIncrementalSync() { 1838 void DriveFileSyncService::FetchChangesForIncrementalSync() {
1833 scoped_ptr<TaskToken> token(GetToken(FROM_HERE, TASK_TYPE_DRIVE, 1839 scoped_ptr<TaskToken> token(GetToken(FROM_HERE, TASK_TYPE_DRIVE,
1834 "Fetching remote change list")); 1840 "Fetching remote change list"));
1835 DCHECK(token); 1841 DCHECK(token);
1836 DCHECK(may_have_unfetched_changes_); 1842 DCHECK(may_have_unfetched_changes_);
1837 DCHECK(pending_batch_sync_origins_.empty()); 1843 DCHECK(pending_batch_sync_origins_.empty());
1838 DCHECK(!metadata_store_->incremental_sync_origins().empty()); 1844 DCHECK(!metadata_store_->incremental_sync_origins().empty());
1839 DCHECK(pending_changes_.empty());
1840 1845
1841 DVLOG(1) << "FetchChangesForIncrementalSync (start_changestamp:" 1846 DVLOG(1) << "FetchChangesForIncrementalSync (start_changestamp:"
1842 << (largest_fetched_changestamp_ + 1) << ")"; 1847 << (largest_fetched_changestamp_ + 1) << ")";
1843 1848
1844 sync_client_->ListChanges( 1849 sync_client_->ListChanges(
1845 largest_fetched_changestamp_ + 1, 1850 largest_fetched_changestamp_ + 1,
1846 base::Bind(&DriveFileSyncService::DidFetchChangesForIncrementalSync, 1851 base::Bind(&DriveFileSyncService::DidFetchChangesForIncrementalSync,
1847 AsWeakPtr(), base::Passed(&token), false)); 1852 AsWeakPtr(), base::Passed(&token), false));
1848 1853
1849 may_have_unfetched_changes_ = false; 1854 may_have_unfetched_changes_ = false;
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
2031 DCHECK_EQ(SYNC_ACTION_NONE, action_taken); 2036 DCHECK_EQ(SYNC_ACTION_NONE, action_taken);
2032 DCHECK_EQ(SYNC_DIRECTION_NONE, direction); 2037 DCHECK_EQ(SYNC_DIRECTION_NONE, direction);
2033 } 2038 }
2034 2039
2035 FOR_EACH_OBSERVER( 2040 FOR_EACH_OBSERVER(
2036 FileStatusObserver, file_status_observers_, 2041 FileStatusObserver, file_status_observers_,
2037 OnFileStatusChanged(url, sync_status, action_taken, direction)); 2042 OnFileStatusChanged(url, sync_status, action_taken, direction));
2038 } 2043 }
2039 2044
2040 } // namespace sync_file_system 2045 } // namespace sync_file_system
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698