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

Side by Side Diff: components/browser_sync/browser/profile_sync_service.cc

Issue 2276943006: [USS] Move GetAllNodes from backend to controller (Closed)
Patch Set: remove task runnner Created 4 years, 3 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/browser_sync/browser/profile_sync_service.h" 5 #include "components/browser_sync/browser/profile_sync_service.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <cstddef> 9 #include <cstddef>
10 #include <map> 10 #include <map>
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 #include "components/sync/core/shared_model_type_processor.h" 54 #include "components/sync/core/shared_model_type_processor.h"
55 #include "components/sync/core/shutdown_reason.h" 55 #include "components/sync/core/shutdown_reason.h"
56 #include "components/sync/core/sync_encryption_handler.h" 56 #include "components/sync/core/sync_encryption_handler.h"
57 #include "components/sync/device_info/device_info.h" 57 #include "components/sync/device_info/device_info.h"
58 #include "components/sync/device_info/device_info_service.h" 58 #include "components/sync/device_info/device_info_service.h"
59 #include "components/sync/device_info/device_info_sync_service.h" 59 #include "components/sync/device_info/device_info_sync_service.h"
60 #include "components/sync/device_info/device_info_tracker.h" 60 #include "components/sync/device_info/device_info_tracker.h"
61 #include "components/sync/driver/backend_migrator.h" 61 #include "components/sync/driver/backend_migrator.h"
62 #include "components/sync/driver/change_processor.h" 62 #include "components/sync/driver/change_processor.h"
63 #include "components/sync/driver/data_type_controller.h" 63 #include "components/sync/driver/data_type_controller.h"
64 #include "components/sync/driver/directory_data_type_controller.h"
64 #include "components/sync/driver/glue/chrome_report_unrecoverable_error.h" 65 #include "components/sync/driver/glue/chrome_report_unrecoverable_error.h"
65 #include "components/sync/driver/glue/sync_backend_host.h" 66 #include "components/sync/driver/glue/sync_backend_host.h"
66 #include "components/sync/driver/glue/sync_backend_host_impl.h" 67 #include "components/sync/driver/glue/sync_backend_host_impl.h"
67 #include "components/sync/driver/pref_names.h" 68 #include "components/sync/driver/pref_names.h"
68 #include "components/sync/driver/signin_manager_wrapper.h" 69 #include "components/sync/driver/signin_manager_wrapper.h"
69 #include "components/sync/driver/sync_api_component_factory.h" 70 #include "components/sync/driver/sync_api_component_factory.h"
70 #include "components/sync/driver/sync_client.h" 71 #include "components/sync/driver/sync_client.h"
71 #include "components/sync/driver/sync_driver_switches.h" 72 #include "components/sync/driver/sync_driver_switches.h"
72 #include "components/sync/driver/sync_error_controller.h" 73 #include "components/sync/driver/sync_error_controller.h"
73 #include "components/sync/driver/sync_stopped_reporter.h" 74 #include "components/sync/driver/sync_stopped_reporter.h"
74 #include "components/sync/driver/sync_type_preference_provider.h" 75 #include "components/sync/driver/sync_type_preference_provider.h"
75 #include "components/sync/driver/sync_util.h" 76 #include "components/sync/driver/sync_util.h"
76 #include "components/sync/driver/system_encryptor.h" 77 #include "components/sync/driver/system_encryptor.h"
77 #include "components/sync/driver/user_selectable_sync_type.h" 78 #include "components/sync/driver/user_selectable_sync_type.h"
78 #include "components/sync/engine/cycle/model_neutral_state.h" 79 #include "components/sync/engine/cycle/model_neutral_state.h"
79 #include "components/sync/engine/cycle/type_debug_info_observer.h" 80 #include "components/sync/engine/cycle/type_debug_info_observer.h"
80 #include "components/sync/engine/sync_string_conversions.h" 81 #include "components/sync/engine/sync_string_conversions.h"
81 #include "components/sync/js/js_event_details.h" 82 #include "components/sync/js/js_event_details.h"
82 #include "components/sync/protocol/sync.pb.h" 83 #include "components/sync/protocol/sync.pb.h"
83 #include "components/sync/syncable/directory.h" 84 #include "components/sync/syncable/directory.h"
85 #include "components/sync/syncable/syncable_read_transaction.h"
84 #include "components/sync_sessions/favicon_cache.h" 86 #include "components/sync_sessions/favicon_cache.h"
85 #include "components/sync_sessions/session_data_type_controller.h" 87 #include "components/sync_sessions/session_data_type_controller.h"
86 #include "components/sync_sessions/sessions_sync_manager.h" 88 #include "components/sync_sessions/sessions_sync_manager.h"
87 #include "components/sync_sessions/sync_sessions_client.h" 89 #include "components/sync_sessions/sync_sessions_client.h"
88 #include "components/syncable_prefs/pref_service_syncable.h" 90 #include "components/syncable_prefs/pref_service_syncable.h"
89 #include "components/version_info/version_info_values.h" 91 #include "components/version_info/version_info_values.h"
90 #include "net/cookies/cookie_monster.h" 92 #include "net/cookies/cookie_monster.h"
91 #include "net/url_request/url_request_context_getter.h" 93 #include "net/url_request/url_request_context_getter.h"
92 #include "ui/base/l10n/l10n_util.h" 94 #include "ui/base/l10n/l10n_util.h"
93 #include "ui/base/l10n/time_format.h" 95 #include "ui/base/l10n/time_format.h"
(...skipping 2098 matching lines...) Expand 10 before | Expand all | Expand 10 after
2192 2194
2193 namespace { 2195 namespace {
2194 2196
2195 class GetAllNodesRequestHelper 2197 class GetAllNodesRequestHelper
2196 : public base::RefCountedThreadSafe<GetAllNodesRequestHelper> { 2198 : public base::RefCountedThreadSafe<GetAllNodesRequestHelper> {
2197 public: 2199 public:
2198 GetAllNodesRequestHelper( 2200 GetAllNodesRequestHelper(
2199 syncer::ModelTypeSet requested_types, 2201 syncer::ModelTypeSet requested_types,
2200 const base::Callback<void(std::unique_ptr<base::ListValue>)>& callback); 2202 const base::Callback<void(std::unique_ptr<base::ListValue>)>& callback);
2201 2203
2202 void OnReceivedNodesForTypes( 2204 void OnReceivedNodesForType(const syncer::ModelType type,
2203 const std::vector<syncer::ModelType>& types, 2205 std::unique_ptr<base::ListValue> node_list);
2204 ScopedVector<base::ListValue> scoped_node_lists);
2205 2206
2206 private: 2207 private:
2207 friend class base::RefCountedThreadSafe<GetAllNodesRequestHelper>; 2208 friend class base::RefCountedThreadSafe<GetAllNodesRequestHelper>;
2208 virtual ~GetAllNodesRequestHelper(); 2209 virtual ~GetAllNodesRequestHelper();
2209 2210
2210 std::unique_ptr<base::ListValue> result_accumulator_; 2211 std::unique_ptr<base::ListValue> result_accumulator_;
2211 2212
2212 syncer::ModelTypeSet awaiting_types_; 2213 syncer::ModelTypeSet awaiting_types_;
2213 base::Callback<void(std::unique_ptr<base::ListValue>)> callback_; 2214 base::Callback<void(std::unique_ptr<base::ListValue>)> callback_;
2214 }; 2215 };
2215 2216
2216 GetAllNodesRequestHelper::GetAllNodesRequestHelper( 2217 GetAllNodesRequestHelper::GetAllNodesRequestHelper(
2217 syncer::ModelTypeSet requested_types, 2218 syncer::ModelTypeSet requested_types,
2218 const base::Callback<void(std::unique_ptr<base::ListValue>)>& callback) 2219 const base::Callback<void(std::unique_ptr<base::ListValue>)>& callback)
2219 : result_accumulator_(new base::ListValue()), 2220 : result_accumulator_(new base::ListValue()),
2220 awaiting_types_(requested_types), 2221 awaiting_types_(requested_types),
2221 callback_(callback) {} 2222 callback_(callback) {}
2222 2223
2223 GetAllNodesRequestHelper::~GetAllNodesRequestHelper() { 2224 GetAllNodesRequestHelper::~GetAllNodesRequestHelper() {
2224 if (!awaiting_types_.Empty()) { 2225 if (!awaiting_types_.Empty()) {
2225 DLOG(WARNING) 2226 DLOG(WARNING)
2226 << "GetAllNodesRequest deleted before request was fulfilled. " 2227 << "GetAllNodesRequest deleted before request was fulfilled. "
2227 << "Missing types are: " << ModelTypeSetToString(awaiting_types_); 2228 << "Missing types are: " << ModelTypeSetToString(awaiting_types_);
2228 } 2229 }
2229 } 2230 }
2230 2231
2231 // Called when the set of nodes for a type or set of types has been returned. 2232 // Called when the set of nodes for a type has been returned.
2232 // 2233 // Only return one type of nodes each time.
2233 // The nodes for several types can be returned at the same time by specifying 2234 void GetAllNodesRequestHelper::OnReceivedNodesForType(
2234 // their types in the |types| array, and putting their results at the 2235 const syncer::ModelType type,
2235 // correspnding indices in the |scoped_node_lists|. 2236 std::unique_ptr<base::ListValue> node_list) {
2236 void GetAllNodesRequestHelper::OnReceivedNodesForTypes( 2237 // Add these results to our list.
2237 const std::vector<syncer::ModelType>& types, 2238 std::unique_ptr<base::DictionaryValue> type_dict(new base::DictionaryValue());
2238 ScopedVector<base::ListValue> scoped_node_lists) { 2239 type_dict->SetString("type", ModelTypeToString(type));
2239 DCHECK_EQ(types.size(), scoped_node_lists.size()); 2240 type_dict->Set("nodes", std::move(node_list));
2241 result_accumulator_->Append(std::move(type_dict));
2240 2242
2241 // Take unsafe ownership of the node list. 2243 // Remember that this part of the request is satisfied.
2242 std::vector<base::ListValue*> node_lists; 2244 awaiting_types_.Remove(type);
2243 scoped_node_lists.release(&node_lists);
2244
2245 for (size_t i = 0; i < node_lists.size() && i < types.size(); ++i) {
2246 const ModelType type = types[i];
2247 base::ListValue* node_list = node_lists[i];
2248
2249 // Add these results to our list.
2250 std::unique_ptr<base::DictionaryValue> type_dict(
2251 new base::DictionaryValue());
2252 type_dict->SetString("type", ModelTypeToString(type));
2253 type_dict->Set("nodes", node_list);
2254 result_accumulator_->Append(std::move(type_dict));
2255
2256 // Remember that this part of the request is satisfied.
2257 awaiting_types_.Remove(type);
2258 }
2259 2245
2260 if (awaiting_types_.Empty()) { 2246 if (awaiting_types_.Empty()) {
2261 callback_.Run(std::move(result_accumulator_)); 2247 callback_.Run(std::move(result_accumulator_));
2262 callback_.Reset(); 2248 callback_.Reset();
2263 } 2249 }
2264 } 2250 }
2265 2251
2266 } // namespace 2252 } // namespace
2267 2253
2268 void ProfileSyncService::GetAllNodes( 2254 void ProfileSyncService::GetAllNodes(
2269 const base::Callback<void(std::unique_ptr<base::ListValue>)>& callback) { 2255 const base::Callback<void(std::unique_ptr<base::ListValue>)>& callback) {
2270 // TODO(stanisc): crbug.com/328606: Make this work for USS datatypes. 2256 // TODO(stanisc): crbug.com/328606: Make this work for USS datatypes.
2271 ModelTypeSet all_types = GetRegisteredDataTypes(); 2257 ModelTypeSet all_types = GetRegisteredDataTypes();
2272 all_types.PutAll(syncer::ControlTypes()); 2258 all_types.PutAll(syncer::ControlTypes());
2273 scoped_refptr<GetAllNodesRequestHelper> helper = 2259 scoped_refptr<GetAllNodesRequestHelper> helper =
2274 new GetAllNodesRequestHelper(all_types, callback); 2260 new GetAllNodesRequestHelper(all_types, callback);
2275 2261
2276 if (!backend_initialized_) { 2262 if (!backend_initialized_) {
2277 // If there's no backend available to fulfill the request, handle it here. 2263 // If there's no backend available to fulfill the request, handle it here.
2278 ScopedVector<base::ListValue> empty_results;
2279 std::vector<ModelType> type_vector;
2280 for (ModelTypeSet::Iterator it = all_types.First(); it.Good(); it.Inc()) { 2264 for (ModelTypeSet::Iterator it = all_types.First(); it.Good(); it.Inc()) {
2281 type_vector.push_back(it.Get()); 2265 std::unique_ptr<base::ListValue> empty_results;
2282 empty_results.push_back(new base::ListValue()); 2266 helper->OnReceivedNodesForType(it.Get(), std::move(empty_results));
2283 } 2267 }
2284 helper->OnReceivedNodesForTypes(type_vector, std::move(empty_results));
2285 } else { 2268 } else {
2286 backend_->GetAllNodesForTypes( 2269 GetAllNodesForTypes(
2287 all_types, 2270 all_types,
2288 base::Bind(&GetAllNodesRequestHelper::OnReceivedNodesForTypes, helper)); 2271 base::Bind(&GetAllNodesRequestHelper::OnReceivedNodesForType, helper));
2289 } 2272 }
2290 } 2273 }
2291 2274
2292 bool ProfileSyncService::HasObserver( 2275 bool ProfileSyncService::HasObserver(
2293 const sync_driver::SyncServiceObserver* observer) const { 2276 const sync_driver::SyncServiceObserver* observer) const {
2294 return observers_.HasObserver(observer); 2277 return observers_.HasObserver(observer);
2295 } 2278 }
2296 2279
2297 base::WeakPtr<syncer::JsController> ProfileSyncService::GetJsController() { 2280 base::WeakPtr<syncer::JsController> ProfileSyncService::GetJsController() {
2298 return sync_js_controller_.AsWeakPtr(); 2281 return sync_js_controller_.AsWeakPtr();
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
2533 if (--outstanding_setup_in_progress_handles_ != 0) 2516 if (--outstanding_setup_in_progress_handles_ != 0)
2534 return; 2517 return;
2535 2518
2536 DCHECK(startup_controller_->IsSetupInProgress()); 2519 DCHECK(startup_controller_->IsSetupInProgress());
2537 startup_controller_->SetSetupInProgress(false); 2520 startup_controller_->SetSetupInProgress(false);
2538 2521
2539 if (IsBackendInitialized()) 2522 if (IsBackendInitialized())
2540 ReconfigureDatatypeManager(); 2523 ReconfigureDatatypeManager();
2541 NotifyObservers(); 2524 NotifyObservers();
2542 } 2525 }
2526
2527 void ProfileSyncService::GetAllNodesForTypes(
2528 syncer::ModelTypeSet types,
2529 base::Callback<void(const syncer::ModelType,
2530 std::unique_ptr<base::ListValue>)> callback) {
2531 for (syncer::ModelTypeSet::Iterator it = types.First(); it.Good(); it.Inc()) {
2532 DataTypeController::TypeMap::const_iterator iter =
2533 data_type_controllers_.find(it.Get());
2534 if (iter != data_type_controllers_.end()) {
2535 iter->second->GetAllNodes(callback);
2536 } else {
2537 // Control Types
2538 callback.Run(it.Get(),
2539 sync_driver::DirectoryDataTypeController::
2540 GetAllNodesForTypeFromDirectory(
2541 it.Get(), GetUserShare()->directory.get()));
2542 }
2543 }
2544 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698