| 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" |
| 11 #include "base/string_number_conversions.h" | 11 #include "base/string_number_conversions.h" |
| 12 #include "base/values.h" | 12 #include "base/values.h" |
| 13 #include "sync/internal_api/public/change_record.h" | 13 #include "sync/internal_api/public/change_record.h" |
| 14 #include "sync/internal_api/public/sessions/sync_session_snapshot.h" | 14 #include "sync/internal_api/public/sessions/sync_session_snapshot.h" |
| 15 #include "sync/internal_api/public/syncable/model_type.h" | 15 #include "sync/internal_api/public/syncable/model_type.h" |
| 16 #include "sync/js/js_arg_list.h" | 16 #include "sync/js/js_arg_list.h" |
| 17 #include "sync/js/js_event_details.h" | 17 #include "sync/js/js_event_details.h" |
| 18 #include "sync/js/js_event_handler.h" | 18 #include "sync/js/js_event_handler.h" |
| 19 #include "sync/sessions/session_state.h" | 19 #include "sync/sessions/session_state.h" |
| 20 | 20 |
| 21 namespace csync { | 21 namespace syncer { |
| 22 | 22 |
| 23 using csync::SyncProtocolError; | 23 using syncer::SyncProtocolError; |
| 24 | 24 |
| 25 JsSyncManagerObserver::JsSyncManagerObserver() {} | 25 JsSyncManagerObserver::JsSyncManagerObserver() {} |
| 26 | 26 |
| 27 JsSyncManagerObserver::~JsSyncManagerObserver() {} | 27 JsSyncManagerObserver::~JsSyncManagerObserver() {} |
| 28 | 28 |
| 29 void JsSyncManagerObserver::SetJsEventHandler( | 29 void JsSyncManagerObserver::SetJsEventHandler( |
| 30 const WeakHandle<JsEventHandler>& event_handler) { | 30 const WeakHandle<JsEventHandler>& event_handler) { |
| 31 event_handler_ = event_handler; | 31 event_handler_ = event_handler; |
| 32 } | 32 } |
| 33 | 33 |
| 34 void JsSyncManagerObserver::OnSyncCycleCompleted( | 34 void JsSyncManagerObserver::OnSyncCycleCompleted( |
| 35 const sessions::SyncSessionSnapshot& snapshot) { | 35 const sessions::SyncSessionSnapshot& snapshot) { |
| 36 if (!event_handler_.IsInitialized()) { | 36 if (!event_handler_.IsInitialized()) { |
| 37 return; | 37 return; |
| 38 } | 38 } |
| 39 DictionaryValue details; | 39 DictionaryValue details; |
| 40 details.Set("snapshot", snapshot.ToValue()); | 40 details.Set("snapshot", snapshot.ToValue()); |
| 41 HandleJsEvent(FROM_HERE, "onSyncCycleCompleted", JsEventDetails(&details)); | 41 HandleJsEvent(FROM_HERE, "onSyncCycleCompleted", JsEventDetails(&details)); |
| 42 } | 42 } |
| 43 | 43 |
| 44 void JsSyncManagerObserver::OnConnectionStatusChange( | 44 void JsSyncManagerObserver::OnConnectionStatusChange( |
| 45 csync::ConnectionStatus status) { | 45 syncer::ConnectionStatus status) { |
| 46 if (!event_handler_.IsInitialized()) { | 46 if (!event_handler_.IsInitialized()) { |
| 47 return; | 47 return; |
| 48 } | 48 } |
| 49 DictionaryValue details; | 49 DictionaryValue details; |
| 50 details.SetString("status", csync::ConnectionStatusToString(status)); | 50 details.SetString("status", syncer::ConnectionStatusToString(status)); |
| 51 HandleJsEvent(FROM_HERE, | 51 HandleJsEvent(FROM_HERE, |
| 52 "onConnectionStatusChange", JsEventDetails(&details)); | 52 "onConnectionStatusChange", JsEventDetails(&details)); |
| 53 } | 53 } |
| 54 | 54 |
| 55 void JsSyncManagerObserver::OnUpdatedToken(const std::string& token) { | 55 void JsSyncManagerObserver::OnUpdatedToken(const std::string& token) { |
| 56 if (!event_handler_.IsInitialized()) { | 56 if (!event_handler_.IsInitialized()) { |
| 57 return; | 57 return; |
| 58 } | 58 } |
| 59 DictionaryValue details; | 59 DictionaryValue details; |
| 60 details.SetString("token", "<redacted>"); | 60 details.SetString("token", "<redacted>"); |
| 61 HandleJsEvent(FROM_HERE, "onUpdatedToken", JsEventDetails(&details)); | 61 HandleJsEvent(FROM_HERE, "onUpdatedToken", JsEventDetails(&details)); |
| 62 } | 62 } |
| 63 | 63 |
| 64 void JsSyncManagerObserver::OnPassphraseRequired( | 64 void JsSyncManagerObserver::OnPassphraseRequired( |
| 65 csync::PassphraseRequiredReason reason, | 65 syncer::PassphraseRequiredReason reason, |
| 66 const sync_pb::EncryptedData& pending_keys) { | 66 const sync_pb::EncryptedData& pending_keys) { |
| 67 if (!event_handler_.IsInitialized()) { | 67 if (!event_handler_.IsInitialized()) { |
| 68 return; | 68 return; |
| 69 } | 69 } |
| 70 DictionaryValue details; | 70 DictionaryValue details; |
| 71 details.SetString("reason", | 71 details.SetString("reason", |
| 72 csync::PassphraseRequiredReasonToString(reason)); | 72 syncer::PassphraseRequiredReasonToString(reason)); |
| 73 HandleJsEvent(FROM_HERE, "onPassphraseRequired", JsEventDetails(&details)); | 73 HandleJsEvent(FROM_HERE, "onPassphraseRequired", JsEventDetails(&details)); |
| 74 } | 74 } |
| 75 | 75 |
| 76 void JsSyncManagerObserver::OnPassphraseAccepted() { | 76 void JsSyncManagerObserver::OnPassphraseAccepted() { |
| 77 if (!event_handler_.IsInitialized()) { | 77 if (!event_handler_.IsInitialized()) { |
| 78 return; | 78 return; |
| 79 } | 79 } |
| 80 DictionaryValue details; | 80 DictionaryValue details; |
| 81 HandleJsEvent(FROM_HERE, "onPassphraseAccepted", JsEventDetails(&details)); | 81 HandleJsEvent(FROM_HERE, "onPassphraseAccepted", JsEventDetails(&details)); |
| 82 } | 82 } |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 const tracked_objects::Location& from_here, | 146 const tracked_objects::Location& from_here, |
| 147 const std::string& name, const JsEventDetails& details) { | 147 const std::string& name, const JsEventDetails& details) { |
| 148 if (!event_handler_.IsInitialized()) { | 148 if (!event_handler_.IsInitialized()) { |
| 149 NOTREACHED(); | 149 NOTREACHED(); |
| 150 return; | 150 return; |
| 151 } | 151 } |
| 152 event_handler_.Call(from_here, | 152 event_handler_.Call(from_here, |
| 153 &JsEventHandler::HandleJsEvent, name, details); | 153 &JsEventHandler::HandleJsEvent, name, details); |
| 154 } | 154 } |
| 155 | 155 |
| 156 } // namespace csync | 156 } // namespace syncer |
| OLD | NEW |