Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(239)

Side by Side Diff: components/sync/core_impl/js_mutation_event_observer.cc

Issue 2130453004: [Sync] Move //sync to //components/sync. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_mutation_event_observer.h" 5 #include "components/sync/core_impl/js_mutation_event_observer.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <string> 10 #include <string>
11 11
12 #include "base/location.h" 12 #include "base/location.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/strings/string_number_conversions.h" 14 #include "base/strings/string_number_conversions.h"
15 #include "base/values.h" 15 #include "base/values.h"
16 #include "sync/js/js_event_details.h" 16 #include "components/sync/js/js_event_details.h"
17 #include "sync/js/js_event_handler.h" 17 #include "components/sync/js/js_event_handler.h"
18 18
19 namespace syncer { 19 namespace syncer {
20 20
21 JsMutationEventObserver::JsMutationEventObserver() 21 JsMutationEventObserver::JsMutationEventObserver() : weak_ptr_factory_(this) {}
22 : weak_ptr_factory_(this) {}
23 22
24 JsMutationEventObserver::~JsMutationEventObserver() { 23 JsMutationEventObserver::~JsMutationEventObserver() {
25 DCHECK(CalledOnValidThread()); 24 DCHECK(CalledOnValidThread());
26 } 25 }
27 26
28 base::WeakPtr<JsMutationEventObserver> JsMutationEventObserver::AsWeakPtr() { 27 base::WeakPtr<JsMutationEventObserver> JsMutationEventObserver::AsWeakPtr() {
29 return weak_ptr_factory_.GetWeakPtr(); 28 return weak_ptr_factory_.GetWeakPtr();
30 } 29 }
31 30
32 void JsMutationEventObserver::InvalidateWeakPtrs() { 31 void JsMutationEventObserver::InvalidateWeakPtrs() {
(...skipping 21 matching lines...) Expand all
54 return; 53 return;
55 } 54 }
56 base::DictionaryValue details; 55 base::DictionaryValue details;
57 details.SetString("modelType", ModelTypeToString(model_type)); 56 details.SetString("modelType", ModelTypeToString(model_type));
58 details.SetString("writeTransactionId", 57 details.SetString("writeTransactionId",
59 base::Int64ToString(write_transaction_id)); 58 base::Int64ToString(write_transaction_id));
60 base::Value* changes_value = NULL; 59 base::Value* changes_value = NULL;
61 const size_t changes_size = changes.Get().size(); 60 const size_t changes_size = changes.Get().size();
62 if (changes_size <= kChangeLimit) { 61 if (changes_size <= kChangeLimit) {
63 base::ListValue* changes_list = new base::ListValue(); 62 base::ListValue* changes_list = new base::ListValue();
64 for (ChangeRecordList::const_iterator it = 63 for (ChangeRecordList::const_iterator it = changes.Get().begin();
65 changes.Get().begin(); it != changes.Get().end(); ++it) { 64 it != changes.Get().end(); ++it) {
66 changes_list->Append(it->ToValue()); 65 changes_list->Append(it->ToValue());
67 } 66 }
68 changes_value = changes_list; 67 changes_value = changes_list;
69 } else { 68 } else {
70 changes_value = 69 changes_value =
71 new base::StringValue( 70 new base::StringValue(base::SizeTToString(changes_size) + " changes");
72 base::SizeTToString(changes_size) + " changes");
73 } 71 }
74 details.Set("changes", changes_value); 72 details.Set("changes", changes_value);
75 HandleJsEvent(FROM_HERE, "onChangesApplied", JsEventDetails(&details)); 73 HandleJsEvent(FROM_HERE, "onChangesApplied", JsEventDetails(&details));
76 } 74 }
77 75
78 void JsMutationEventObserver::OnChangesComplete(ModelType model_type) { 76 void JsMutationEventObserver::OnChangesComplete(ModelType model_type) {
79 if (!event_handler_.IsInitialized()) { 77 if (!event_handler_.IsInitialized()) {
80 return; 78 return;
81 } 79 }
82 base::DictionaryValue details; 80 base::DictionaryValue details;
83 details.SetString("modelType", ModelTypeToString(model_type)); 81 details.SetString("modelType", ModelTypeToString(model_type));
84 HandleJsEvent(FROM_HERE, "onChangesComplete", JsEventDetails(&details)); 82 HandleJsEvent(FROM_HERE, "onChangesComplete", JsEventDetails(&details));
85 } 83 }
86 84
87 void JsMutationEventObserver::OnTransactionWrite( 85 void JsMutationEventObserver::OnTransactionWrite(
88 const syncable::ImmutableWriteTransactionInfo& write_transaction_info, 86 const syncable::ImmutableWriteTransactionInfo& write_transaction_info,
89 ModelTypeSet models_with_changes) { 87 ModelTypeSet models_with_changes) {
90 DCHECK(CalledOnValidThread()); 88 DCHECK(CalledOnValidThread());
91 if (!event_handler_.IsInitialized()) { 89 if (!event_handler_.IsInitialized()) {
92 return; 90 return;
93 } 91 }
94 base::DictionaryValue details; 92 base::DictionaryValue details;
95 details.Set("writeTransactionInfo", 93 details.Set("writeTransactionInfo",
96 write_transaction_info.Get().ToValue(kChangeLimit)); 94 write_transaction_info.Get().ToValue(kChangeLimit));
97 details.Set("modelsWithChanges", 95 details.Set("modelsWithChanges", ModelTypeSetToValue(models_with_changes));
98 ModelTypeSetToValue(models_with_changes));
99 HandleJsEvent(FROM_HERE, "onTransactionWrite", JsEventDetails(&details)); 96 HandleJsEvent(FROM_HERE, "onTransactionWrite", JsEventDetails(&details));
100 } 97 }
101 98
102 void JsMutationEventObserver::HandleJsEvent( 99 void JsMutationEventObserver::HandleJsEvent(
103 const tracked_objects::Location& from_here, 100 const tracked_objects::Location& from_here,
104 const std::string& name, const JsEventDetails& details) { 101 const std::string& name,
102 const JsEventDetails& details) {
105 if (!event_handler_.IsInitialized()) { 103 if (!event_handler_.IsInitialized()) {
106 NOTREACHED(); 104 NOTREACHED();
107 return; 105 return;
108 } 106 }
109 event_handler_.Call(from_here, 107 event_handler_.Call(from_here, &JsEventHandler::HandleJsEvent, name, details);
110 &JsEventHandler::HandleJsEvent, name, details);
111 } 108 }
112 109
113 } // namespace syncer 110 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698