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

Side by Side Diff: chrome/browser/sync/js_transaction_observer.cc

Issue 7497051: sync: Move all the js_* files into a js/ subdirectory. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 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 | Annotate | Revision Log
OLDNEW
(Empty)
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_transaction_observer.h"
6
7 #include <sstream>
8 #include <string>
9
10 #include "base/logging.h"
11 #include "base/tracked.h"
12 #include "base/values.h"
13 #include "chrome/browser/sync/js_event_details.h"
14 #include "chrome/browser/sync/js_event_handler.h"
15
16 namespace browser_sync {
17
18 JsTransactionObserver::JsTransactionObserver() {}
19
20 JsTransactionObserver::~JsTransactionObserver() {
21 DCHECK(non_thread_safe_.CalledOnValidThread());
22 }
23
24 void JsTransactionObserver::SetJsEventHandler(
25 const WeakHandle<JsEventHandler>& event_handler) {
26 event_handler_ = event_handler;
27 }
28
29 namespace {
30
31 std::string GetLocationString(const tracked_objects::Location& location) {
32 std::ostringstream oss;
33 oss << location.function_name() << "@"
34 << location.file_name() << ":" << location.line_number();
35 return oss.str();
36 }
37
38 } // namespace
39
40 void JsTransactionObserver::OnTransactionStart(
41 const tracked_objects::Location& location,
42 const syncable::WriterTag& writer) {
43 DCHECK(non_thread_safe_.CalledOnValidThread());
44 if (!event_handler_.IsInitialized()) {
45 return;
46 }
47 DictionaryValue details;
48 details.SetString("location", GetLocationString(location));
49 details.SetString("writer", syncable::WriterTagToString(writer));
50 HandleJsEvent(FROM_HERE, "onTransactionStart", JsEventDetails(&details));
51 }
52
53 void JsTransactionObserver::OnTransactionMutate(
54 const tracked_objects::Location& location,
55 const syncable::WriterTag& writer,
56 const syncable::EntryKernelMutationSet& mutations,
57 const syncable::ModelTypeBitSet& models_with_changes) {
58 DCHECK(non_thread_safe_.CalledOnValidThread());
59 if (!event_handler_.IsInitialized()) {
60 return;
61 }
62 DictionaryValue details;
63 details.SetString("location", GetLocationString(location));
64 details.SetString("writer", syncable::WriterTagToString(writer));
65 details.Set("mutations", syncable::EntryKernelMutationSetToValue(mutations));
66 details.Set("modelsWithChanges",
67 syncable::ModelTypeBitSetToValue(models_with_changes));
68 HandleJsEvent(FROM_HERE, "onTransactionMutate", JsEventDetails(&details));
69 }
70
71 void JsTransactionObserver::OnTransactionEnd(
72 const tracked_objects::Location& location,
73 const syncable::WriterTag& writer) {
74 DCHECK(non_thread_safe_.CalledOnValidThread());
75 if (!event_handler_.IsInitialized()) {
76 return;
77 }
78 DictionaryValue details;
79 details.SetString("location", GetLocationString(location));
80 details.SetString("writer", syncable::WriterTagToString(writer));
81 HandleJsEvent(FROM_HERE, "onTransactionEnd", JsEventDetails(&details));
82 }
83
84 void JsTransactionObserver::HandleJsEvent(
85 const tracked_objects::Location& from_here,
86 const std::string& name, const JsEventDetails& details) {
87 if (!event_handler_.IsInitialized()) {
88 NOTREACHED();
89 return;
90 }
91 event_handler_.Call(from_here,
92 &JsEventHandler::HandleJsEvent, name, details);
93 }
94
95 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/js_transaction_observer.h ('k') | chrome/browser/sync/profile_sync_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698