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

Side by Side Diff: sync/internal_api/sync_manager.cc

Issue 10545170: [Sync] Propagate XMPP auth errors to SyncNotifierObservers (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix compile error Created 8 years, 6 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 "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 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 311
312 // Open the directory named with username_for_share 312 // Open the directory named with username_for_share
313 bool OpenDirectory(); 313 bool OpenDirectory();
314 314
315 // Cryptographer::Observer implementation. 315 // Cryptographer::Observer implementation.
316 virtual void OnEncryptedTypesChanged( 316 virtual void OnEncryptedTypesChanged(
317 syncable::ModelTypeSet encrypted_types, 317 syncable::ModelTypeSet encrypted_types,
318 bool encrypt_everything) OVERRIDE; 318 bool encrypt_everything) OVERRIDE;
319 319
320 // SyncNotifierObserver implementation. 320 // SyncNotifierObserver implementation.
321 virtual void OnNotificationStateChange(
322 bool notifications_enabled) OVERRIDE;
323
324 virtual void OnIncomingNotification( 321 virtual void OnIncomingNotification(
325 const syncable::ModelTypePayloadMap& type_payloads, 322 const syncable::ModelTypePayloadMap& type_payloads,
326 sync_notifier::IncomingNotificationSource source) OVERRIDE; 323 sync_notifier::IncomingNotificationSource source) OVERRIDE;
324 virtual void OnSyncNotifierStateChange(
325 sync_notifier::SyncNotifierState sync_notifier_state) OVERRIDE;
327 326
328 void AddObserver(SyncManager::Observer* observer); 327 void AddObserver(SyncManager::Observer* observer);
329 void RemoveObserver(SyncManager::Observer* observer); 328 void RemoveObserver(SyncManager::Observer* observer);
330 329
331 // Accessors for the private members. 330 // Accessors for the private members.
332 syncable::Directory* directory() { return share_.directory.get(); } 331 syncable::Directory* directory() { return share_.directory.get(); }
333 SyncAPIServerConnectionManager* connection_manager() { 332 SyncAPIServerConnectionManager* connection_manager() {
334 return connection_manager_.get(); 333 return connection_manager_.get();
335 } 334 }
336 SyncSessionContext* session_context() { return session_context_.get(); } 335 SyncSessionContext* session_context() { return session_context_.get(); }
(...skipping 1951 matching lines...) Expand 10 before | Expand all | Expand 10 after
2288 2287
2289 void SyncManager::SyncInternal::OnEncryptedTypesChanged( 2288 void SyncManager::SyncInternal::OnEncryptedTypesChanged(
2290 syncable::ModelTypeSet encrypted_types, 2289 syncable::ModelTypeSet encrypted_types,
2291 bool encrypt_everything) { 2290 bool encrypt_everything) {
2292 // NOTE: We're in a transaction. 2291 // NOTE: We're in a transaction.
2293 FOR_EACH_OBSERVER( 2292 FOR_EACH_OBSERVER(
2294 SyncManager::Observer, observers_, 2293 SyncManager::Observer, observers_,
2295 OnEncryptedTypesChanged(encrypted_types, encrypt_everything)); 2294 OnEncryptedTypesChanged(encrypted_types, encrypt_everything));
2296 } 2295 }
2297 2296
2298 void SyncManager::SyncInternal::OnNotificationStateChange( 2297 void SyncManager::SyncInternal::UpdateNotificationInfo(
2299 bool notifications_enabled) { 2298 const syncable::ModelTypePayloadMap& type_payloads) {
2300 DVLOG(1) << "P2P: Notifications enabled = " 2299 for (syncable::ModelTypePayloadMap::const_iterator it = type_payloads.begin();
2301 << (notifications_enabled ? "true" : "false"); 2300 it != type_payloads.end(); ++it) {
2301 NotificationInfo* info = &notification_info_map_[it->first];
2302 info->total_count++;
2303 info->payload = it->second;
2304 }
2305 }
2306
2307 void SyncManager::SyncInternal::OnSyncNotifierStateChange(
2308 sync_notifier::SyncNotifierState sync_notifier_state) {
2309 DVLOG(1) << "SyncNotifierState: "
2310 << sync_notifier::SyncNotifierStateToString(
2311 sync_notifier_state);
2312 const bool notifications_enabled =
2313 (sync_notifier_state == sync_notifier::NOTIFICATIONS_ON);
2302 allstatus_.SetNotificationsEnabled(notifications_enabled); 2314 allstatus_.SetNotificationsEnabled(notifications_enabled);
2303 if (scheduler()) { 2315 if (scheduler()) {
2304 scheduler()->set_notifications_enabled(notifications_enabled); 2316 scheduler()->set_notifications_enabled(notifications_enabled);
2305 } 2317 }
2306 if (js_event_handler_.IsInitialized()) { 2318 if (js_event_handler_.IsInitialized()) {
2307 DictionaryValue details; 2319 DictionaryValue details;
2308 details.Set("enabled", Value::CreateBooleanValue(notifications_enabled)); 2320 details.Set("enabled", Value::CreateBooleanValue(notifications_enabled));
2309 js_event_handler_.Call(FROM_HERE, 2321 js_event_handler_.Call(FROM_HERE,
2310 &JsEventHandler::HandleJsEvent, 2322 &JsEventHandler::HandleJsEvent,
2311 "onNotificationStateChange", 2323 "onNotificationStateChange",
2312 JsEventDetails(&details)); 2324 JsEventDetails(&details));
2313 } 2325 }
2314 } 2326 // TODO(akalin): Treat a CREDENTIALS_REJECTED state as an auth
2315 2327 // error.
2316 void SyncManager::SyncInternal::UpdateNotificationInfo(
2317 const syncable::ModelTypePayloadMap& type_payloads) {
2318 for (syncable::ModelTypePayloadMap::const_iterator it = type_payloads.begin();
2319 it != type_payloads.end(); ++it) {
2320 NotificationInfo* info = &notification_info_map_[it->first];
2321 info->total_count++;
2322 info->payload = it->second;
2323 }
2324 } 2328 }
2325 2329
2326 void SyncManager::SyncInternal::OnIncomingNotification( 2330 void SyncManager::SyncInternal::OnIncomingNotification(
2327 const syncable::ModelTypePayloadMap& type_payloads, 2331 const syncable::ModelTypePayloadMap& type_payloads,
2328 sync_notifier::IncomingNotificationSource source) { 2332 sync_notifier::IncomingNotificationSource source) {
2329 DCHECK(thread_checker_.CalledOnValidThread()); 2333 DCHECK(thread_checker_.CalledOnValidThread());
2330 if (source == sync_notifier::LOCAL_NOTIFICATION) { 2334 if (source == sync_notifier::LOCAL_NOTIFICATION) {
2331 if (scheduler()) { 2335 if (scheduler()) {
2332 scheduler()->ScheduleNudgeWithPayloadsAsync( 2336 scheduler()->ScheduleNudgeWithPayloadsAsync(
2333 TimeDelta::FromMilliseconds(kSyncRefreshDelayMsec), 2337 TimeDelta::FromMilliseconds(kSyncRefreshDelayMsec),
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
2427 found_experiment = true; 2431 found_experiment = true;
2428 } 2432 }
2429 return found_experiment; 2433 return found_experiment;
2430 } 2434 }
2431 2435
2432 bool SyncManager::HasUnsyncedItems() const { 2436 bool SyncManager::HasUnsyncedItems() const {
2433 sync_api::ReadTransaction trans(FROM_HERE, GetUserShare()); 2437 sync_api::ReadTransaction trans(FROM_HERE, GetUserShare());
2434 return (trans.GetWrappedTrans()->directory()->unsynced_entity_count() != 0); 2438 return (trans.GetWrappedTrans()->directory()->unsynced_entity_count() != 0);
2435 } 2439 }
2436 2440
2437 void SyncManager::TriggerOnNotificationStateChangeForTest( 2441 void SyncManager::TriggerOnSyncNotifierStateChangeForTest(
2438 bool notifications_enabled) { 2442 sync_notifier::SyncNotifierState sync_notifier_state) {
2439 DCHECK(thread_checker_.CalledOnValidThread()); 2443 DCHECK(thread_checker_.CalledOnValidThread());
2440 data_->OnNotificationStateChange(notifications_enabled); 2444 data_->OnSyncNotifierStateChange(sync_notifier_state);
2441 } 2445 }
2442 2446
2443 void SyncManager::TriggerOnIncomingNotificationForTest( 2447 void SyncManager::TriggerOnIncomingNotificationForTest(
2444 ModelTypeSet model_types) { 2448 ModelTypeSet model_types) {
2445 DCHECK(thread_checker_.CalledOnValidThread()); 2449 DCHECK(thread_checker_.CalledOnValidThread());
2446 syncable::ModelTypePayloadMap model_types_with_payloads = 2450 syncable::ModelTypePayloadMap model_types_with_payloads =
2447 syncable::ModelTypePayloadMapFromEnumSet(model_types, 2451 syncable::ModelTypePayloadMapFromEnumSet(model_types,
2448 std::string()); 2452 std::string());
2449 2453
2450 data_->OnIncomingNotification(model_types_with_payloads, 2454 data_->OnIncomingNotification(model_types_with_payloads,
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
2502 share->directory->GetDownloadProgress(i.Get(), &marker); 2506 share->directory->GetDownloadProgress(i.Get(), &marker);
2503 2507
2504 if (marker.token().empty()) 2508 if (marker.token().empty())
2505 result.Put(i.Get()); 2509 result.Put(i.Get());
2506 2510
2507 } 2511 }
2508 return result; 2512 return result;
2509 } 2513 }
2510 2514
2511 } // namespace sync_api 2515 } // namespace sync_api
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698