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

Side by Side Diff: sync/internal_api/sync_manager_impl.cc

Issue 224563004: sync: Re-implement getAllNodes WebUI function (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Style fixes + comments Created 6 years, 8 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
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/sync_manager_impl.h" 5 #include "sync/internal_api/sync_manager_impl.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/base64.h" 9 #include "base/base64.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
13 #include "base/json/json_writer.h" 13 #include "base/json/json_writer.h"
14 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
15 #include "base/metrics/histogram.h" 15 #include "base/metrics/histogram.h"
16 #include "base/observer_list.h" 16 #include "base/observer_list.h"
17 #include "base/strings/string_number_conversions.h" 17 #include "base/strings/string_number_conversions.h"
18 #include "base/values.h" 18 #include "base/values.h"
19 #include "sync/engine/directory_type_debug_info_emitter.h"
19 #include "sync/engine/sync_scheduler.h" 20 #include "sync/engine/sync_scheduler.h"
20 #include "sync/engine/syncer_types.h" 21 #include "sync/engine/syncer_types.h"
21 #include "sync/internal_api/change_reorder_buffer.h" 22 #include "sync/internal_api/change_reorder_buffer.h"
22 #include "sync/internal_api/public/base/cancelation_signal.h" 23 #include "sync/internal_api/public/base/cancelation_signal.h"
23 #include "sync/internal_api/public/base/model_type.h" 24 #include "sync/internal_api/public/base/model_type.h"
24 #include "sync/internal_api/public/base_node.h" 25 #include "sync/internal_api/public/base_node.h"
25 #include "sync/internal_api/public/configure_reason.h" 26 #include "sync/internal_api/public/configure_reason.h"
26 #include "sync/internal_api/public/engine/polling_constants.h" 27 #include "sync/internal_api/public/engine/polling_constants.h"
27 #include "sync/internal_api/public/http_post_provider_factory.h" 28 #include "sync/internal_api/public/http_post_provider_factory.h"
28 #include "sync/internal_api/public/internal_components_factory.h" 29 #include "sync/internal_api/public/internal_components_factory.h"
29 #include "sync/internal_api/public/read_node.h" 30 #include "sync/internal_api/public/read_node.h"
30 #include "sync/internal_api/public/read_transaction.h" 31 #include "sync/internal_api/public/read_transaction.h"
31 #include "sync/internal_api/public/user_share.h" 32 #include "sync/internal_api/public/user_share.h"
32 #include "sync/internal_api/public/util/experiments.h" 33 #include "sync/internal_api/public/util/experiments.h"
33 #include "sync/internal_api/public/write_node.h" 34 #include "sync/internal_api/public/write_node.h"
34 #include "sync/internal_api/public/write_transaction.h" 35 #include "sync/internal_api/public/write_transaction.h"
35 #include "sync/internal_api/sync_core.h" 36 #include "sync/internal_api/sync_core.h"
36 #include "sync/internal_api/syncapi_internal.h" 37 #include "sync/internal_api/syncapi_internal.h"
37 #include "sync/internal_api/syncapi_server_connection_manager.h" 38 #include "sync/internal_api/syncapi_server_connection_manager.h"
38 #include "sync/js/js_arg_list.h"
39 #include "sync/js/js_reply_handler.h"
40 #include "sync/notifier/invalidation_util.h" 39 #include "sync/notifier/invalidation_util.h"
41 #include "sync/notifier/invalidator.h" 40 #include "sync/notifier/invalidator.h"
42 #include "sync/notifier/object_id_invalidation_map.h" 41 #include "sync/notifier/object_id_invalidation_map.h"
43 #include "sync/protocol/proto_value_conversions.h" 42 #include "sync/protocol/proto_value_conversions.h"
44 #include "sync/protocol/sync.pb.h" 43 #include "sync/protocol/sync.pb.h"
45 #include "sync/syncable/directory.h" 44 #include "sync/syncable/directory.h"
46 #include "sync/syncable/entry.h" 45 #include "sync/syncable/entry.h"
47 #include "sync/syncable/in_memory_directory_backing_store.h" 46 #include "sync/syncable/in_memory_directory_backing_store.h"
48 #include "sync/syncable/on_disk_directory_backing_store.h" 47 #include "sync/syncable/on_disk_directory_backing_store.h"
49 48
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 observing_network_connectivity_changes_(false), 168 observing_network_connectivity_changes_(false),
170 invalidator_state_(DEFAULT_INVALIDATION_ERROR), 169 invalidator_state_(DEFAULT_INVALIDATION_ERROR),
171 encryptor_(NULL), 170 encryptor_(NULL),
172 report_unrecoverable_error_function_(NULL), 171 report_unrecoverable_error_function_(NULL),
173 weak_ptr_factory_(this) { 172 weak_ptr_factory_(this) {
174 // Pre-fill |notification_info_map_|. 173 // Pre-fill |notification_info_map_|.
175 for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; ++i) { 174 for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; ++i) {
176 notification_info_map_.insert( 175 notification_info_map_.insert(
177 std::make_pair(ModelTypeFromInt(i), NotificationInfo())); 176 std::make_pair(ModelTypeFromInt(i), NotificationInfo()));
178 } 177 }
179
180 // Bind message handlers.
181 BindJsMessageHandler(
182 "getAllNodes",
183 &SyncManagerImpl::GetAllNodes);
184 } 178 }
185 179
186 SyncManagerImpl::~SyncManagerImpl() { 180 SyncManagerImpl::~SyncManagerImpl() {
187 DCHECK(thread_checker_.CalledOnValidThread()); 181 DCHECK(thread_checker_.CalledOnValidThread());
188 CHECK(!initialized_); 182 CHECK(!initialized_);
189 } 183 }
190 184
191 SyncManagerImpl::NotificationInfo::NotificationInfo() : total_count(0) {} 185 SyncManagerImpl::NotificationInfo::NotificationInfo() : total_count(0) {}
192 SyncManagerImpl::NotificationInfo::~NotificationInfo() {} 186 SyncManagerImpl::NotificationInfo::~NotificationInfo() {}
193 187
(...skipping 748 matching lines...) Expand 10 before | Expand all | Expand 10 after
942 OnProtocolEvent(event)); 936 OnProtocolEvent(event));
943 } 937 }
944 938
945 void SyncManagerImpl::SetJsEventHandler( 939 void SyncManagerImpl::SetJsEventHandler(
946 const WeakHandle<JsEventHandler>& event_handler) { 940 const WeakHandle<JsEventHandler>& event_handler) {
947 js_sync_manager_observer_.SetJsEventHandler(event_handler); 941 js_sync_manager_observer_.SetJsEventHandler(event_handler);
948 js_mutation_event_observer_.SetJsEventHandler(event_handler); 942 js_mutation_event_observer_.SetJsEventHandler(event_handler);
949 js_sync_encryption_handler_observer_.SetJsEventHandler(event_handler); 943 js_sync_encryption_handler_observer_.SetJsEventHandler(event_handler);
950 } 944 }
951 945
946 // TODO(rlarocque): This function is no longer needed and should be removed.
947 // See http://crbug.com/357821.
952 void SyncManagerImpl::ProcessJsMessage( 948 void SyncManagerImpl::ProcessJsMessage(
953 const std::string& name, const JsArgList& args, 949 const std::string& name, const JsArgList& args,
954 const WeakHandle<JsReplyHandler>& reply_handler) { 950 const WeakHandle<JsReplyHandler>& reply_handler) {
955 if (!initialized_) { 951 NOTREACHED();
956 NOTREACHED(); 952 }
957 return; 953
954 scoped_ptr<base::ListValue> SyncManagerImpl::GetAllNodesForType(
955 syncer::ModelType type) {
956 DirectoryTypeDebugInfoEmitterMap* emitter_map =
957 model_type_registry_->directory_type_debug_info_emitter_map();
958 DirectoryTypeDebugInfoEmitterMap::iterator it = emitter_map->find(type);
959
960 if (it == emitter_map->end()) {
961 NOTREACHED() << "Asked to return debug info for invalid type "
962 << ModelTypeToString(type);
963 return scoped_ptr<base::ListValue>();
958 } 964 }
959 965
960 if (!reply_handler.IsInitialized()) { 966 return it->second->GetAllNodes();
961 DVLOG(1) << "Uninitialized reply handler; dropping unknown message "
962 << name << " with args " << args.ToString();
963 return;
964 }
965
966 JsMessageHandler js_message_handler = js_message_handlers_[name];
967 if (js_message_handler.is_null()) {
968 DVLOG(1) << "Dropping unknown message " << name
969 << " with args " << args.ToString();
970 return;
971 }
972
973 reply_handler.Call(FROM_HERE,
974 &JsReplyHandler::HandleJsReply,
975 name, js_message_handler.Run(args));
976 }
977
978 void SyncManagerImpl::BindJsMessageHandler(
979 const std::string& name,
980 UnboundJsMessageHandler unbound_message_handler) {
981 js_message_handlers_[name] =
982 base::Bind(unbound_message_handler, base::Unretained(this));
983 }
984
985 JsArgList SyncManagerImpl::GetAllNodes(const JsArgList& args) {
986 ReadTransaction trans(FROM_HERE, GetUserShare());
987 base::ListValue return_args;
988 scoped_ptr<base::ListValue> nodes(
989 trans.GetDirectory()->GetAllNodeDetails(trans.GetWrappedTrans()));
990 return_args.Append(nodes.release());
991 return JsArgList(&return_args);
992 } 967 }
993 968
994 void SyncManagerImpl::OnInvalidatorStateChange(InvalidatorState state) { 969 void SyncManagerImpl::OnInvalidatorStateChange(InvalidatorState state) {
995 DCHECK(thread_checker_.CalledOnValidThread()); 970 DCHECK(thread_checker_.CalledOnValidThread());
996 971
997 const std::string& state_str = InvalidatorStateToString(state); 972 const std::string& state_str = InvalidatorStateToString(state);
998 invalidator_state_ = state; 973 invalidator_state_ = state;
999 DVLOG(1) << "Invalidator state changed to: " << state_str; 974 DVLOG(1) << "Invalidator state changed to: " << state_str;
1000 const bool notifications_enabled = 975 const bool notifications_enabled =
1001 (invalidator_state_ == INVALIDATIONS_ENABLED); 976 (invalidator_state_ == INVALIDATIONS_ENABLED);
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
1153 int SyncManagerImpl::GetDefaultNudgeDelay() { 1128 int SyncManagerImpl::GetDefaultNudgeDelay() {
1154 return kDefaultNudgeDelayMilliseconds; 1129 return kDefaultNudgeDelayMilliseconds;
1155 } 1130 }
1156 1131
1157 // static. 1132 // static.
1158 int SyncManagerImpl::GetPreferencesNudgeDelay() { 1133 int SyncManagerImpl::GetPreferencesNudgeDelay() {
1159 return kPreferencesNudgeDelayMilliseconds; 1134 return kPreferencesNudgeDelayMilliseconds;
1160 } 1135 }
1161 1136
1162 } // namespace syncer 1137 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698