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

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

Issue 13197004: Draft: InvalidationService (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Passes tests Created 7 years, 8 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
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/debug/trace_event.h" 12 #include "base/debug/trace_event.h"
13 #include "base/file_util.h" 13 #include "base/file_util.h"
14 #include "base/location.h" 14 #include "base/location.h"
15 #include "base/memory/weak_ptr.h" 15 #include "base/memory/weak_ptr.h"
16 #include "base/message_loop_proxy.h" 16 #include "base/message_loop_proxy.h"
17 #include "base/utf_string_conversions.h" 17 #include "base/utf_string_conversions.h"
18 #include "base/values.h" 18 #include "base/values.h"
19 #include "chrome/browser/extensions/extension_service.h" 19 #include "chrome/browser/extensions/extension_service.h"
20 #include "chrome/browser/extensions/extension_system.h" 20 #include "chrome/browser/extensions/extension_system.h"
21 #include "chrome/browser/invalidation_service.h"
22 #include "chrome/browser/invalidation_service_factory.h"
21 #include "chrome/browser/profiles/profile.h" 23 #include "chrome/browser/profiles/profile.h"
22 #include "chrome/browser/sync/profile_sync_service.h"
23 #include "chrome/browser/sync/profile_sync_service_factory.h"
24 #include "chrome/browser/sync_file_system/conflict_resolution_policy.h" 24 #include "chrome/browser/sync_file_system/conflict_resolution_policy.h"
25 #include "chrome/browser/sync_file_system/drive_file_sync_client.h" 25 #include "chrome/browser/sync_file_system/drive_file_sync_client.h"
26 #include "chrome/browser/sync_file_system/drive_file_sync_util.h" 26 #include "chrome/browser/sync_file_system/drive_file_sync_util.h"
27 #include "chrome/browser/sync_file_system/drive_metadata_store.h" 27 #include "chrome/browser/sync_file_system/drive_metadata_store.h"
28 #include "chrome/browser/sync_file_system/file_status_observer.h" 28 #include "chrome/browser/sync_file_system/file_status_observer.h"
29 #include "chrome/browser/sync_file_system/remote_change_processor.h" 29 #include "chrome/browser/sync_file_system/remote_change_processor.h"
30 #include "chrome/browser/sync_file_system/sync_file_system.pb.h" 30 #include "chrome/browser/sync_file_system/sync_file_system.pb.h"
31 #include "chrome/common/extensions/extension.h" 31 #include "chrome/common/extensions/extension.h"
32 #include "content/public/browser/browser_thread.h" 32 #include "content/public/browser/browser_thread.h"
33 #include "extensions/common/constants.h" 33 #include "extensions/common/constants.h"
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 324
325 DriveFileSyncService::~DriveFileSyncService() { 325 DriveFileSyncService::~DriveFileSyncService() {
326 // Invalidate WeakPtr instances here explicitly to notify TaskToken that we 326 // Invalidate WeakPtr instances here explicitly to notify TaskToken that we
327 // can safely discard the token. 327 // can safely discard the token.
328 weak_factory_.InvalidateWeakPtrs(); 328 weak_factory_.InvalidateWeakPtrs();
329 if (sync_client_) 329 if (sync_client_)
330 sync_client_->RemoveObserver(this); 330 sync_client_->RemoveObserver(this);
331 token_.reset(); 331 token_.reset();
332 332
333 // Unregister for Drive notifications. 333 // Unregister for Drive notifications.
334 ProfileSyncService* profile_sync_service = 334 InvalidationService* invalidation_service =
335 ProfileSyncServiceFactory::GetForProfile(profile_); 335 InvalidationServiceFactory::GetForProfile(profile_);
336 if (!profile_sync_service || !push_notification_registered_) { 336 if (!invalidation_service || !push_notification_registered_) {
337 return; 337 return;
338 } 338 }
339 339
340 // TODO(calvinlo): Revisit this later in Consolidate Drive XMPP Notification 340 // TODO(calvinlo): Revisit this later in Consolidate Drive XMPP Notification
341 // and Polling Backup into one Class patch. http://crbug/173339. 341 // and Polling Backup into one Class patch. http://crbug/173339.
342 // Original comment from Kochi about the order this is done in: 342 // Original comment from Kochi about the order this is done in:
343 // Once DriveSystemService gets started / stopped at runtime, this ID needs to 343 // Once DriveSystemService gets started / stopped at runtime, this ID needs to
344 // be unregistered *before* the handler is unregistered 344 // be unregistered *before* the handler is unregistered
345 // as ID persists across browser restarts. 345 // as ID persists across browser restarts.
346 profile_sync_service->UpdateRegisteredInvalidationIds( 346 invalidation_service->UpdateRegisteredInvalidationIds(
347 this, syncer::ObjectIdSet()); 347 this, syncer::ObjectIdSet());
348 profile_sync_service->UnregisterInvalidationHandler(this); 348 invalidation_service->UnregisterInvalidationHandler(this);
349 } 349 }
350 350
351 // static 351 // static
352 scoped_ptr<DriveFileSyncService> DriveFileSyncService::CreateForTesting( 352 scoped_ptr<DriveFileSyncService> DriveFileSyncService::CreateForTesting(
353 Profile* profile, 353 Profile* profile,
354 const base::FilePath& base_dir, 354 const base::FilePath& base_dir,
355 scoped_ptr<DriveFileSyncClientInterface> sync_client, 355 scoped_ptr<DriveFileSyncClientInterface> sync_client,
356 scoped_ptr<DriveMetadataStore> metadata_store) { 356 scoped_ptr<DriveMetadataStore> metadata_store) {
357 return make_scoped_ptr(new DriveFileSyncService( 357 return make_scoped_ptr(new DriveFileSyncService(
358 profile, base_dir, sync_client.Pass(), metadata_store.Pass())); 358 profile, base_dir, sync_client.Pass(), metadata_store.Pass()));
(...skipping 2006 matching lines...) Expand 10 before | Expand all | Expand 10 after
2365 #endif 2365 #endif
2366 } 2366 }
2367 2367
2368 // Register for Google Drive invalidation notifications through XMPP. 2368 // Register for Google Drive invalidation notifications through XMPP.
2369 void DriveFileSyncService::RegisterDriveNotifications() { 2369 void DriveFileSyncService::RegisterDriveNotifications() {
2370 // Push notification registration might have already occurred if called from 2370 // Push notification registration might have already occurred if called from
2371 // a different extension. 2371 // a different extension.
2372 if (!IsDriveNotificationSupported() || push_notification_registered_) 2372 if (!IsDriveNotificationSupported() || push_notification_registered_)
2373 return; 2373 return;
2374 2374
2375 ProfileSyncService* profile_sync_service = 2375 InvalidationService* invalidation_service =
2376 ProfileSyncServiceFactory::GetForProfile(profile_); 2376 InvalidationServiceFactory::GetForProfile(profile_);
2377 if (!profile_sync_service) 2377 if (!invalidation_service)
2378 return; 2378 return;
2379 2379
2380 profile_sync_service->RegisterInvalidationHandler(this); 2380 invalidation_service->RegisterInvalidationHandler(this);
2381 syncer::ObjectIdSet ids; 2381 syncer::ObjectIdSet ids;
2382 ids.insert(invalidation::ObjectId( 2382 ids.insert(invalidation::ObjectId(
2383 ipc::invalidation::ObjectSource::COSMO_CHANGELOG, 2383 ipc::invalidation::ObjectSource::COSMO_CHANGELOG,
2384 kDriveInvalidationObjectId)); 2384 kDriveInvalidationObjectId));
2385 profile_sync_service->UpdateRegisteredInvalidationIds(this, ids); 2385 invalidation_service->UpdateRegisteredInvalidationIds(this, ids);
2386 push_notification_registered_ = true; 2386 push_notification_registered_ = true;
2387 SetPushNotificationEnabled(profile_sync_service->GetInvalidatorState()); 2387 SetPushNotificationEnabled(invalidation_service->GetInvalidatorState());
2388 } 2388 }
2389 2389
2390 void DriveFileSyncService::SetPushNotificationEnabled( 2390 void DriveFileSyncService::SetPushNotificationEnabled(
2391 syncer::InvalidatorState state) { 2391 syncer::InvalidatorState state) {
2392 push_notification_enabled_ = (state == syncer::INVALIDATIONS_ENABLED); 2392 push_notification_enabled_ = (state == syncer::INVALIDATIONS_ENABLED);
2393 if (!push_notification_enabled_) 2393 if (!push_notification_enabled_)
2394 return; 2394 return;
2395 2395
2396 // Push notifications are enabled so reset polling timer. 2396 // Push notifications are enabled so reset polling timer.
2397 UpdatePollingDelay(kPollingDelaySecondsWithNotification); 2397 UpdatePollingDelay(kPollingDelaySecondsWithNotification);
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
2476 pending_batch_sync_origins_.insert(origin); 2476 pending_batch_sync_origins_.insert(origin);
2477 } 2477 }
2478 callback.Run(status, resource_id); 2478 callback.Run(status, resource_id);
2479 } 2479 }
2480 2480
2481 std::string DriveFileSyncService::sync_root_resource_id() { 2481 std::string DriveFileSyncService::sync_root_resource_id() {
2482 return metadata_store_->sync_root_directory(); 2482 return metadata_store_->sync_root_directory();
2483 } 2483 }
2484 2484
2485 } // namespace sync_file_system 2485 } // namespace sync_file_system
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698