| 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/js_sync_manager_observer.h" | 5 #include "sync/internal_api/js_sync_manager_observer.h" |
| 6 | 6 |
| 7 #include <cstddef> | 7 #include <cstddef> |
| 8 | 8 |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 void JsSyncManagerObserver::SetJsEventHandler( | 27 void JsSyncManagerObserver::SetJsEventHandler( |
| 28 const WeakHandle<JsEventHandler>& event_handler) { | 28 const WeakHandle<JsEventHandler>& event_handler) { |
| 29 event_handler_ = event_handler; | 29 event_handler_ = event_handler; |
| 30 } | 30 } |
| 31 | 31 |
| 32 void JsSyncManagerObserver::OnSyncCycleCompleted( | 32 void JsSyncManagerObserver::OnSyncCycleCompleted( |
| 33 const sessions::SyncSessionSnapshot& snapshot) { | 33 const sessions::SyncSessionSnapshot& snapshot) { |
| 34 if (!event_handler_.IsInitialized()) { | 34 if (!event_handler_.IsInitialized()) { |
| 35 return; | 35 return; |
| 36 } | 36 } |
| 37 DictionaryValue details; | 37 base::DictionaryValue details; |
| 38 details.Set("snapshot", snapshot.ToValue()); | 38 details.Set("snapshot", snapshot.ToValue()); |
| 39 HandleJsEvent(FROM_HERE, "onSyncCycleCompleted", JsEventDetails(&details)); | 39 HandleJsEvent(FROM_HERE, "onSyncCycleCompleted", JsEventDetails(&details)); |
| 40 } | 40 } |
| 41 | 41 |
| 42 void JsSyncManagerObserver::OnConnectionStatusChange(ConnectionStatus status) { | 42 void JsSyncManagerObserver::OnConnectionStatusChange(ConnectionStatus status) { |
| 43 if (!event_handler_.IsInitialized()) { | 43 if (!event_handler_.IsInitialized()) { |
| 44 return; | 44 return; |
| 45 } | 45 } |
| 46 DictionaryValue details; | 46 base::DictionaryValue details; |
| 47 details.SetString("status", ConnectionStatusToString(status)); | 47 details.SetString("status", ConnectionStatusToString(status)); |
| 48 HandleJsEvent(FROM_HERE, | 48 HandleJsEvent(FROM_HERE, |
| 49 "onConnectionStatusChange", JsEventDetails(&details)); | 49 "onConnectionStatusChange", JsEventDetails(&details)); |
| 50 } | 50 } |
| 51 | 51 |
| 52 void JsSyncManagerObserver::OnUpdatedToken(const std::string& token) { | 52 void JsSyncManagerObserver::OnUpdatedToken(const std::string& token) { |
| 53 if (!event_handler_.IsInitialized()) { | 53 if (!event_handler_.IsInitialized()) { |
| 54 return; | 54 return; |
| 55 } | 55 } |
| 56 DictionaryValue details; | 56 base::DictionaryValue details; |
| 57 details.SetString("token", "<redacted>"); | 57 details.SetString("token", "<redacted>"); |
| 58 HandleJsEvent(FROM_HERE, "onUpdatedToken", JsEventDetails(&details)); | 58 HandleJsEvent(FROM_HERE, "onUpdatedToken", JsEventDetails(&details)); |
| 59 } | 59 } |
| 60 | 60 |
| 61 void JsSyncManagerObserver::OnActionableError( | 61 void JsSyncManagerObserver::OnActionableError( |
| 62 const SyncProtocolError& sync_error) { | 62 const SyncProtocolError& sync_error) { |
| 63 if (!event_handler_.IsInitialized()) { | 63 if (!event_handler_.IsInitialized()) { |
| 64 return; | 64 return; |
| 65 } | 65 } |
| 66 DictionaryValue details; | 66 base::DictionaryValue details; |
| 67 details.Set("syncError", sync_error.ToValue()); | 67 details.Set("syncError", sync_error.ToValue()); |
| 68 HandleJsEvent(FROM_HERE, "onActionableError", | 68 HandleJsEvent(FROM_HERE, "onActionableError", |
| 69 JsEventDetails(&details)); | 69 JsEventDetails(&details)); |
| 70 } | 70 } |
| 71 | 71 |
| 72 void JsSyncManagerObserver::OnInitializationComplete( | 72 void JsSyncManagerObserver::OnInitializationComplete( |
| 73 const WeakHandle<JsBackend>& js_backend, | 73 const WeakHandle<JsBackend>& js_backend, |
| 74 const WeakHandle<DataTypeDebugInfoListener>& debug_info_listener, | 74 const WeakHandle<DataTypeDebugInfoListener>& debug_info_listener, |
| 75 bool success, syncer::ModelTypeSet restored_types) { | 75 bool success, syncer::ModelTypeSet restored_types) { |
| 76 if (!event_handler_.IsInitialized()) { | 76 if (!event_handler_.IsInitialized()) { |
| 77 return; | 77 return; |
| 78 } | 78 } |
| 79 // Ignore the |js_backend| argument; it's not really convertible to | 79 // Ignore the |js_backend| argument; it's not really convertible to |
| 80 // JSON anyway. | 80 // JSON anyway. |
| 81 | 81 |
| 82 DictionaryValue details; | 82 base::DictionaryValue details; |
| 83 details.Set("restoredTypes", ModelTypeSetToValue(restored_types)); | 83 details.Set("restoredTypes", ModelTypeSetToValue(restored_types)); |
| 84 | 84 |
| 85 HandleJsEvent(FROM_HERE, | 85 HandleJsEvent(FROM_HERE, |
| 86 "onInitializationComplete", | 86 "onInitializationComplete", |
| 87 JsEventDetails(&details)); | 87 JsEventDetails(&details)); |
| 88 } | 88 } |
| 89 | 89 |
| 90 void JsSyncManagerObserver::OnStopSyncingPermanently() { | 90 void JsSyncManagerObserver::OnStopSyncingPermanently() { |
| 91 if (!event_handler_.IsInitialized()) { | 91 if (!event_handler_.IsInitialized()) { |
| 92 return; | 92 return; |
| 93 } | 93 } |
| 94 HandleJsEvent(FROM_HERE, "onStopSyncingPermanently", JsEventDetails()); | 94 HandleJsEvent(FROM_HERE, "onStopSyncingPermanently", JsEventDetails()); |
| 95 } | 95 } |
| 96 | 96 |
| 97 void JsSyncManagerObserver::HandleJsEvent( | 97 void JsSyncManagerObserver::HandleJsEvent( |
| 98 const tracked_objects::Location& from_here, | 98 const tracked_objects::Location& from_here, |
| 99 const std::string& name, const JsEventDetails& details) { | 99 const std::string& name, const JsEventDetails& details) { |
| 100 if (!event_handler_.IsInitialized()) { | 100 if (!event_handler_.IsInitialized()) { |
| 101 NOTREACHED(); | 101 NOTREACHED(); |
| 102 return; | 102 return; |
| 103 } | 103 } |
| 104 event_handler_.Call(from_here, | 104 event_handler_.Call(from_here, |
| 105 &JsEventHandler::HandleJsEvent, name, details); | 105 &JsEventHandler::HandleJsEvent, name, details); |
| 106 } | 106 } |
| 107 | 107 |
| 108 } // namespace syncer | 108 } // namespace syncer |
| OLD | NEW |