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/public/sync_manager.h" | 5 #include "sync/internal_api/public/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 29 matching lines...) Expand all Loading... |
40 #include "sync/internal_api/public/util/experiments.h" | 40 #include "sync/internal_api/public/util/experiments.h" |
41 #include "sync/internal_api/public/write_node.h" | 41 #include "sync/internal_api/public/write_node.h" |
42 #include "sync/internal_api/public/write_transaction.h" | 42 #include "sync/internal_api/public/write_transaction.h" |
43 #include "sync/internal_api/syncapi_internal.h" | 43 #include "sync/internal_api/syncapi_internal.h" |
44 #include "sync/internal_api/syncapi_server_connection_manager.h" | 44 #include "sync/internal_api/syncapi_server_connection_manager.h" |
45 #include "sync/js/js_arg_list.h" | 45 #include "sync/js/js_arg_list.h" |
46 #include "sync/js/js_backend.h" | 46 #include "sync/js/js_backend.h" |
47 #include "sync/js/js_event_details.h" | 47 #include "sync/js/js_event_details.h" |
48 #include "sync/js/js_event_handler.h" | 48 #include "sync/js/js_event_handler.h" |
49 #include "sync/js/js_reply_handler.h" | 49 #include "sync/js/js_reply_handler.h" |
| 50 #include "sync/notifier/notifications_disabled_reason.h" |
50 #include "sync/notifier/sync_notifier.h" | 51 #include "sync/notifier/sync_notifier.h" |
51 #include "sync/notifier/sync_notifier_observer.h" | 52 #include "sync/notifier/sync_notifier_observer.h" |
52 #include "sync/protocol/encryption.pb.h" | 53 #include "sync/protocol/encryption.pb.h" |
53 #include "sync/protocol/proto_value_conversions.h" | 54 #include "sync/protocol/proto_value_conversions.h" |
54 #include "sync/protocol/sync.pb.h" | 55 #include "sync/protocol/sync.pb.h" |
55 #include "sync/syncable/directory_change_delegate.h" | 56 #include "sync/syncable/directory_change_delegate.h" |
56 #include "sync/syncable/syncable.h" | 57 #include "sync/syncable/syncable.h" |
57 #include "sync/util/cryptographer.h" | 58 #include "sync/util/cryptographer.h" |
58 #include "sync/util/get_session_name.h" | 59 #include "sync/util/get_session_name.h" |
59 #include "sync/util/time.h" | 60 #include "sync/util/time.h" |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 | 316 |
316 // Open the directory named with username_for_share | 317 // Open the directory named with username_for_share |
317 bool OpenDirectory(); | 318 bool OpenDirectory(); |
318 | 319 |
319 // Cryptographer::Observer implementation. | 320 // Cryptographer::Observer implementation. |
320 virtual void OnEncryptedTypesChanged( | 321 virtual void OnEncryptedTypesChanged( |
321 syncable::ModelTypeSet encrypted_types, | 322 syncable::ModelTypeSet encrypted_types, |
322 bool encrypt_everything) OVERRIDE; | 323 bool encrypt_everything) OVERRIDE; |
323 | 324 |
324 // SyncNotifierObserver implementation. | 325 // SyncNotifierObserver implementation. |
325 virtual void OnNotificationStateChange( | 326 virtual void OnNotificationsEnabled() OVERRIDE; |
326 bool notifications_enabled) OVERRIDE; | 327 virtual void OnNotificationsDisabled( |
327 | 328 sync_notifier::NotificationsDisabledReason reason) OVERRIDE; |
328 virtual void OnIncomingNotification( | 329 virtual void OnIncomingNotification( |
329 const syncable::ModelTypePayloadMap& type_payloads, | 330 const syncable::ModelTypePayloadMap& type_payloads, |
330 sync_notifier::IncomingNotificationSource source) OVERRIDE; | 331 sync_notifier::IncomingNotificationSource source) OVERRIDE; |
331 | 332 |
332 void AddObserver(SyncManager::Observer* observer); | 333 void AddObserver(SyncManager::Observer* observer); |
333 void RemoveObserver(SyncManager::Observer* observer); | 334 void RemoveObserver(SyncManager::Observer* observer); |
334 | 335 |
335 // Accessors for the private members. | 336 // Accessors for the private members. |
336 syncable::Directory* directory() { return share_.directory.get(); } | 337 syncable::Directory* directory() { return share_.directory.get(); } |
337 SyncAPIServerConnectionManager* connection_manager() { | 338 SyncAPIServerConnectionManager* connection_manager() { |
(...skipping 1940 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2278 | 2279 |
2279 void SyncManager::SyncInternal::OnEncryptedTypesChanged( | 2280 void SyncManager::SyncInternal::OnEncryptedTypesChanged( |
2280 syncable::ModelTypeSet encrypted_types, | 2281 syncable::ModelTypeSet encrypted_types, |
2281 bool encrypt_everything) { | 2282 bool encrypt_everything) { |
2282 // NOTE: We're in a transaction. | 2283 // NOTE: We're in a transaction. |
2283 FOR_EACH_OBSERVER( | 2284 FOR_EACH_OBSERVER( |
2284 SyncManager::Observer, observers_, | 2285 SyncManager::Observer, observers_, |
2285 OnEncryptedTypesChanged(encrypted_types, encrypt_everything)); | 2286 OnEncryptedTypesChanged(encrypted_types, encrypt_everything)); |
2286 } | 2287 } |
2287 | 2288 |
2288 void SyncManager::SyncInternal::OnNotificationStateChange( | 2289 void SyncManager::SyncInternal::UpdateNotificationInfo( |
2289 bool notifications_enabled) { | 2290 const syncable::ModelTypePayloadMap& type_payloads) { |
2290 DVLOG(1) << "P2P: Notifications enabled = " | 2291 for (syncable::ModelTypePayloadMap::const_iterator it = type_payloads.begin(); |
2291 << (notifications_enabled ? "true" : "false"); | 2292 it != type_payloads.end(); ++it) { |
2292 allstatus_.SetNotificationsEnabled(notifications_enabled); | 2293 NotificationInfo* info = ¬ification_info_map_[it->first]; |
| 2294 info->total_count++; |
| 2295 info->payload = it->second; |
| 2296 } |
| 2297 } |
| 2298 |
| 2299 void SyncManager::SyncInternal::OnNotificationsEnabled() { |
| 2300 DVLOG(1) << "Notifications enabled"; |
| 2301 allstatus_.SetNotificationsEnabled(true); |
2293 if (scheduler()) { | 2302 if (scheduler()) { |
2294 scheduler()->set_notifications_enabled(notifications_enabled); | 2303 scheduler()->set_notifications_enabled(true); |
2295 } | 2304 } |
| 2305 // TODO(akalin): Separate onNotificationStateChange into |
| 2306 // enabled/disabled events. |
2296 if (js_event_handler_.IsInitialized()) { | 2307 if (js_event_handler_.IsInitialized()) { |
2297 DictionaryValue details; | 2308 DictionaryValue details; |
2298 details.Set("enabled", Value::CreateBooleanValue(notifications_enabled)); | 2309 details.Set("enabled", Value::CreateBooleanValue(true)); |
2299 js_event_handler_.Call(FROM_HERE, | 2310 js_event_handler_.Call(FROM_HERE, |
2300 &JsEventHandler::HandleJsEvent, | 2311 &JsEventHandler::HandleJsEvent, |
2301 "onNotificationStateChange", | 2312 "onNotificationStateChange", |
2302 JsEventDetails(&details)); | 2313 JsEventDetails(&details)); |
2303 } | 2314 } |
2304 } | 2315 } |
2305 | 2316 |
2306 void SyncManager::SyncInternal::UpdateNotificationInfo( | 2317 void SyncManager::SyncInternal::OnNotificationsDisabled( |
2307 const syncable::ModelTypePayloadMap& type_payloads) { | 2318 sync_notifier::NotificationsDisabledReason reason) { |
2308 for (syncable::ModelTypePayloadMap::const_iterator it = type_payloads.begin(); | 2319 DVLOG(1) << "Notifications disabled with reason " |
2309 it != type_payloads.end(); ++it) { | 2320 << sync_notifier::NotificationsDisabledReasonToString(reason); |
2310 NotificationInfo* info = ¬ification_info_map_[it->first]; | 2321 allstatus_.SetNotificationsEnabled(false); |
2311 info->total_count++; | 2322 if (scheduler()) { |
2312 info->payload = it->second; | 2323 scheduler()->set_notifications_enabled(false); |
2313 } | 2324 } |
| 2325 if (js_event_handler_.IsInitialized()) { |
| 2326 DictionaryValue details; |
| 2327 details.Set("enabled", Value::CreateBooleanValue(false)); |
| 2328 js_event_handler_.Call(FROM_HERE, |
| 2329 &JsEventHandler::HandleJsEvent, |
| 2330 "onNotificationStateChange", |
| 2331 JsEventDetails(&details)); |
| 2332 } |
| 2333 // TODO(akalin): Treat a CREDENTIALS_REJECTED state as an auth |
| 2334 // error. |
2314 } | 2335 } |
2315 | 2336 |
2316 void SyncManager::SyncInternal::OnIncomingNotification( | 2337 void SyncManager::SyncInternal::OnIncomingNotification( |
2317 const syncable::ModelTypePayloadMap& type_payloads, | 2338 const syncable::ModelTypePayloadMap& type_payloads, |
2318 sync_notifier::IncomingNotificationSource source) { | 2339 sync_notifier::IncomingNotificationSource source) { |
2319 DCHECK(thread_checker_.CalledOnValidThread()); | 2340 DCHECK(thread_checker_.CalledOnValidThread()); |
2320 if (source == sync_notifier::LOCAL_NOTIFICATION) { | 2341 if (source == sync_notifier::LOCAL_NOTIFICATION) { |
2321 if (scheduler()) { | 2342 if (scheduler()) { |
2322 scheduler()->ScheduleNudgeWithPayloadsAsync( | 2343 scheduler()->ScheduleNudgeWithPayloadsAsync( |
2323 TimeDelta::FromMilliseconds(kSyncRefreshDelayMsec), | 2344 TimeDelta::FromMilliseconds(kSyncRefreshDelayMsec), |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2426 found_experiment = true; | 2447 found_experiment = true; |
2427 } | 2448 } |
2428 return found_experiment; | 2449 return found_experiment; |
2429 } | 2450 } |
2430 | 2451 |
2431 bool SyncManager::HasUnsyncedItems() const { | 2452 bool SyncManager::HasUnsyncedItems() const { |
2432 sync_api::ReadTransaction trans(FROM_HERE, GetUserShare()); | 2453 sync_api::ReadTransaction trans(FROM_HERE, GetUserShare()); |
2433 return (trans.GetWrappedTrans()->directory()->unsynced_entity_count() != 0); | 2454 return (trans.GetWrappedTrans()->directory()->unsynced_entity_count() != 0); |
2434 } | 2455 } |
2435 | 2456 |
2436 void SyncManager::TriggerOnNotificationStateChangeForTest( | 2457 void SyncManager::SimulateEnableNotificationsForTest() { |
2437 bool notifications_enabled) { | |
2438 DCHECK(thread_checker_.CalledOnValidThread()); | 2458 DCHECK(thread_checker_.CalledOnValidThread()); |
2439 data_->OnNotificationStateChange(notifications_enabled); | 2459 data_->OnNotificationsEnabled(); |
| 2460 } |
| 2461 |
| 2462 void SyncManager::SimulateDisableNotificationsForTest(int reason) { |
| 2463 DCHECK(thread_checker_.CalledOnValidThread()); |
| 2464 data_->OnNotificationsDisabled( |
| 2465 static_cast<sync_notifier::NotificationsDisabledReason>(reason)); |
2440 } | 2466 } |
2441 | 2467 |
2442 void SyncManager::TriggerOnIncomingNotificationForTest( | 2468 void SyncManager::TriggerOnIncomingNotificationForTest( |
2443 ModelTypeSet model_types) { | 2469 ModelTypeSet model_types) { |
2444 DCHECK(thread_checker_.CalledOnValidThread()); | 2470 DCHECK(thread_checker_.CalledOnValidThread()); |
2445 syncable::ModelTypePayloadMap model_types_with_payloads = | 2471 syncable::ModelTypePayloadMap model_types_with_payloads = |
2446 syncable::ModelTypePayloadMapFromEnumSet(model_types, | 2472 syncable::ModelTypePayloadMapFromEnumSet(model_types, |
2447 std::string()); | 2473 std::string()); |
2448 | 2474 |
2449 data_->OnIncomingNotification(model_types_with_payloads, | 2475 data_->OnIncomingNotification(model_types_with_payloads, |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2501 share->directory->GetDownloadProgress(i.Get(), &marker); | 2527 share->directory->GetDownloadProgress(i.Get(), &marker); |
2502 | 2528 |
2503 if (marker.token().empty()) | 2529 if (marker.token().empty()) |
2504 result.Put(i.Get()); | 2530 result.Put(i.Get()); |
2505 | 2531 |
2506 } | 2532 } |
2507 return result; | 2533 return result; |
2508 } | 2534 } |
2509 | 2535 |
2510 } // namespace sync_api | 2536 } // namespace sync_api |
OLD | NEW |