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

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

Issue 2276943006: [USS] Move GetAllNodes from backend to controller (Closed)
Patch Set: 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 OnReceivedNodesForTypes(
maxbogue 2016/08/25 23:38:59 This should become OnReceivedNodesForType, since n
Gang Wu 2016/08/26 16:48:04 Done.
2203 const std::vector<syncer::ModelType>& types, 2205 const std::vector<syncer::ModelType>& types,
2204 ScopedVector<base::ListValue> scoped_node_lists); 2206 ScopedVector<base::ListValue> scoped_node_lists);
2205 2207
2206 private: 2208 private:
2207 friend class base::RefCountedThreadSafe<GetAllNodesRequestHelper>; 2209 friend class base::RefCountedThreadSafe<GetAllNodesRequestHelper>;
2208 virtual ~GetAllNodesRequestHelper(); 2210 virtual ~GetAllNodesRequestHelper();
2209 2211
2210 std::unique_ptr<base::ListValue> result_accumulator_; 2212 std::unique_ptr<base::ListValue> result_accumulator_;
2211 2213
2212 syncer::ModelTypeSet awaiting_types_; 2214 syncer::ModelTypeSet awaiting_types_;
(...skipping 30 matching lines...) Expand all
2243 scoped_node_lists.release(&node_lists); 2245 scoped_node_lists.release(&node_lists);
2244 2246
2245 for (size_t i = 0; i < node_lists.size() && i < types.size(); ++i) { 2247 for (size_t i = 0; i < node_lists.size() && i < types.size(); ++i) {
2246 const ModelType type = types[i]; 2248 const ModelType type = types[i];
2247 base::ListValue* node_list = node_lists[i]; 2249 base::ListValue* node_list = node_lists[i];
2248 2250
2249 // Add these results to our list. 2251 // Add these results to our list.
2250 std::unique_ptr<base::DictionaryValue> type_dict( 2252 std::unique_ptr<base::DictionaryValue> type_dict(
2251 new base::DictionaryValue()); 2253 new base::DictionaryValue());
2252 type_dict->SetString("type", ModelTypeToString(type)); 2254 type_dict->SetString("type", ModelTypeToString(type));
2253 type_dict->Set("nodes", node_list); 2255 type_dict->Set("nodes", node_list);
maxbogue 2016/08/25 23:38:59 Does this take ownership of the list pointer? Can
Gang Wu 2016/08/26 16:48:04 Done.
2254 result_accumulator_->Append(std::move(type_dict)); 2256 result_accumulator_->Append(std::move(type_dict));
2255 2257
2256 // Remember that this part of the request is satisfied. 2258 // Remember that this part of the request is satisfied.
2257 awaiting_types_.Remove(type); 2259 awaiting_types_.Remove(type);
2258 } 2260 }
2259 2261
2260 if (awaiting_types_.Empty()) { 2262 if (awaiting_types_.Empty()) {
2261 callback_.Run(std::move(result_accumulator_)); 2263 callback_.Run(std::move(result_accumulator_));
2262 callback_.Reset(); 2264 callback_.Reset();
2263 } 2265 }
2264 } 2266 }
2265 2267
2266 } // namespace 2268 } // namespace
2267 2269
2268 void ProfileSyncService::GetAllNodes( 2270 void ProfileSyncService::GetAllNodes(
2269 const base::Callback<void(std::unique_ptr<base::ListValue>)>& callback) { 2271 const base::Callback<void(std::unique_ptr<base::ListValue>)>& callback) {
2270 // TODO(stanisc): crbug.com/328606: Make this work for USS datatypes. 2272 // TODO(stanisc): crbug.com/328606: Make this work for USS datatypes.
2271 ModelTypeSet all_types = GetRegisteredDataTypes(); 2273 ModelTypeSet all_types = GetRegisteredDataTypes();
maxbogue 2016/08/25 23:38:59 Should this be using GetEnabledDataTypes()? It was
Gang Wu 2016/08/26 16:48:04 I did not find GetEnabledDataTypes(), so I let DTC
2272 all_types.PutAll(syncer::ControlTypes()); 2274 all_types.PutAll(syncer::ControlTypes());
2273 scoped_refptr<GetAllNodesRequestHelper> helper = 2275 scoped_refptr<GetAllNodesRequestHelper> helper =
2274 new GetAllNodesRequestHelper(all_types, callback); 2276 new GetAllNodesRequestHelper(all_types, callback);
2275 2277
2276 if (!backend_initialized_) { 2278 if (!backend_initialized_) {
2277 // If there's no backend available to fulfill the request, handle it here. 2279 // If there's no backend available to fulfill the request, handle it here.
2278 ScopedVector<base::ListValue> empty_results; 2280 ScopedVector<base::ListValue> empty_results;
2279 std::vector<ModelType> type_vector; 2281 std::vector<ModelType> type_vector;
2280 for (ModelTypeSet::Iterator it = all_types.First(); it.Good(); it.Inc()) { 2282 for (ModelTypeSet::Iterator it = all_types.First(); it.Good(); it.Inc()) {
2281 type_vector.push_back(it.Get()); 2283 type_vector.push_back(it.Get());
2282 empty_results.push_back(new base::ListValue()); 2284 empty_results.push_back(new base::ListValue());
2283 } 2285 }
2284 helper->OnReceivedNodesForTypes(type_vector, std::move(empty_results)); 2286 helper->OnReceivedNodesForTypes(type_vector, std::move(empty_results));
2285 } else { 2287 } else {
2286 backend_->GetAllNodesForTypes( 2288 GetAllNodesForTypes(
2287 all_types, 2289 all_types, base::ThreadTaskRunnerHandle::Get(),
2288 base::Bind(&GetAllNodesRequestHelper::OnReceivedNodesForTypes, helper)); 2290 base::Bind(&GetAllNodesRequestHelper::OnReceivedNodesForTypes, helper));
2289 } 2291 }
2290 } 2292 }
2291 2293
2292 bool ProfileSyncService::HasObserver( 2294 bool ProfileSyncService::HasObserver(
2293 const sync_driver::SyncServiceObserver* observer) const { 2295 const sync_driver::SyncServiceObserver* observer) const {
2294 return observers_.HasObserver(observer); 2296 return observers_.HasObserver(observer);
2295 } 2297 }
2296 2298
2297 base::WeakPtr<syncer::JsController> ProfileSyncService::GetJsController() { 2299 base::WeakPtr<syncer::JsController> ProfileSyncService::GetJsController() {
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
2533 if (--outstanding_setup_in_progress_handles_ != 0) 2535 if (--outstanding_setup_in_progress_handles_ != 0)
2534 return; 2536 return;
2535 2537
2536 DCHECK(startup_controller_->IsSetupInProgress()); 2538 DCHECK(startup_controller_->IsSetupInProgress());
2537 startup_controller_->SetSetupInProgress(false); 2539 startup_controller_->SetSetupInProgress(false);
2538 2540
2539 if (IsBackendInitialized()) 2541 if (IsBackendInitialized())
2540 ReconfigureDatatypeManager(); 2542 ReconfigureDatatypeManager();
2541 NotifyObservers(); 2543 NotifyObservers();
2542 } 2544 }
2545
2546 void ProfileSyncService::GetAllNodesForTypes(
2547 syncer::ModelTypeSet types,
2548 scoped_refptr<base::SequencedTaskRunner> task_runner,
2549 base::Callback<void(const std::vector<syncer::ModelType>& type,
2550 ScopedVector<base::ListValue>)> callback) {
2551 std::vector<syncer::ModelType> types_vector;
2552 ScopedVector<base::ListValue> node_lists;
2553
2554 for (syncer::ModelTypeSet::Iterator it = types.First(); it.Good(); it.Inc()) {
2555 DataTypeController::TypeMap::const_iterator iter =
2556 data_type_controllers_.find(it.Get());
2557 if (iter != data_type_controllers_.end()) {
2558 iter->second->GetAllNodes(base::ThreadTaskRunnerHandle::Get(), callback);
2559 } else {
2560 // Control Types
2561 types_vector.push_back(it.Get());
2562 node_lists.push_back(sync_driver::DirectoryDataTypeController::
2563 GetAllNodesForTypeFromDirectory(
2564 it.Get(), GetUserShare()->directory.get())
2565 .release());
2566 }
2567 }
2568
2569 if (!types_vector.empty()) {
2570 callback.Run(types_vector, std::move(node_lists));
2571 }
2572 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698