| 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 "sync/internal_api/sync_manager.h" | 5 #include "sync/internal_api/sync_manager.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 bool encrypt_everything) OVERRIDE; | 318 bool encrypt_everything) OVERRIDE; |
| 319 | 319 |
| 320 // SyncNotifierObserver implementation. | 320 // SyncNotifierObserver implementation. |
| 321 virtual void OnNotificationStateChange( | 321 virtual void OnNotificationStateChange( |
| 322 bool notifications_enabled) OVERRIDE; | 322 bool notifications_enabled) OVERRIDE; |
| 323 | 323 |
| 324 virtual void OnIncomingNotification( | 324 virtual void OnIncomingNotification( |
| 325 const syncable::ModelTypePayloadMap& type_payloads, | 325 const syncable::ModelTypePayloadMap& type_payloads, |
| 326 sync_notifier::IncomingNotificationSource source) OVERRIDE; | 326 sync_notifier::IncomingNotificationSource source) OVERRIDE; |
| 327 | 327 |
| 328 virtual void StoreState(const std::string& cookie) OVERRIDE; | |
| 329 | |
| 330 void AddObserver(SyncManager::Observer* observer); | 328 void AddObserver(SyncManager::Observer* observer); |
| 331 void RemoveObserver(SyncManager::Observer* observer); | 329 void RemoveObserver(SyncManager::Observer* observer); |
| 332 | 330 |
| 333 // Accessors for the private members. | 331 // Accessors for the private members. |
| 334 syncable::Directory* directory() { return share_.directory.get(); } | 332 syncable::Directory* directory() { return share_.directory.get(); } |
| 335 SyncAPIServerConnectionManager* connection_manager() { | 333 SyncAPIServerConnectionManager* connection_manager() { |
| 336 return connection_manager_.get(); | 334 return connection_manager_.get(); |
| 337 } | 335 } |
| 338 SyncScheduler* scheduler() const { return scheduler_.get(); } | 336 SyncScheduler* scheduler() const { return scheduler_.get(); } |
| 339 UserShare* GetUserShare() { | 337 UserShare* GetUserShare() { |
| (...skipping 844 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1184 std::string unique_id = directory()->cache_guid(); | 1182 std::string unique_id = directory()->cache_guid(); |
| 1185 std::string state = directory()->GetNotificationState(); | 1183 std::string state = directory()->GetNotificationState(); |
| 1186 DVLOG(1) << "Read notification unique ID: " << unique_id; | 1184 DVLOG(1) << "Read notification unique ID: " << unique_id; |
| 1187 if (VLOG_IS_ON(1)) { | 1185 if (VLOG_IS_ON(1)) { |
| 1188 std::string encoded_state; | 1186 std::string encoded_state; |
| 1189 base::Base64Encode(state, &encoded_state); | 1187 base::Base64Encode(state, &encoded_state); |
| 1190 DVLOG(1) << "Read notification state: " << encoded_state; | 1188 DVLOG(1) << "Read notification state: " << encoded_state; |
| 1191 } | 1189 } |
| 1192 allstatus_.SetUniqueId(unique_id); | 1190 allstatus_.SetUniqueId(unique_id); |
| 1193 sync_notifier_->SetUniqueId(unique_id); | 1191 sync_notifier_->SetUniqueId(unique_id); |
| 1194 sync_notifier_->SetState(state); | 1192 // TODO(tim): Remove once invalidation state has been migrated to new |
| 1193 // InvalidationStateTracker store. Bug 124140. |
| 1194 sync_notifier_->SetStateDeprecated(state); |
| 1195 | 1195 |
| 1196 UpdateCredentials(credentials); | 1196 UpdateCredentials(credentials); |
| 1197 UpdateEnabledTypes(); | 1197 UpdateEnabledTypes(); |
| 1198 return true; | 1198 return true; |
| 1199 } | 1199 } |
| 1200 | 1200 |
| 1201 void SyncManager::SyncInternal::UpdateCredentials( | 1201 void SyncManager::SyncInternal::UpdateCredentials( |
| 1202 const SyncCredentials& credentials) { | 1202 const SyncCredentials& credentials) { |
| 1203 DCHECK(thread_checker_.CalledOnValidThread()); | 1203 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1204 DCHECK_EQ(credentials.email, share_.name); | 1204 DCHECK_EQ(credentials.email, share_.name); |
| (...skipping 1163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2368 } | 2368 } |
| 2369 details.SetString("source", (source == sync_notifier::LOCAL_NOTIFICATION) ? | 2369 details.SetString("source", (source == sync_notifier::LOCAL_NOTIFICATION) ? |
| 2370 "LOCAL_NOTIFICATION" : "REMOTE_NOTIFICATION"); | 2370 "LOCAL_NOTIFICATION" : "REMOTE_NOTIFICATION"); |
| 2371 js_event_handler_.Call(FROM_HERE, | 2371 js_event_handler_.Call(FROM_HERE, |
| 2372 &JsEventHandler::HandleJsEvent, | 2372 &JsEventHandler::HandleJsEvent, |
| 2373 "onIncomingNotification", | 2373 "onIncomingNotification", |
| 2374 JsEventDetails(&details)); | 2374 JsEventDetails(&details)); |
| 2375 } | 2375 } |
| 2376 } | 2376 } |
| 2377 | 2377 |
| 2378 void SyncManager::SyncInternal::StoreState( | |
| 2379 const std::string& state) { | |
| 2380 if (!directory()) { | |
| 2381 LOG(ERROR) << "Could not write notification state"; | |
| 2382 // TODO(akalin): Propagate result callback all the way to this | |
| 2383 // function and call it with "false" to signal failure. | |
| 2384 return; | |
| 2385 } | |
| 2386 if (VLOG_IS_ON(1)) { | |
| 2387 std::string encoded_state; | |
| 2388 base::Base64Encode(state, &encoded_state); | |
| 2389 DVLOG(1) << "Writing notification state: " << encoded_state; | |
| 2390 } | |
| 2391 directory()->SetNotificationState(state); | |
| 2392 directory()->SaveChanges(); | |
| 2393 } | |
| 2394 | |
| 2395 void SyncManager::SyncInternal::AddObserver( | 2378 void SyncManager::SyncInternal::AddObserver( |
| 2396 SyncManager::Observer* observer) { | 2379 SyncManager::Observer* observer) { |
| 2397 observers_.AddObserver(observer); | 2380 observers_.AddObserver(observer); |
| 2398 } | 2381 } |
| 2399 | 2382 |
| 2400 void SyncManager::SyncInternal::RemoveObserver( | 2383 void SyncManager::SyncInternal::RemoveObserver( |
| 2401 SyncManager::Observer* observer) { | 2384 SyncManager::Observer* observer) { |
| 2402 observers_.RemoveObserver(observer); | 2385 observers_.RemoveObserver(observer); |
| 2403 } | 2386 } |
| 2404 | 2387 |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2526 share->directory->GetDownloadProgress(i.Get(), &marker); | 2509 share->directory->GetDownloadProgress(i.Get(), &marker); |
| 2527 | 2510 |
| 2528 if (marker.token().empty()) | 2511 if (marker.token().empty()) |
| 2529 result.Put(i.Get()); | 2512 result.Put(i.Get()); |
| 2530 | 2513 |
| 2531 } | 2514 } |
| 2532 return result; | 2515 return result; |
| 2533 } | 2516 } |
| 2534 | 2517 |
| 2535 } // namespace sync_api | 2518 } // namespace sync_api |
| OLD | NEW |