Chromium Code Reviews| 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 #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/google_apis/drive_notification_manager.h" | |
| 22 #include "chrome/browser/google_apis/drive_notification_manager_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" |
| 34 #include "google/cacheinvalidation/types.pb.h" | |
| 35 #include "webkit/fileapi/file_system_url.h" | 34 #include "webkit/fileapi/file_system_url.h" |
| 36 #include "webkit/fileapi/syncable/sync_file_metadata.h" | 35 #include "webkit/fileapi/syncable/sync_file_metadata.h" |
| 37 #include "webkit/fileapi/syncable/sync_file_type.h" | 36 #include "webkit/fileapi/syncable/sync_file_type.h" |
| 38 #include "webkit/fileapi/syncable/syncable_file_system_util.h" | 37 #include "webkit/fileapi/syncable/syncable_file_system_util.h" |
| 39 | 38 |
| 40 using fileapi::FileSystemURL; | 39 using fileapi::FileSystemURL; |
| 41 | 40 |
| 42 namespace sync_file_system { | 41 namespace sync_file_system { |
| 43 | 42 |
| 44 namespace { | 43 namespace { |
| 45 | 44 |
| 46 const base::FilePath::CharType kTempDirName[] = FILE_PATH_LITERAL("tmp"); | 45 const base::FilePath::CharType kTempDirName[] = FILE_PATH_LITERAL("tmp"); |
| 47 const base::FilePath::CharType kSyncFileSystemDir[] = | 46 const base::FilePath::CharType kSyncFileSystemDir[] = |
| 48 FILE_PATH_LITERAL("Sync FileSystem"); | 47 FILE_PATH_LITERAL("Sync FileSystem"); |
| 49 | 48 |
| 50 // The sync invalidation object ID for Google Drive. | |
| 51 const char kDriveInvalidationObjectId[] = "CHANGELOG"; | |
| 52 | |
| 53 // Incremental sync polling interval. | 49 // Incremental sync polling interval. |
| 54 // TODO(calvinlo): Improve polling algorithm dependent on whether push | 50 // TODO(calvinlo): Improve polling algorithm dependent on whether push |
| 55 // notifications are on or off. | 51 // notifications are on or off. |
| 56 const int64 kMinimumPollingDelaySeconds = 5; | 52 const int64 kMinimumPollingDelaySeconds = 5; |
| 57 const int64 kMaximumPollingDelaySeconds = 10 * 60; // 10 min | 53 const int64 kMaximumPollingDelaySeconds = 10 * 60; // 10 min |
| 58 const int64 kPollingDelaySecondsWithNotification = 4 * 60 * 60; // 4 hr | 54 const int64 kPollingDelaySecondsWithNotification = 4 * 60 * 60; // 4 hr |
| 59 const double kDelayMultiplier = 1.6; | 55 const double kDelayMultiplier = 1.6; |
| 60 | 56 |
| 61 bool CreateTemporaryFile(const base::FilePath& dir_path, | 57 bool CreateTemporaryFile(const base::FilePath& dir_path, |
| 62 base::FilePath* temp_file) { | 58 base::FilePath* temp_file) { |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 148 | 144 |
| 149 private: | 145 private: |
| 150 base::WeakPtr<DriveFileSyncService> sync_service_; | 146 base::WeakPtr<DriveFileSyncService> sync_service_; |
| 151 tracked_objects::Location location_; | 147 tracked_objects::Location location_; |
| 152 TaskType task_type_; | 148 TaskType task_type_; |
| 153 std::string description_; | 149 std::string description_; |
| 154 | 150 |
| 155 DISALLOW_COPY_AND_ASSIGN(TaskToken); | 151 DISALLOW_COPY_AND_ASSIGN(TaskToken); |
| 156 }; | 152 }; |
| 157 | 153 |
| 158 void DriveFileSyncService::OnInvalidatorStateChange( | |
| 159 syncer::InvalidatorState state) { | |
| 160 SetPushNotificationEnabled(state); | |
| 161 } | |
| 162 | |
| 163 void DriveFileSyncService::OnIncomingInvalidation( | |
| 164 const syncer::ObjectIdInvalidationMap& invalidation_map) { | |
| 165 DCHECK_EQ(1U, invalidation_map.size()); | |
| 166 const invalidation::ObjectId object_id( | |
| 167 ipc::invalidation::ObjectSource::COSMO_CHANGELOG, | |
| 168 kDriveInvalidationObjectId); | |
| 169 DCHECK_EQ(1U, invalidation_map.count(object_id)); | |
| 170 // TODO(dcheng): Only acknowledge the invalidation once the fetch has | |
| 171 // completed. http://crbug.com/156843 | |
| 172 ProfileSyncService* profile_sync_service = | |
| 173 ProfileSyncServiceFactory::GetForProfile(profile_); | |
| 174 CHECK(profile_sync_service); | |
| 175 profile_sync_service->AcknowledgeInvalidation( | |
| 176 invalidation_map.begin()->first, | |
| 177 invalidation_map.begin()->second.ack_handle); | |
| 178 | |
| 179 may_have_unfetched_changes_ = true; | |
| 180 MaybeStartFetchChanges(); | |
| 181 } | |
| 182 | |
| 183 struct DriveFileSyncService::ProcessRemoteChangeParam { | 154 struct DriveFileSyncService::ProcessRemoteChangeParam { |
| 184 scoped_ptr<TaskToken> token; | 155 scoped_ptr<TaskToken> token; |
| 185 RemoteChange remote_change; | 156 RemoteChange remote_change; |
| 186 SyncFileCallback callback; | 157 SyncFileCallback callback; |
| 187 | 158 |
| 188 DriveMetadata drive_metadata; | 159 DriveMetadata drive_metadata; |
| 189 SyncFileMetadata local_metadata; | 160 SyncFileMetadata local_metadata; |
| 190 bool metadata_updated; | 161 bool metadata_updated; |
| 191 base::FilePath temporary_file_path; | 162 base::FilePath temporary_file_path; |
| 192 std::string md5_checksum; | 163 std::string md5_checksum; |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 297 return left.changestamp > right.changestamp; | 268 return left.changestamp > right.changestamp; |
| 298 return false; | 269 return false; |
| 299 } | 270 } |
| 300 | 271 |
| 301 DriveFileSyncService::DriveFileSyncService(Profile* profile) | 272 DriveFileSyncService::DriveFileSyncService(Profile* profile) |
| 302 : profile_(profile), | 273 : profile_(profile), |
| 303 last_operation_status_(SYNC_STATUS_OK), | 274 last_operation_status_(SYNC_STATUS_OK), |
| 304 state_(REMOTE_SERVICE_OK), | 275 state_(REMOTE_SERVICE_OK), |
| 305 sync_enabled_(true), | 276 sync_enabled_(true), |
| 306 largest_fetched_changestamp_(0), | 277 largest_fetched_changestamp_(0), |
| 307 push_notification_registered_(false), | |
| 308 push_notification_enabled_(false), | |
| 309 polling_delay_seconds_(kMinimumPollingDelaySeconds), | 278 polling_delay_seconds_(kMinimumPollingDelaySeconds), |
| 310 may_have_unfetched_changes_(false), | 279 may_have_unfetched_changes_(false), |
| 311 remote_change_processor_(NULL), | 280 remote_change_processor_(NULL), |
| 312 conflict_resolution_(kDefaultPolicy), | 281 conflict_resolution_(kDefaultPolicy), |
| 313 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 282 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
| 314 temporary_file_dir_ = | 283 temporary_file_dir_ = |
| 315 profile->GetPath().Append(kSyncFileSystemDir).Append(kTempDirName); | 284 profile->GetPath().Append(kSyncFileSystemDir).Append(kTempDirName); |
| 316 token_.reset(new TaskToken(AsWeakPtr())); | 285 token_.reset(new TaskToken(AsWeakPtr())); |
| 317 | 286 |
| 318 sync_client_.reset(new DriveFileSyncClient(profile)); | 287 sync_client_.reset(new DriveFileSyncClient(profile)); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 331 } | 300 } |
| 332 | 301 |
| 333 DriveFileSyncService::~DriveFileSyncService() { | 302 DriveFileSyncService::~DriveFileSyncService() { |
| 334 // Invalidate WeakPtr instances here explicitly to notify TaskToken that we | 303 // Invalidate WeakPtr instances here explicitly to notify TaskToken that we |
| 335 // can safely discard the token. | 304 // can safely discard the token. |
| 336 weak_factory_.InvalidateWeakPtrs(); | 305 weak_factory_.InvalidateWeakPtrs(); |
| 337 if (sync_client_) | 306 if (sync_client_) |
| 338 sync_client_->RemoveObserver(this); | 307 sync_client_->RemoveObserver(this); |
| 339 token_.reset(); | 308 token_.reset(); |
| 340 | 309 |
| 341 // Unregister for Drive notifications. | 310 google_apis::DriveNotificationManager* drive_notification_manager = |
| 342 ProfileSyncService* profile_sync_service = | 311 google_apis::DriveNotificationManagerFactory::GetForProfile(profile_); |
| 343 ProfileSyncServiceFactory::GetForProfile(profile_); | 312 DCHECK(drive_notification_manager); |
| 344 if (!profile_sync_service || !push_notification_registered_) { | 313 drive_notification_manager->RemoveObserver(this); |
| 345 return; | |
| 346 } | |
| 347 | |
| 348 // TODO(calvinlo): Revisit this later in Consolidate Drive XMPP Notification | |
| 349 // and Polling Backup into one Class patch. http://crbug/173339. | |
| 350 // Original comment from Kochi about the order this is done in: | |
| 351 // Once DriveSystemService gets started / stopped at runtime, this ID needs to | |
| 352 // be unregistered *before* the handler is unregistered | |
| 353 // as ID persists across browser restarts. | |
| 354 profile_sync_service->UpdateRegisteredInvalidationIds( | |
| 355 this, syncer::ObjectIdSet()); | |
| 356 profile_sync_service->UnregisterInvalidationHandler(this); | |
| 357 } | 314 } |
| 358 | 315 |
| 359 // static | 316 // static |
| 360 scoped_ptr<DriveFileSyncService> DriveFileSyncService::CreateForTesting( | 317 scoped_ptr<DriveFileSyncService> DriveFileSyncService::CreateForTesting( |
| 361 Profile* profile, | 318 Profile* profile, |
| 362 const base::FilePath& base_dir, | 319 const base::FilePath& base_dir, |
| 363 scoped_ptr<DriveFileSyncClientInterface> sync_client, | 320 scoped_ptr<DriveFileSyncClientInterface> sync_client, |
| 364 scoped_ptr<DriveMetadataStore> metadata_store) { | 321 scoped_ptr<DriveMetadataStore> metadata_store) { |
| 365 return make_scoped_ptr(new DriveFileSyncService( | 322 return make_scoped_ptr(new DriveFileSyncService( |
| 366 profile, base_dir, sync_client.Pass(), metadata_store.Pass())); | 323 profile, base_dir, sync_client.Pass(), metadata_store.Pass())); |
| (...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 734 DriveFileSyncService::DriveFileSyncService( | 691 DriveFileSyncService::DriveFileSyncService( |
| 735 Profile* profile, | 692 Profile* profile, |
| 736 const base::FilePath& base_dir, | 693 const base::FilePath& base_dir, |
| 737 scoped_ptr<DriveFileSyncClientInterface> sync_client, | 694 scoped_ptr<DriveFileSyncClientInterface> sync_client, |
| 738 scoped_ptr<DriveMetadataStore> metadata_store) | 695 scoped_ptr<DriveMetadataStore> metadata_store) |
| 739 : profile_(profile), | 696 : profile_(profile), |
| 740 last_operation_status_(SYNC_STATUS_OK), | 697 last_operation_status_(SYNC_STATUS_OK), |
| 741 state_(REMOTE_SERVICE_OK), | 698 state_(REMOTE_SERVICE_OK), |
| 742 sync_enabled_(true), | 699 sync_enabled_(true), |
| 743 largest_fetched_changestamp_(0), | 700 largest_fetched_changestamp_(0), |
| 744 push_notification_registered_(false), | |
| 745 push_notification_enabled_(false), | |
| 746 polling_delay_seconds_(-1), | 701 polling_delay_seconds_(-1), |
| 747 may_have_unfetched_changes_(false), | 702 may_have_unfetched_changes_(false), |
| 748 remote_change_processor_(NULL), | 703 remote_change_processor_(NULL), |
| 749 conflict_resolution_(kDefaultPolicy), | 704 conflict_resolution_(kDefaultPolicy), |
| 750 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 705 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
| 751 DCHECK(profile); | 706 DCHECK(profile); |
| 752 temporary_file_dir_ = base_dir.Append(kTempDirName); | 707 temporary_file_dir_ = base_dir.Append(kTempDirName); |
| 753 | 708 |
| 754 token_.reset(new TaskToken(AsWeakPtr())); | 709 token_.reset(new TaskToken(AsWeakPtr())); |
| 755 sync_client_ = sync_client.Pass(); | 710 sync_client_ = sync_client.Pass(); |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 916 DriveMetadata metadata; | 871 DriveMetadata metadata; |
| 917 const FileSystemURL& url = itr->first; | 872 const FileSystemURL& url = itr->first; |
| 918 const std::string& resource_id = itr->second; | 873 const std::string& resource_id = itr->second; |
| 919 AppendFetchChange(url.origin(), url.path(), resource_id); | 874 AppendFetchChange(url.origin(), url.path(), resource_id); |
| 920 } | 875 } |
| 921 | 876 |
| 922 if (!sync_root_resource_id().empty()) | 877 if (!sync_root_resource_id().empty()) |
| 923 sync_client_->EnsureSyncRootIsNotInMyDrive(sync_root_resource_id()); | 878 sync_client_->EnsureSyncRootIsNotInMyDrive(sync_root_resource_id()); |
| 924 | 879 |
| 925 NotifyTaskDone(status, token.Pass()); | 880 NotifyTaskDone(status, token.Pass()); |
| 926 RegisterDriveNotifications(); | |
| 927 may_have_unfetched_changes_ = true; | 881 may_have_unfetched_changes_ = true; |
| 882 | |
| 883 google_apis::DriveNotificationManager* drive_notification_manager = | |
| 884 google_apis::DriveNotificationManagerFactory::GetForProfile(profile_); | |
| 885 DCHECK(drive_notification_manager); | |
| 886 drive_notification_manager->AddObserver(this); | |
| 928 } | 887 } |
| 929 | 888 |
| 930 void DriveFileSyncService::UpdateRegisteredOrigins() { | 889 void DriveFileSyncService::UpdateRegisteredOrigins() { |
| 931 ExtensionService* extension_service = | 890 ExtensionService* extension_service = |
| 932 extensions::ExtensionSystem::Get(profile_)->extension_service(); | 891 extensions::ExtensionSystem::Get(profile_)->extension_service(); |
| 933 if (!extension_service) | 892 if (!extension_service) |
| 934 return; | 893 return; |
| 935 | 894 |
| 936 // TODO(nhiroki): clean up these loops with similar bodies. | 895 // TODO(nhiroki): clean up these loops with similar bodies. |
| 937 // http://crbug.com/211600 | 896 // http://crbug.com/211600 |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1106 AsWeakPtr(), base::Passed(&token), origin, largest_changestamp)); | 1065 AsWeakPtr(), base::Passed(&token), origin, largest_changestamp)); |
| 1107 return; | 1066 return; |
| 1108 } | 1067 } |
| 1109 | 1068 |
| 1110 // Move |origin| to the incremental sync origin set if the origin has no file. | 1069 // Move |origin| to the incremental sync origin set if the origin has no file. |
| 1111 if (metadata_store_->IsBatchSyncOrigin(origin) && | 1070 if (metadata_store_->IsBatchSyncOrigin(origin) && |
| 1112 !ContainsKey(origin_to_changes_map_, origin)) { | 1071 !ContainsKey(origin_to_changes_map_, origin)) { |
| 1113 metadata_store_->MoveBatchSyncOriginToIncremental(origin); | 1072 metadata_store_->MoveBatchSyncOriginToIncremental(origin); |
| 1114 } | 1073 } |
| 1115 | 1074 |
| 1116 // If this was the last batch sync origin and push_notification is enabled | |
| 1117 // (indicates that we may have longer polling cycle), trigger the first | |
| 1118 // incremental sync on next task cycle. | |
| 1119 if (pending_batch_sync_origins_.empty() && | |
| 1120 push_notification_enabled_) { | |
| 1121 may_have_unfetched_changes_ = true; | |
|
tzik
2013/04/12 02:00:15
Any alternate for this?
calvinlo
2013/04/12 04:42:00
I think in general I want to get rid of the "may_h
tzik
2013/04/12 05:12:46
I think we still need to kick CheckForUpdates arou
calvinlo
2013/04/12 06:44:38
Done. Yeah, I agree, calling CheckForUpdates here
| |
| 1122 } | |
| 1123 | |
| 1124 NotifyTaskDone(SYNC_STATUS_OK, token.Pass()); | 1075 NotifyTaskDone(SYNC_STATUS_OK, token.Pass()); |
| 1125 } | 1076 } |
| 1126 | 1077 |
| 1127 void DriveFileSyncService::DidChangeOriginOnMetadataStore( | 1078 void DriveFileSyncService::DidChangeOriginOnMetadataStore( |
| 1128 scoped_ptr<TaskToken> token, | 1079 scoped_ptr<TaskToken> token, |
| 1129 const SyncStatusCallback& callback, | 1080 const SyncStatusCallback& callback, |
| 1130 SyncStatusCode status) { | 1081 SyncStatusCode status) { |
| 1131 NotifyTaskDone(status, token.Pass()); | 1082 NotifyTaskDone(status, token.Pass()); |
| 1132 callback.Run(status); | 1083 callback.Run(status); |
| 1133 } | 1084 } |
| (...skipping 1050 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2184 return; | 2135 return; |
| 2185 } | 2136 } |
| 2186 | 2137 |
| 2187 if (may_have_unfetched_changes_ && | 2138 if (may_have_unfetched_changes_ && |
| 2188 !metadata_store_->incremental_sync_origins().empty()) { | 2139 !metadata_store_->incremental_sync_origins().empty()) { |
| 2189 FetchChangesForIncrementalSync(); | 2140 FetchChangesForIncrementalSync(); |
| 2190 } | 2141 } |
| 2191 } | 2142 } |
| 2192 | 2143 |
| 2193 void DriveFileSyncService::CheckForUpdates() { | 2144 void DriveFileSyncService::CheckForUpdates() { |
| 2145 // TODO(calvinlo): Try to eliminate may_have_unfetched_changes_ variable. | |
| 2146 may_have_unfetched_changes_ = true; | |
| 2194 MaybeStartFetchChanges(); | 2147 MaybeStartFetchChanges(); |
| 2195 } | 2148 } |
| 2196 | 2149 |
| 2197 void DriveFileSyncService::FetchChangesForIncrementalSync() { | 2150 void DriveFileSyncService::FetchChangesForIncrementalSync() { |
| 2198 scoped_ptr<TaskToken> token(GetToken(FROM_HERE, TASK_TYPE_DRIVE, | 2151 scoped_ptr<TaskToken> token(GetToken(FROM_HERE, TASK_TYPE_DRIVE, |
| 2199 "Fetching remote change list")); | 2152 "Fetching remote change list")); |
| 2200 DCHECK(token); | 2153 DCHECK(token); |
| 2201 DCHECK(may_have_unfetched_changes_); | 2154 DCHECK(may_have_unfetched_changes_); |
| 2202 DCHECK(pending_batch_sync_origins_.empty()); | 2155 DCHECK(pending_batch_sync_origins_.empty()); |
| 2203 DCHECK(!metadata_store_->incremental_sync_origins().empty()); | 2156 DCHECK(!metadata_store_->incremental_sync_origins().empty()); |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2345 if (state_ == REMOTE_SERVICE_TEMPORARY_UNAVAILABLE) { | 2298 if (state_ == REMOTE_SERVICE_TEMPORARY_UNAVAILABLE) { |
| 2346 // If the service state is TEMPORARY_UNAVAILABLE, poll the service | 2299 // If the service state is TEMPORARY_UNAVAILABLE, poll the service |
| 2347 // with a modest duration (but more frequently than | 2300 // with a modest duration (but more frequently than |
| 2348 // kPollingDelaySecondsWithNotification) so that we have a mild chance | 2301 // kPollingDelaySecondsWithNotification) so that we have a mild chance |
| 2349 // to recover the state. | 2302 // to recover the state. |
| 2350 polling_delay_seconds_ = kMaximumPollingDelaySeconds; | 2303 polling_delay_seconds_ = kMaximumPollingDelaySeconds; |
| 2351 polling_timer_.Stop(); | 2304 polling_timer_.Stop(); |
| 2352 return; | 2305 return; |
| 2353 } | 2306 } |
| 2354 | 2307 |
| 2355 if (push_notification_enabled_) { | |
| 2356 polling_delay_seconds_ = kPollingDelaySecondsWithNotification; | |
| 2357 return; | |
| 2358 } | |
| 2359 | |
| 2360 int64 old_delay = polling_delay_seconds_; | 2308 int64 old_delay = polling_delay_seconds_; |
| 2361 | 2309 |
| 2362 // Push notifications off. | 2310 // Push notifications off. |
| 2363 polling_delay_seconds_ = std::min(new_delay_sec, kMaximumPollingDelaySeconds); | 2311 polling_delay_seconds_ = std::min(new_delay_sec, kMaximumPollingDelaySeconds); |
| 2364 | 2312 |
| 2365 if (polling_delay_seconds_ < old_delay) | 2313 if (polling_delay_seconds_ < old_delay) |
| 2366 polling_timer_.Stop(); | 2314 polling_timer_.Stop(); |
| 2367 } | 2315 } |
| 2368 | 2316 |
| 2369 bool DriveFileSyncService::IsDriveNotificationSupported() { | |
| 2370 // TODO(calvinlo): A invalidation ID can only be registered to one handler. | |
| 2371 // Therefore ChromeOS and SyncFS cannot both use XMPP notifications until | |
| 2372 // (http://crbug.com/173339) is completed. | |
| 2373 // For now, disable XMPP notifications for SyncFC on ChromeOS to guarantee | |
| 2374 // that ChromeOS's file manager can register itself to the invalidationID. | |
| 2375 | |
| 2376 #if defined(OS_CHROMEOS) | |
| 2377 return false; | |
| 2378 #else | |
| 2379 return true; | |
| 2380 #endif | |
| 2381 } | |
| 2382 | |
| 2383 // Register for Google Drive invalidation notifications through XMPP. | |
| 2384 void DriveFileSyncService::RegisterDriveNotifications() { | |
| 2385 // Push notification registration might have already occurred if called from | |
| 2386 // a different extension. | |
| 2387 if (!IsDriveNotificationSupported() || push_notification_registered_) | |
| 2388 return; | |
| 2389 | |
| 2390 ProfileSyncService* profile_sync_service = | |
| 2391 ProfileSyncServiceFactory::GetForProfile(profile_); | |
| 2392 if (!profile_sync_service) | |
| 2393 return; | |
| 2394 | |
| 2395 profile_sync_service->RegisterInvalidationHandler(this); | |
| 2396 syncer::ObjectIdSet ids; | |
| 2397 ids.insert(invalidation::ObjectId( | |
| 2398 ipc::invalidation::ObjectSource::COSMO_CHANGELOG, | |
| 2399 kDriveInvalidationObjectId)); | |
| 2400 profile_sync_service->UpdateRegisteredInvalidationIds(this, ids); | |
| 2401 push_notification_registered_ = true; | |
| 2402 SetPushNotificationEnabled(profile_sync_service->GetInvalidatorState()); | |
| 2403 } | |
| 2404 | |
| 2405 void DriveFileSyncService::SetPushNotificationEnabled( | |
| 2406 syncer::InvalidatorState state) { | |
| 2407 push_notification_enabled_ = (state == syncer::INVALIDATIONS_ENABLED); | |
| 2408 if (!push_notification_enabled_) | |
| 2409 return; | |
| 2410 | |
| 2411 // Push notifications are enabled so reset polling timer. | |
| 2412 UpdatePollingDelay(kPollingDelaySecondsWithNotification); | |
| 2413 } | |
| 2414 | |
| 2415 void DriveFileSyncService::NotifyObserversFileStatusChanged( | 2317 void DriveFileSyncService::NotifyObserversFileStatusChanged( |
| 2416 const FileSystemURL& url, | 2318 const FileSystemURL& url, |
| 2417 SyncFileStatus sync_status, | 2319 SyncFileStatus sync_status, |
| 2418 SyncAction action_taken, | 2320 SyncAction action_taken, |
| 2419 SyncDirection direction) { | 2321 SyncDirection direction) { |
| 2420 if (sync_status != SYNC_FILE_STATUS_SYNCED) { | 2322 if (sync_status != SYNC_FILE_STATUS_SYNCED) { |
| 2421 DCHECK_EQ(SYNC_ACTION_NONE, action_taken); | 2323 DCHECK_EQ(SYNC_ACTION_NONE, action_taken); |
| 2422 DCHECK_EQ(SYNC_DIRECTION_NONE, direction); | 2324 DCHECK_EQ(SYNC_DIRECTION_NONE, direction); |
| 2423 } | 2325 } |
| 2424 | 2326 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2491 pending_batch_sync_origins_.insert(origin); | 2393 pending_batch_sync_origins_.insert(origin); |
| 2492 } | 2394 } |
| 2493 callback.Run(status, resource_id); | 2395 callback.Run(status, resource_id); |
| 2494 } | 2396 } |
| 2495 | 2397 |
| 2496 std::string DriveFileSyncService::sync_root_resource_id() { | 2398 std::string DriveFileSyncService::sync_root_resource_id() { |
| 2497 return metadata_store_->sync_root_directory(); | 2399 return metadata_store_->sync_root_directory(); |
| 2498 } | 2400 } |
| 2499 | 2401 |
| 2500 } // namespace sync_file_system | 2402 } // namespace sync_file_system |
| OLD | NEW |