[email protected] | 88af9601 | 2011-02-11 20:50:17 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "chrome/browser/sync/js_sync_manager_observer.h" |
| 6 | |
| 7 | #include <cstddef> |
| 8 | |
| 9 | #include "base/logging.h" |
| 10 | #include "base/values.h" |
| 11 | #include "chrome/browser/sync/js_arg_list.h" |
[email protected] | ec5263a | 2011-05-10 09:23:39 | [diff] [blame] | 12 | #include "chrome/browser/sync/js_event_details.h" |
[email protected] | 88af9601 | 2011-02-11 20:50:17 | [diff] [blame] | 13 | #include "chrome/browser/sync/js_event_router.h" |
| 14 | #include "chrome/browser/sync/sessions/session_state.h" |
| 15 | #include "chrome/browser/sync/syncable/model_type.h" |
[email protected] | 88af9601 | 2011-02-11 20:50:17 | [diff] [blame] | 16 | |
| 17 | namespace browser_sync { |
| 18 | |
| 19 | JsSyncManagerObserver::JsSyncManagerObserver(JsEventRouter* parent_router) |
| 20 | : parent_router_(parent_router) { |
| 21 | DCHECK(parent_router_); |
| 22 | } |
| 23 | |
| 24 | JsSyncManagerObserver::~JsSyncManagerObserver() {} |
| 25 | |
| 26 | void JsSyncManagerObserver::OnChangesApplied( |
| 27 | syncable::ModelType model_type, |
| 28 | const sync_api::BaseTransaction* trans, |
| 29 | const sync_api::SyncManager::ChangeRecord* changes, |
| 30 | int change_count) { |
[email protected] | ec5263a | 2011-05-10 09:23:39 | [diff] [blame] | 31 | DictionaryValue details; |
| 32 | details.SetString("modelType", syncable::ModelTypeToString(model_type)); |
[email protected] | 88af9601 | 2011-02-11 20:50:17 | [diff] [blame] | 33 | ListValue* change_values = new ListValue(); |
[email protected] | ec5263a | 2011-05-10 09:23:39 | [diff] [blame] | 34 | details.Set("changes", change_values); |
[email protected] | 88af9601 | 2011-02-11 20:50:17 | [diff] [blame] | 35 | for (int i = 0; i < change_count; ++i) { |
[email protected] | ab58e42 | 2011-02-18 09:57:04 | [diff] [blame] | 36 | change_values->Append(changes[i].ToValue(trans)); |
[email protected] | 88af9601 | 2011-02-11 20:50:17 | [diff] [blame] | 37 | } |
[email protected] | ec5263a | 2011-05-10 09:23:39 | [diff] [blame] | 38 | parent_router_->RouteJsEvent("onChangesApplied", JsEventDetails(&details)); |
[email protected] | 88af9601 | 2011-02-11 20:50:17 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | void JsSyncManagerObserver::OnChangesComplete( |
| 42 | syncable::ModelType model_type) { |
[email protected] | ec5263a | 2011-05-10 09:23:39 | [diff] [blame] | 43 | DictionaryValue details; |
| 44 | details.SetString("modelType", syncable::ModelTypeToString(model_type)); |
| 45 | parent_router_->RouteJsEvent("onChangesComplete", JsEventDetails(&details)); |
[email protected] | 88af9601 | 2011-02-11 20:50:17 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | void JsSyncManagerObserver::OnSyncCycleCompleted( |
| 49 | const sessions::SyncSessionSnapshot* snapshot) { |
[email protected] | ec5263a | 2011-05-10 09:23:39 | [diff] [blame] | 50 | DictionaryValue details; |
| 51 | details.Set("snapshot", snapshot->ToValue()); |
[email protected] | 3c92138 | 2011-05-06 09:32:50 | [diff] [blame] | 52 | parent_router_->RouteJsEvent("onSyncCycleCompleted", |
[email protected] | ec5263a | 2011-05-10 09:23:39 | [diff] [blame] | 53 | JsEventDetails(&details)); |
[email protected] | 88af9601 | 2011-02-11 20:50:17 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | void JsSyncManagerObserver::OnAuthError( |
| 57 | const GoogleServiceAuthError& auth_error) { |
[email protected] | ec5263a | 2011-05-10 09:23:39 | [diff] [blame] | 58 | DictionaryValue details; |
| 59 | details.Set("authError", auth_error.ToValue()); |
| 60 | parent_router_->RouteJsEvent("onAuthError", JsEventDetails(&details)); |
[email protected] | 88af9601 | 2011-02-11 20:50:17 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | void JsSyncManagerObserver::OnUpdatedToken(const std::string& token) { |
[email protected] | ec5263a | 2011-05-10 09:23:39 | [diff] [blame] | 64 | DictionaryValue details; |
| 65 | details.SetString("token", "<redacted>"); |
| 66 | parent_router_->RouteJsEvent("onUpdatedToken", JsEventDetails(&details)); |
[email protected] | 88af9601 | 2011-02-11 20:50:17 | [diff] [blame] | 67 | } |
| 68 | |
[email protected] | 43c48fb9 | 2011-05-02 19:47:43 | [diff] [blame] | 69 | void JsSyncManagerObserver::OnPassphraseRequired( |
| 70 | sync_api::PassphraseRequiredReason reason) { |
[email protected] | ec5263a | 2011-05-10 09:23:39 | [diff] [blame] | 71 | DictionaryValue details; |
| 72 | details.SetString("reason", |
| 73 | sync_api::PassphraseRequiredReasonToString(reason)); |
[email protected] | 88af9601 | 2011-02-11 20:50:17 | [diff] [blame] | 74 | parent_router_->RouteJsEvent("onPassphraseRequired", |
[email protected] | ec5263a | 2011-05-10 09:23:39 | [diff] [blame] | 75 | JsEventDetails(&details)); |
[email protected] | 88af9601 | 2011-02-11 20:50:17 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | void JsSyncManagerObserver::OnPassphraseAccepted( |
| 79 | const std::string& bootstrap_token) { |
[email protected] | ec5263a | 2011-05-10 09:23:39 | [diff] [blame] | 80 | DictionaryValue details; |
| 81 | details.SetString("bootstrapToken", "<redacted>"); |
[email protected] | 88af9601 | 2011-02-11 20:50:17 | [diff] [blame] | 82 | parent_router_->RouteJsEvent("onPassphraseAccepted", |
[email protected] | ec5263a | 2011-05-10 09:23:39 | [diff] [blame] | 83 | JsEventDetails(&details)); |
[email protected] | 88af9601 | 2011-02-11 20:50:17 | [diff] [blame] | 84 | } |
| 85 | |
[email protected] | 3fa964af | 2011-02-24 18:54:39 | [diff] [blame] | 86 | void JsSyncManagerObserver::OnEncryptionComplete( |
| 87 | const syncable::ModelTypeSet& encrypted_types) { |
[email protected] | ec5263a | 2011-05-10 09:23:39 | [diff] [blame] | 88 | DictionaryValue details; |
| 89 | details.Set("encryptedTypes", |
| 90 | syncable::ModelTypeSetToValue(encrypted_types)); |
[email protected] | 3fa964af | 2011-02-24 18:54:39 | [diff] [blame] | 91 | parent_router_->RouteJsEvent("onEncryptionComplete", |
[email protected] | ec5263a | 2011-05-10 09:23:39 | [diff] [blame] | 92 | JsEventDetails(&details)); |
[email protected] | 3fa964af | 2011-02-24 18:54:39 | [diff] [blame] | 93 | } |
| 94 | |
[email protected] | dc55625 | 2011-04-20 01:59:35 | [diff] [blame] | 95 | void JsSyncManagerObserver::OnMigrationNeededForTypes( |
| 96 | const syncable::ModelTypeSet& types) { |
[email protected] | ec5263a | 2011-05-10 09:23:39 | [diff] [blame] | 97 | DictionaryValue details; |
| 98 | details.Set("types", syncable::ModelTypeSetToValue(types)); |
[email protected] | dc55625 | 2011-04-20 01:59:35 | [diff] [blame] | 99 | parent_router_->RouteJsEvent("onMigrationNeededForTypes", |
[email protected] | ec5263a | 2011-05-10 09:23:39 | [diff] [blame] | 100 | JsEventDetails(&details)); |
[email protected] | dc55625 | 2011-04-20 01:59:35 | [diff] [blame] | 101 | } |
| 102 | |
[email protected] | 88af9601 | 2011-02-11 20:50:17 | [diff] [blame] | 103 | void JsSyncManagerObserver::OnInitializationComplete() { |
[email protected] | ec5263a | 2011-05-10 09:23:39 | [diff] [blame] | 104 | parent_router_->RouteJsEvent("onInitializationComplete", JsEventDetails()); |
[email protected] | 88af9601 | 2011-02-11 20:50:17 | [diff] [blame] | 105 | } |
| 106 | |
[email protected] | 88af9601 | 2011-02-11 20:50:17 | [diff] [blame] | 107 | void JsSyncManagerObserver::OnStopSyncingPermanently() { |
[email protected] | ec5263a | 2011-05-10 09:23:39 | [diff] [blame] | 108 | parent_router_->RouteJsEvent("onStopSyncingPermanently", JsEventDetails()); |
[email protected] | 88af9601 | 2011-02-11 20:50:17 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | void JsSyncManagerObserver::OnClearServerDataSucceeded() { |
[email protected] | ec5263a | 2011-05-10 09:23:39 | [diff] [blame] | 112 | parent_router_->RouteJsEvent("onClearServerDataSucceeded", JsEventDetails()); |
[email protected] | 88af9601 | 2011-02-11 20:50:17 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | void JsSyncManagerObserver::OnClearServerDataFailed() { |
[email protected] | ec5263a | 2011-05-10 09:23:39 | [diff] [blame] | 116 | parent_router_->RouteJsEvent("onClearServerDataFailed", JsEventDetails()); |
[email protected] | 88af9601 | 2011-02-11 20:50:17 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | } // namespace browser_sync |