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

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

Issue 2889163002: Remove raw DictionaryValue::Set in //components (Closed)
Patch Set: Nits Created 3 years, 6 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 "components/sync/engine_impl/js_mutation_event_observer.h" 5 #include "components/sync/engine_impl/js_mutation_event_observer.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <utility>
8 9
9 #include "base/location.h" 10 #include "base/location.h"
10 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/memory/ptr_util.h"
11 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
12 #include "base/values.h" 14 #include "base/values.h"
13 #include "components/sync/js/js_event_details.h" 15 #include "components/sync/js/js_event_details.h"
14 #include "components/sync/js/js_event_handler.h" 16 #include "components/sync/js/js_event_handler.h"
15 17
16 namespace syncer { 18 namespace syncer {
17 19
18 JsMutationEventObserver::JsMutationEventObserver() : weak_ptr_factory_(this) {} 20 JsMutationEventObserver::JsMutationEventObserver() : weak_ptr_factory_(this) {}
19 21
20 JsMutationEventObserver::~JsMutationEventObserver() { 22 JsMutationEventObserver::~JsMutationEventObserver() {
(...skipping 25 matching lines...) Expand all
46 ModelType model_type, 48 ModelType model_type,
47 int64_t write_transaction_id, 49 int64_t write_transaction_id,
48 const ImmutableChangeRecordList& changes) { 50 const ImmutableChangeRecordList& changes) {
49 if (!event_handler_.IsInitialized()) { 51 if (!event_handler_.IsInitialized()) {
50 return; 52 return;
51 } 53 }
52 base::DictionaryValue details; 54 base::DictionaryValue details;
53 details.SetString("modelType", ModelTypeToString(model_type)); 55 details.SetString("modelType", ModelTypeToString(model_type));
54 details.SetString("writeTransactionId", 56 details.SetString("writeTransactionId",
55 base::Int64ToString(write_transaction_id)); 57 base::Int64ToString(write_transaction_id));
56 base::Value* changes_value = nullptr; 58 std::unique_ptr<base::Value> changes_value;
57 const size_t changes_size = changes.Get().size(); 59 const size_t changes_size = changes.Get().size();
58 if (changes_size <= kChangeLimit) { 60 if (changes_size <= kChangeLimit) {
59 base::ListValue* changes_list = new base::ListValue(); 61 auto changes_list = base::MakeUnique<base::ListValue>();
60 for (ChangeRecordList::const_iterator it = changes.Get().begin(); 62 for (ChangeRecordList::const_iterator it = changes.Get().begin();
61 it != changes.Get().end(); ++it) { 63 it != changes.Get().end(); ++it) {
62 changes_list->Append(it->ToValue()); 64 changes_list->Append(it->ToValue());
63 } 65 }
64 changes_value = changes_list; 66 changes_value = std::move(changes_list);
65 } else { 67 } else {
66 changes_value = 68 changes_value = base::MakeUnique<base::Value>(
67 new base::Value(base::SizeTToString(changes_size) + " changes"); 69 base::SizeTToString(changes_size) + " changes");
68 } 70 }
69 details.Set("changes", changes_value); 71 details.Set("changes", std::move(changes_value));
70 HandleJsEvent(FROM_HERE, "onChangesApplied", JsEventDetails(&details)); 72 HandleJsEvent(FROM_HERE, "onChangesApplied", JsEventDetails(&details));
71 } 73 }
72 74
73 void JsMutationEventObserver::OnChangesComplete(ModelType model_type) { 75 void JsMutationEventObserver::OnChangesComplete(ModelType model_type) {
74 if (!event_handler_.IsInitialized()) { 76 if (!event_handler_.IsInitialized()) {
75 return; 77 return;
76 } 78 }
77 base::DictionaryValue details; 79 base::DictionaryValue details;
78 details.SetString("modelType", ModelTypeToString(model_type)); 80 details.SetString("modelType", ModelTypeToString(model_type));
79 HandleJsEvent(FROM_HERE, "onChangesComplete", JsEventDetails(&details)); 81 HandleJsEvent(FROM_HERE, "onChangesComplete", JsEventDetails(&details));
(...skipping 18 matching lines...) Expand all
98 const std::string& name, 100 const std::string& name,
99 const JsEventDetails& details) { 101 const JsEventDetails& details) {
100 if (!event_handler_.IsInitialized()) { 102 if (!event_handler_.IsInitialized()) {
101 NOTREACHED(); 103 NOTREACHED();
102 return; 104 return;
103 } 105 }
104 event_handler_.Call(from_here, &JsEventHandler::HandleJsEvent, name, details); 106 event_handler_.Call(from_here, &JsEventHandler::HandleJsEvent, name, details);
105 } 107 }
106 108
107 } // namespace syncer 109 } // namespace syncer
OLDNEW
« no previous file with comments | « components/sync/engine/events/protocol_event.cc ('k') | components/sync/engine_impl/js_mutation_event_observer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698