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

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

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

Powered by Google App Engine
This is Rietveld 408576698