[email protected] | 12bb3e11 | 2012-01-18 08:58:01 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 88af9601 | 2011-02-11 20:50:17 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 91835ca | 2012-04-21 09:59:42 | [diff] [blame] | 5 | #include "sync/internal_api/js_sync_manager_observer.h" |
[email protected] | 88af9601 | 2011-02-11 20:50:17 | [diff] [blame] | 6 | |
| 7 | #include <cstddef> |
| 8 | |
[email protected] | c62dd9d | 2011-09-21 18:05:41 | [diff] [blame] | 9 | #include "base/location.h" |
[email protected] | 88af9601 | 2011-02-11 20:50:17 | [diff] [blame] | 10 | #include "base/logging.h" |
[email protected] | a4bbc1f9 | 2013-06-11 07:28:19 | [diff] [blame] | 11 | #include "base/strings/string_number_conversions.h" |
[email protected] | 88af9601 | 2011-02-11 20:50:17 | [diff] [blame] | 12 | #include "base/values.h" |
[email protected] | 002d3919 | 2012-07-03 01:30:56 | [diff] [blame] | 13 | #include "sync/internal_api/public/base/model_type.h" |
[email protected] | 406203d | 2012-06-17 01:07:19 | [diff] [blame] | 14 | #include "sync/internal_api/public/change_record.h" |
[email protected] | 3f8556a | 2012-06-07 17:50:19 | [diff] [blame] | 15 | #include "sync/internal_api/public/sessions/sync_session_snapshot.h" |
[email protected] | ceffdf0 | 2012-07-17 20:12:15 | [diff] [blame] | 16 | #include "sync/internal_api/public/util/sync_string_conversions.h" |
[email protected] | c1c32c8 | 2012-03-15 09:35:42 | [diff] [blame] | 17 | #include "sync/js/js_event_details.h" |
| 18 | #include "sync/js/js_event_handler.h" |
[email protected] | 88af9601 | 2011-02-11 20:50:17 | [diff] [blame] | 19 | |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 20 | namespace syncer { |
[email protected] | 88af9601 | 2011-02-11 20:50:17 | [diff] [blame] | 21 | |
[email protected] | fa13487 | 2011-08-02 18:39:55 | [diff] [blame] | 22 | JsSyncManagerObserver::JsSyncManagerObserver() {} |
[email protected] | 88af9601 | 2011-02-11 20:50:17 | [diff] [blame] | 23 | |
| 24 | JsSyncManagerObserver::~JsSyncManagerObserver() {} |
| 25 | |
[email protected] | fa13487 | 2011-08-02 18:39:55 | [diff] [blame] | 26 | void JsSyncManagerObserver::SetJsEventHandler( |
| 27 | const WeakHandle<JsEventHandler>& event_handler) { |
| 28 | event_handler_ = event_handler; |
| 29 | } |
| 30 | |
[email protected] | 88af9601 | 2011-02-11 20:50:17 | [diff] [blame] | 31 | void JsSyncManagerObserver::OnSyncCycleCompleted( |
[email protected] | 90ce61b5 | 2012-04-24 19:32:28 | [diff] [blame] | 32 | const sessions::SyncSessionSnapshot& snapshot) { |
[email protected] | fa13487 | 2011-08-02 18:39:55 | [diff] [blame] | 33 | if (!event_handler_.IsInitialized()) { |
| 34 | return; |
| 35 | } |
[email protected] | 0c6c1e4 | 2013-06-21 19:42:19 | [diff] [blame] | 36 | base::DictionaryValue details; |
[email protected] | 90ce61b5 | 2012-04-24 19:32:28 | [diff] [blame] | 37 | details.Set("snapshot", snapshot.ToValue()); |
[email protected] | fa13487 | 2011-08-02 18:39:55 | [diff] [blame] | 38 | HandleJsEvent(FROM_HERE, "onSyncCycleCompleted", JsEventDetails(&details)); |
[email protected] | 88af9601 | 2011-02-11 20:50:17 | [diff] [blame] | 39 | } |
| 40 | |
[email protected] | d45f0d9 | 2012-07-20 17:25:41 | [diff] [blame] | 41 | void JsSyncManagerObserver::OnConnectionStatusChange(ConnectionStatus status) { |
[email protected] | fa13487 | 2011-08-02 18:39:55 | [diff] [blame] | 42 | if (!event_handler_.IsInitialized()) { |
| 43 | return; |
| 44 | } |
[email protected] | 0c6c1e4 | 2013-06-21 19:42:19 | [diff] [blame] | 45 | base::DictionaryValue details; |
[email protected] | d45f0d9 | 2012-07-20 17:25:41 | [diff] [blame] | 46 | details.SetString("status", ConnectionStatusToString(status)); |
[email protected] | 6e205989 | 2012-03-08 02:22:24 | [diff] [blame] | 47 | HandleJsEvent(FROM_HERE, |
| 48 | "onConnectionStatusChange", JsEventDetails(&details)); |
[email protected] | 88af9601 | 2011-02-11 20:50:17 | [diff] [blame] | 49 | } |
| 50 | |
[email protected] | cb5199b | 2011-09-04 01:55:52 | [diff] [blame] | 51 | void JsSyncManagerObserver::OnActionableError( |
| 52 | const SyncProtocolError& sync_error) { |
| 53 | if (!event_handler_.IsInitialized()) { |
| 54 | return; |
| 55 | } |
[email protected] | 0c6c1e4 | 2013-06-21 19:42:19 | [diff] [blame] | 56 | base::DictionaryValue details; |
[email protected] | cb5199b | 2011-09-04 01:55:52 | [diff] [blame] | 57 | details.Set("syncError", sync_error.ToValue()); |
| 58 | HandleJsEvent(FROM_HERE, "onActionableError", |
| 59 | JsEventDetails(&details)); |
| 60 | } |
| 61 | |
[email protected] | eb370fc | 2014-03-21 22:14:35 | [diff] [blame] | 62 | void JsSyncManagerObserver::OnProtocolEvent( |
| 63 | const ProtocolEvent& event) { } |
| 64 | |
[email protected] | b99f548 | 2014-02-12 23:47:37 | [diff] [blame] | 65 | void JsSyncManagerObserver::OnMigrationRequested(ModelTypeSet types) { } |
| 66 | |
[email protected] | fa13487 | 2011-08-02 18:39:55 | [diff] [blame] | 67 | void JsSyncManagerObserver::OnInitializationComplete( |
[email protected] | da0832b | 2011-09-08 17:00:04 | [diff] [blame] | 68 | const WeakHandle<JsBackend>& js_backend, |
[email protected] | 12a11e2 | 2012-11-08 06:26:30 | [diff] [blame] | 69 | const WeakHandle<DataTypeDebugInfoListener>& debug_info_listener, |
[email protected] | 62c28b9 | 2012-07-30 04:37:48 | [diff] [blame] | 70 | bool success, syncer::ModelTypeSet restored_types) { |
[email protected] | fa13487 | 2011-08-02 18:39:55 | [diff] [blame] | 71 | if (!event_handler_.IsInitialized()) { |
| 72 | return; |
| 73 | } |
| 74 | // Ignore the |js_backend| argument; it's not really convertible to |
| 75 | // JSON anyway. |
[email protected] | 62c28b9 | 2012-07-30 04:37:48 | [diff] [blame] | 76 | |
[email protected] | 0c6c1e4 | 2013-06-21 19:42:19 | [diff] [blame] | 77 | base::DictionaryValue details; |
[email protected] | 32e757a | 2012-07-30 23:09:36 | [diff] [blame] | 78 | details.Set("restoredTypes", ModelTypeSetToValue(restored_types)); |
[email protected] | 62c28b9 | 2012-07-30 04:37:48 | [diff] [blame] | 79 | |
[email protected] | 32e757a | 2012-07-30 23:09:36 | [diff] [blame] | 80 | HandleJsEvent(FROM_HERE, |
| 81 | "onInitializationComplete", |
| 82 | JsEventDetails(&details)); |
[email protected] | 88af9601 | 2011-02-11 20:50:17 | [diff] [blame] | 83 | } |
| 84 | |
[email protected] | fa13487 | 2011-08-02 18:39:55 | [diff] [blame] | 85 | void JsSyncManagerObserver::HandleJsEvent( |
| 86 | const tracked_objects::Location& from_here, |
| 87 | const std::string& name, const JsEventDetails& details) { |
| 88 | if (!event_handler_.IsInitialized()) { |
| 89 | NOTREACHED(); |
| 90 | return; |
| 91 | } |
| 92 | event_handler_.Call(from_here, |
| 93 | &JsEventHandler::HandleJsEvent, name, details); |
[email protected] | 88af9601 | 2011-02-11 20:50:17 | [diff] [blame] | 94 | } |
| 95 | |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 96 | } // namespace syncer |