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

Unified Diff: sync/internal_api/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, 5 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 side-by-side diff with in-line comments
Download patch
Index: sync/internal_api/js_mutation_event_observer.cc
diff --git a/sync/internal_api/js_mutation_event_observer.cc b/sync/internal_api/js_mutation_event_observer.cc
deleted file mode 100644
index 857d723e39e7cac6765b3707238a83b679d5bdbc..0000000000000000000000000000000000000000
--- a/sync/internal_api/js_mutation_event_observer.cc
+++ /dev/null
@@ -1,113 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "sync/internal_api/js_mutation_event_observer.h"
-
-#include <stddef.h>
-#include <stdint.h>
-
-#include <string>
-
-#include "base/location.h"
-#include "base/logging.h"
-#include "base/strings/string_number_conversions.h"
-#include "base/values.h"
-#include "sync/js/js_event_details.h"
-#include "sync/js/js_event_handler.h"
-
-namespace syncer {
-
-JsMutationEventObserver::JsMutationEventObserver()
- : weak_ptr_factory_(this) {}
-
-JsMutationEventObserver::~JsMutationEventObserver() {
- DCHECK(CalledOnValidThread());
-}
-
-base::WeakPtr<JsMutationEventObserver> JsMutationEventObserver::AsWeakPtr() {
- return weak_ptr_factory_.GetWeakPtr();
-}
-
-void JsMutationEventObserver::InvalidateWeakPtrs() {
- weak_ptr_factory_.InvalidateWeakPtrs();
-}
-
-void JsMutationEventObserver::SetJsEventHandler(
- const WeakHandle<JsEventHandler>& event_handler) {
- event_handler_ = event_handler;
-}
-
-namespace {
-
-// Max number of changes we attempt to convert to values (to avoid
-// running out of memory).
-const size_t kChangeLimit = 100;
-
-} // namespace
-
-void JsMutationEventObserver::OnChangesApplied(
- ModelType model_type,
- int64_t write_transaction_id,
- const ImmutableChangeRecordList& changes) {
- if (!event_handler_.IsInitialized()) {
- return;
- }
- base::DictionaryValue details;
- details.SetString("modelType", ModelTypeToString(model_type));
- details.SetString("writeTransactionId",
- base::Int64ToString(write_transaction_id));
- base::Value* changes_value = NULL;
- const size_t changes_size = changes.Get().size();
- if (changes_size <= kChangeLimit) {
- base::ListValue* changes_list = new base::ListValue();
- for (ChangeRecordList::const_iterator it =
- changes.Get().begin(); it != changes.Get().end(); ++it) {
- changes_list->Append(it->ToValue());
- }
- changes_value = changes_list;
- } else {
- changes_value =
- new base::StringValue(
- base::SizeTToString(changes_size) + " changes");
- }
- details.Set("changes", changes_value);
- HandleJsEvent(FROM_HERE, "onChangesApplied", JsEventDetails(&details));
-}
-
-void JsMutationEventObserver::OnChangesComplete(ModelType model_type) {
- if (!event_handler_.IsInitialized()) {
- return;
- }
- base::DictionaryValue details;
- details.SetString("modelType", ModelTypeToString(model_type));
- HandleJsEvent(FROM_HERE, "onChangesComplete", JsEventDetails(&details));
-}
-
-void JsMutationEventObserver::OnTransactionWrite(
- const syncable::ImmutableWriteTransactionInfo& write_transaction_info,
- ModelTypeSet models_with_changes) {
- DCHECK(CalledOnValidThread());
- if (!event_handler_.IsInitialized()) {
- return;
- }
- base::DictionaryValue details;
- details.Set("writeTransactionInfo",
- write_transaction_info.Get().ToValue(kChangeLimit));
- details.Set("modelsWithChanges",
- ModelTypeSetToValue(models_with_changes));
- HandleJsEvent(FROM_HERE, "onTransactionWrite", JsEventDetails(&details));
-}
-
-void JsMutationEventObserver::HandleJsEvent(
- const tracked_objects::Location& from_here,
- const std::string& name, const JsEventDetails& details) {
- if (!event_handler_.IsInitialized()) {
- NOTREACHED();
- return;
- }
- event_handler_.Call(from_here,
- &JsEventHandler::HandleJsEvent, name, details);
-}
-
-} // namespace syncer
« no previous file with comments | « sync/internal_api/js_mutation_event_observer.h ('k') | sync/internal_api/js_mutation_event_observer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698