| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 "chrome/browser/sync/js/js_transaction_observer.h" | 5 #include "chrome/browser/sync/js/js_transaction_observer.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 } | 40 } |
| 41 | 41 |
| 42 namespace { | 42 namespace { |
| 43 | 43 |
| 44 // Max number of mutations we attempt to convert to values (to avoid | 44 // Max number of mutations we attempt to convert to values (to avoid |
| 45 // running out of memory). | 45 // running out of memory). |
| 46 const size_t kMutationLimit = 300; | 46 const size_t kMutationLimit = 300; |
| 47 | 47 |
| 48 } // namespace | 48 } // namespace |
| 49 | 49 |
| 50 void JsTransactionObserver::OnTransactionMutate( | 50 void JsTransactionObserver::OnTransactionWrite( |
| 51 const tracked_objects::Location& location, | 51 const syncable::ImmutableWriteTransactionInfo& write_transaction_info, |
| 52 const syncable::WriterTag& writer, | |
| 53 const syncable::ImmutableEntryKernelMutationMap& mutations, | |
| 54 const syncable::ModelTypeBitSet& models_with_changes) { | 52 const syncable::ModelTypeBitSet& models_with_changes) { |
| 55 DCHECK(non_thread_safe_.CalledOnValidThread()); | 53 DCHECK(non_thread_safe_.CalledOnValidThread()); |
| 56 if (!event_handler_.IsInitialized()) { | 54 if (!event_handler_.IsInitialized()) { |
| 57 return; | 55 return; |
| 58 } | 56 } |
| 59 DictionaryValue details; | 57 DictionaryValue details; |
| 60 details.SetString("location", location.ToString()); | 58 details.Set("writeTransactionInfo", |
| 61 details.SetString("writer", syncable::WriterTagToString(writer)); | 59 write_transaction_info.Get().ToValue(kMutationLimit)); |
| 62 Value* mutations_value = NULL; | |
| 63 const size_t mutations_size = mutations.Get().size(); | |
| 64 if (mutations_size <= kMutationLimit) { | |
| 65 mutations_value = syncable::EntryKernelMutationMapToValue(mutations.Get()); | |
| 66 } else { | |
| 67 mutations_value = | |
| 68 Value::CreateStringValue( | |
| 69 base::Uint64ToString(static_cast<uint64>(mutations_size)) + | |
| 70 " mutations"); | |
| 71 } | |
| 72 details.Set("mutations", mutations_value); | |
| 73 details.Set("modelsWithChanges", | 60 details.Set("modelsWithChanges", |
| 74 syncable::ModelTypeBitSetToValue(models_with_changes)); | 61 syncable::ModelTypeBitSetToValue(models_with_changes)); |
| 75 HandleJsEvent(FROM_HERE, "onTransactionMutate", JsEventDetails(&details)); | 62 HandleJsEvent(FROM_HERE, "onTransactionMutate", JsEventDetails(&details)); |
| 76 } | 63 } |
| 77 | 64 |
| 78 void JsTransactionObserver::OnTransactionEnd( | 65 void JsTransactionObserver::OnTransactionEnd( |
| 79 const tracked_objects::Location& location, | 66 const tracked_objects::Location& location, |
| 80 const syncable::WriterTag& writer) { | 67 const syncable::WriterTag& writer) { |
| 81 DCHECK(non_thread_safe_.CalledOnValidThread()); | 68 DCHECK(non_thread_safe_.CalledOnValidThread()); |
| 82 if (!event_handler_.IsInitialized()) { | 69 if (!event_handler_.IsInitialized()) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 93 const std::string& name, const JsEventDetails& details) { | 80 const std::string& name, const JsEventDetails& details) { |
| 94 if (!event_handler_.IsInitialized()) { | 81 if (!event_handler_.IsInitialized()) { |
| 95 NOTREACHED(); | 82 NOTREACHED(); |
| 96 return; | 83 return; |
| 97 } | 84 } |
| 98 event_handler_.Call(from_here, | 85 event_handler_.Call(from_here, |
| 99 &JsEventHandler::HandleJsEvent, name, details); | 86 &JsEventHandler::HandleJsEvent, name, details); |
| 100 } | 87 } |
| 101 | 88 |
| 102 } // namespace browser_sync | 89 } // namespace browser_sync |
| OLD | NEW |