| 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 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 bool encrypt_everything) OVERRIDE; | 324 bool encrypt_everything) OVERRIDE; |
| 325 | 325 |
| 326 // SyncNotifierObserver implementation. | 326 // SyncNotifierObserver implementation. |
| 327 virtual void OnNotificationStateChange( | 327 virtual void OnNotificationStateChange( |
| 328 bool notifications_enabled) OVERRIDE; | 328 bool notifications_enabled) OVERRIDE; |
| 329 | 329 |
| 330 virtual void OnIncomingNotification( | 330 virtual void OnIncomingNotification( |
| 331 const syncable::ModelTypePayloadMap& type_payloads, | 331 const syncable::ModelTypePayloadMap& type_payloads, |
| 332 sync_notifier::IncomingNotificationSource source) OVERRIDE; | 332 sync_notifier::IncomingNotificationSource source) OVERRIDE; |
| 333 | 333 |
| 334 virtual void StoreState(const std::string& cookie) OVERRIDE; | |
| 335 | |
| 336 void AddObserver(SyncManager::Observer* observer); | 334 void AddObserver(SyncManager::Observer* observer); |
| 337 void RemoveObserver(SyncManager::Observer* observer); | 335 void RemoveObserver(SyncManager::Observer* observer); |
| 338 | 336 |
| 339 // Accessors for the private members. | 337 // Accessors for the private members. |
| 340 syncable::Directory* directory() { return share_.directory.get(); } | 338 syncable::Directory* directory() { return share_.directory.get(); } |
| 341 SyncAPIServerConnectionManager* connection_manager() { | 339 SyncAPIServerConnectionManager* connection_manager() { |
| 342 return connection_manager_.get(); | 340 return connection_manager_.get(); |
| 343 } | 341 } |
| 344 SyncScheduler* scheduler() const { return scheduler_.get(); } | 342 SyncScheduler* scheduler() const { return scheduler_.get(); } |
| 345 UserShare* GetUserShare() { | 343 UserShare* GetUserShare() { |
| (...skipping 858 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1204 std::string unique_id = directory()->cache_guid(); | 1202 std::string unique_id = directory()->cache_guid(); |
| 1205 std::string state = directory()->GetNotificationState(); | 1203 std::string state = directory()->GetNotificationState(); |
| 1206 DVLOG(1) << "Read notification unique ID: " << unique_id; | 1204 DVLOG(1) << "Read notification unique ID: " << unique_id; |
| 1207 if (VLOG_IS_ON(1)) { | 1205 if (VLOG_IS_ON(1)) { |
| 1208 std::string encoded_state; | 1206 std::string encoded_state; |
| 1209 base::Base64Encode(state, &encoded_state); | 1207 base::Base64Encode(state, &encoded_state); |
| 1210 DVLOG(1) << "Read notification state: " << encoded_state; | 1208 DVLOG(1) << "Read notification state: " << encoded_state; |
| 1211 } | 1209 } |
| 1212 allstatus_.SetUniqueId(unique_id); | 1210 allstatus_.SetUniqueId(unique_id); |
| 1213 sync_notifier_->SetUniqueId(unique_id); | 1211 sync_notifier_->SetUniqueId(unique_id); |
| 1214 sync_notifier_->SetState(state); | 1212 // TODO(tim): Remove once invalidation state has been migrated to new |
| 1213 // InvalidationStateTracker store. Bug 124140. |
| 1214 sync_notifier_->SetStateDeprecated(state); |
| 1215 | 1215 |
| 1216 UpdateCredentials(credentials); | 1216 UpdateCredentials(credentials); |
| 1217 UpdateEnabledTypes(); | 1217 UpdateEnabledTypes(); |
| 1218 return true; | 1218 return true; |
| 1219 } | 1219 } |
| 1220 | 1220 |
| 1221 void SyncManager::SyncInternal::UpdateCredentials( | 1221 void SyncManager::SyncInternal::UpdateCredentials( |
| 1222 const SyncCredentials& credentials) { | 1222 const SyncCredentials& credentials) { |
| 1223 DCHECK(thread_checker_.CalledOnValidThread()); | 1223 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1224 DCHECK_EQ(credentials.email, share_.name); | 1224 DCHECK_EQ(credentials.email, share_.name); |
| (...skipping 1185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2410 } | 2410 } |
| 2411 details.SetString("source", (source == sync_notifier::LOCAL_NOTIFICATION) ? | 2411 details.SetString("source", (source == sync_notifier::LOCAL_NOTIFICATION) ? |
| 2412 "LOCAL_NOTIFICATION" : "REMOTE_NOTIFICATION"); | 2412 "LOCAL_NOTIFICATION" : "REMOTE_NOTIFICATION"); |
| 2413 js_event_handler_.Call(FROM_HERE, | 2413 js_event_handler_.Call(FROM_HERE, |
| 2414 &JsEventHandler::HandleJsEvent, | 2414 &JsEventHandler::HandleJsEvent, |
| 2415 "onIncomingNotification", | 2415 "onIncomingNotification", |
| 2416 JsEventDetails(&details)); | 2416 JsEventDetails(&details)); |
| 2417 } | 2417 } |
| 2418 } | 2418 } |
| 2419 | 2419 |
| 2420 void SyncManager::SyncInternal::StoreState( | |
| 2421 const std::string& state) { | |
| 2422 if (!directory()) { | |
| 2423 LOG(ERROR) << "Could not write notification state"; | |
| 2424 // TODO(akalin): Propagate result callback all the way to this | |
| 2425 // function and call it with "false" to signal failure. | |
| 2426 return; | |
| 2427 } | |
| 2428 if (VLOG_IS_ON(1)) { | |
| 2429 std::string encoded_state; | |
| 2430 base::Base64Encode(state, &encoded_state); | |
| 2431 DVLOG(1) << "Writing notification state: " << encoded_state; | |
| 2432 } | |
| 2433 directory()->SetNotificationState(state); | |
| 2434 directory()->SaveChanges(); | |
| 2435 } | |
| 2436 | |
| 2437 void SyncManager::SyncInternal::AddObserver( | 2420 void SyncManager::SyncInternal::AddObserver( |
| 2438 SyncManager::Observer* observer) { | 2421 SyncManager::Observer* observer) { |
| 2439 observers_.AddObserver(observer); | 2422 observers_.AddObserver(observer); |
| 2440 } | 2423 } |
| 2441 | 2424 |
| 2442 void SyncManager::SyncInternal::RemoveObserver( | 2425 void SyncManager::SyncInternal::RemoveObserver( |
| 2443 SyncManager::Observer* observer) { | 2426 SyncManager::Observer* observer) { |
| 2444 observers_.RemoveObserver(observer); | 2427 observers_.RemoveObserver(observer); |
| 2445 } | 2428 } |
| 2446 | 2429 |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2572 share->directory->GetDownloadProgress(i.Get(), &marker); | 2555 share->directory->GetDownloadProgress(i.Get(), &marker); |
| 2573 | 2556 |
| 2574 if (marker.token().empty()) | 2557 if (marker.token().empty()) |
| 2575 result.Put(i.Get()); | 2558 result.Put(i.Get()); |
| 2576 | 2559 |
| 2577 } | 2560 } |
| 2578 return result; | 2561 return result; |
| 2579 } | 2562 } |
| 2580 | 2563 |
| 2581 } // namespace sync_api | 2564 } // namespace sync_api |
| OLD | NEW |