Chromium Code Reviews| OLD | NEW |
|---|---|
| 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> |
| 11 #include <utility> | 11 #include <utility> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/bind.h" | 14 #include "base/bind.h" |
| 15 #include "base/bind_helpers.h" | 15 #include "base/bind_helpers.h" |
| 16 #include "base/callback.h" | 16 #include "base/callback.h" |
| 17 #include "base/command_line.h" | 17 #include "base/command_line.h" |
| 18 #include "base/compiler_specific.h" | 18 #include "base/compiler_specific.h" |
| 19 #include "base/feature_list.h" | 19 #include "base/feature_list.h" |
| 20 #include "base/files/file_util.h" | 20 #include "base/files/file_util.h" |
| 21 #include "base/logging.h" | 21 #include "base/logging.h" |
| 22 #include "base/macros.h" | 22 #include "base/macros.h" |
| 23 #include "base/memory/ptr_util.h" | |
| 23 #include "base/memory/ref_counted.h" | 24 #include "base/memory/ref_counted.h" |
| 24 #include "base/metrics/histogram.h" | 25 #include "base/metrics/histogram.h" |
| 25 #include "base/profiler/scoped_tracker.h" | 26 #include "base/profiler/scoped_tracker.h" |
| 26 #include "base/single_thread_task_runner.h" | 27 #include "base/single_thread_task_runner.h" |
| 27 #include "base/strings/string16.h" | 28 #include "base/strings/string16.h" |
| 28 #include "base/strings/stringprintf.h" | 29 #include "base/strings/stringprintf.h" |
| 29 #include "base/threading/thread_restrictions.h" | 30 #include "base/threading/thread_restrictions.h" |
| 30 #include "base/threading/thread_task_runner_handle.h" | 31 #include "base/threading/thread_task_runner_handle.h" |
| 31 #include "base/time/time.h" | 32 #include "base/time/time.h" |
| 32 #include "build/build_config.h" | 33 #include "build/build_config.h" |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 54 #include "components/sync/core/shared_model_type_processor.h" | 55 #include "components/sync/core/shared_model_type_processor.h" |
| 55 #include "components/sync/core/shutdown_reason.h" | 56 #include "components/sync/core/shutdown_reason.h" |
| 56 #include "components/sync/core/sync_encryption_handler.h" | 57 #include "components/sync/core/sync_encryption_handler.h" |
| 57 #include "components/sync/device_info/device_info.h" | 58 #include "components/sync/device_info/device_info.h" |
| 58 #include "components/sync/device_info/device_info_service.h" | 59 #include "components/sync/device_info/device_info_service.h" |
| 59 #include "components/sync/device_info/device_info_sync_service.h" | 60 #include "components/sync/device_info/device_info_sync_service.h" |
| 60 #include "components/sync/device_info/device_info_tracker.h" | 61 #include "components/sync/device_info/device_info_tracker.h" |
| 61 #include "components/sync/driver/backend_migrator.h" | 62 #include "components/sync/driver/backend_migrator.h" |
| 62 #include "components/sync/driver/change_processor.h" | 63 #include "components/sync/driver/change_processor.h" |
| 63 #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" | |
| 64 #include "components/sync/driver/glue/chrome_report_unrecoverable_error.h" | 66 #include "components/sync/driver/glue/chrome_report_unrecoverable_error.h" |
| 65 #include "components/sync/driver/glue/sync_backend_host.h" | 67 #include "components/sync/driver/glue/sync_backend_host.h" |
| 66 #include "components/sync/driver/glue/sync_backend_host_impl.h" | 68 #include "components/sync/driver/glue/sync_backend_host_impl.h" |
| 67 #include "components/sync/driver/pref_names.h" | 69 #include "components/sync/driver/pref_names.h" |
| 68 #include "components/sync/driver/signin_manager_wrapper.h" | 70 #include "components/sync/driver/signin_manager_wrapper.h" |
| 69 #include "components/sync/driver/sync_api_component_factory.h" | 71 #include "components/sync/driver/sync_api_component_factory.h" |
| 70 #include "components/sync/driver/sync_client.h" | 72 #include "components/sync/driver/sync_client.h" |
| 71 #include "components/sync/driver/sync_driver_switches.h" | 73 #include "components/sync/driver/sync_driver_switches.h" |
| 72 #include "components/sync/driver/sync_error_controller.h" | 74 #include "components/sync/driver/sync_error_controller.h" |
| 73 #include "components/sync/driver/sync_stopped_reporter.h" | 75 #include "components/sync/driver/sync_stopped_reporter.h" |
| 74 #include "components/sync/driver/sync_type_preference_provider.h" | 76 #include "components/sync/driver/sync_type_preference_provider.h" |
| 75 #include "components/sync/driver/sync_util.h" | 77 #include "components/sync/driver/sync_util.h" |
| 76 #include "components/sync/driver/system_encryptor.h" | 78 #include "components/sync/driver/system_encryptor.h" |
| 77 #include "components/sync/driver/user_selectable_sync_type.h" | 79 #include "components/sync/driver/user_selectable_sync_type.h" |
| 78 #include "components/sync/engine/cycle/model_neutral_state.h" | 80 #include "components/sync/engine/cycle/model_neutral_state.h" |
| 79 #include "components/sync/engine/cycle/type_debug_info_observer.h" | 81 #include "components/sync/engine/cycle/type_debug_info_observer.h" |
| 80 #include "components/sync/engine/sync_string_conversions.h" | 82 #include "components/sync/engine/sync_string_conversions.h" |
| 81 #include "components/sync/js/js_event_details.h" | 83 #include "components/sync/js/js_event_details.h" |
| 82 #include "components/sync/protocol/sync.pb.h" | 84 #include "components/sync/protocol/sync.pb.h" |
| 83 #include "components/sync/syncable/directory.h" | 85 #include "components/sync/syncable/directory.h" |
| 86 #include "components/sync/syncable/syncable_read_transaction.h" | |
| 84 #include "components/sync_sessions/favicon_cache.h" | 87 #include "components/sync_sessions/favicon_cache.h" |
| 85 #include "components/sync_sessions/session_data_type_controller.h" | 88 #include "components/sync_sessions/session_data_type_controller.h" |
| 86 #include "components/sync_sessions/sessions_sync_manager.h" | 89 #include "components/sync_sessions/sessions_sync_manager.h" |
| 87 #include "components/sync_sessions/sync_sessions_client.h" | 90 #include "components/sync_sessions/sync_sessions_client.h" |
| 88 #include "components/syncable_prefs/pref_service_syncable.h" | 91 #include "components/syncable_prefs/pref_service_syncable.h" |
| 89 #include "components/version_info/version_info_values.h" | 92 #include "components/version_info/version_info_values.h" |
| 90 #include "net/cookies/cookie_monster.h" | 93 #include "net/cookies/cookie_monster.h" |
| 91 #include "net/url_request/url_request_context_getter.h" | 94 #include "net/url_request/url_request_context_getter.h" |
| 92 #include "ui/base/l10n/l10n_util.h" | 95 #include "ui/base/l10n/l10n_util.h" |
| 93 #include "ui/base/l10n/time_format.h" | 96 #include "ui/base/l10n/time_format.h" |
| (...skipping 2098 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2192 | 2195 |
| 2193 namespace { | 2196 namespace { |
| 2194 | 2197 |
| 2195 class GetAllNodesRequestHelper | 2198 class GetAllNodesRequestHelper |
| 2196 : public base::RefCountedThreadSafe<GetAllNodesRequestHelper> { | 2199 : public base::RefCountedThreadSafe<GetAllNodesRequestHelper> { |
| 2197 public: | 2200 public: |
| 2198 GetAllNodesRequestHelper( | 2201 GetAllNodesRequestHelper( |
| 2199 syncer::ModelTypeSet requested_types, | 2202 syncer::ModelTypeSet requested_types, |
| 2200 const base::Callback<void(std::unique_ptr<base::ListValue>)>& callback); | 2203 const base::Callback<void(std::unique_ptr<base::ListValue>)>& callback); |
| 2201 | 2204 |
| 2202 void OnReceivedNodesForTypes( | 2205 void OnReceivedNodesForType(const syncer::ModelType type, |
| 2203 const std::vector<syncer::ModelType>& types, | 2206 std::unique_ptr<base::ListValue> node_list); |
| 2204 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_; |
| 2213 base::Callback<void(std::unique_ptr<base::ListValue>)> callback_; | 2215 base::Callback<void(std::unique_ptr<base::ListValue>)> callback_; |
| 2214 }; | 2216 }; |
| 2215 | 2217 |
| 2216 GetAllNodesRequestHelper::GetAllNodesRequestHelper( | 2218 GetAllNodesRequestHelper::GetAllNodesRequestHelper( |
| 2217 syncer::ModelTypeSet requested_types, | 2219 syncer::ModelTypeSet requested_types, |
| 2218 const base::Callback<void(std::unique_ptr<base::ListValue>)>& callback) | 2220 const base::Callback<void(std::unique_ptr<base::ListValue>)>& callback) |
| 2219 : result_accumulator_(new base::ListValue()), | 2221 : result_accumulator_(new base::ListValue()), |
| 2220 awaiting_types_(requested_types), | 2222 awaiting_types_(requested_types), |
| 2221 callback_(callback) {} | 2223 callback_(callback) {} |
| 2222 | 2224 |
| 2223 GetAllNodesRequestHelper::~GetAllNodesRequestHelper() { | 2225 GetAllNodesRequestHelper::~GetAllNodesRequestHelper() { |
| 2224 if (!awaiting_types_.Empty()) { | 2226 if (!awaiting_types_.Empty()) { |
| 2225 DLOG(WARNING) | 2227 DLOG(WARNING) |
| 2226 << "GetAllNodesRequest deleted before request was fulfilled. " | 2228 << "GetAllNodesRequest deleted before request was fulfilled. " |
| 2227 << "Missing types are: " << ModelTypeSetToString(awaiting_types_); | 2229 << "Missing types are: " << ModelTypeSetToString(awaiting_types_); |
| 2228 } | 2230 } |
| 2229 } | 2231 } |
| 2230 | 2232 |
| 2231 // Called when the set of nodes for a type or set of types has been returned. | 2233 // Called when the set of nodes for a type has been returned. |
| 2232 // | 2234 // Only return one type of nodes each time. |
| 2233 // The nodes for several types can be returned at the same time by specifying | 2235 void GetAllNodesRequestHelper::OnReceivedNodesForType( |
| 2234 // their types in the |types| array, and putting their results at the | 2236 const syncer::ModelType type, |
| 2235 // correspnding indices in the |scoped_node_lists|. | 2237 std::unique_ptr<base::ListValue> node_list) { |
| 2236 void GetAllNodesRequestHelper::OnReceivedNodesForTypes( | 2238 // Add these results to our list. |
| 2237 const std::vector<syncer::ModelType>& types, | 2239 std::unique_ptr<base::DictionaryValue> type_dict(new base::DictionaryValue()); |
| 2238 ScopedVector<base::ListValue> scoped_node_lists) { | 2240 type_dict->SetString("type", ModelTypeToString(type)); |
| 2239 DCHECK_EQ(types.size(), scoped_node_lists.size()); | 2241 type_dict->Set("nodes", std::move(node_list)); |
| 2242 result_accumulator_->Append(std::move(type_dict)); | |
| 2240 | 2243 |
| 2241 // Take unsafe ownership of the node list. | 2244 // Remember that this part of the request is satisfied. |
| 2242 std::vector<base::ListValue*> node_lists; | 2245 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 | 2246 |
| 2260 if (awaiting_types_.Empty()) { | 2247 if (awaiting_types_.Empty()) { |
| 2261 callback_.Run(std::move(result_accumulator_)); | 2248 callback_.Run(std::move(result_accumulator_)); |
| 2262 callback_.Reset(); | 2249 callback_.Reset(); |
| 2263 } | 2250 } |
| 2264 } | 2251 } |
| 2265 | 2252 |
| 2266 } // namespace | 2253 } // namespace |
| 2267 | 2254 |
| 2268 void ProfileSyncService::GetAllNodes( | 2255 void ProfileSyncService::GetAllNodes( |
| 2269 const base::Callback<void(std::unique_ptr<base::ListValue>)>& callback) { | 2256 const base::Callback<void(std::unique_ptr<base::ListValue>)>& callback) { |
| 2270 // TODO(stanisc): crbug.com/328606: Make this work for USS datatypes. | 2257 // TODO(stanisc): crbug.com/328606: Make this work for USS datatypes. |
| 2271 ModelTypeSet all_types = GetRegisteredDataTypes(); | 2258 ModelTypeSet all_types = GetRegisteredDataTypes(); |
| 2272 all_types.PutAll(syncer::ControlTypes()); | 2259 all_types.PutAll(syncer::ControlTypes()); |
| 2273 scoped_refptr<GetAllNodesRequestHelper> helper = | 2260 scoped_refptr<GetAllNodesRequestHelper> helper = |
| 2274 new GetAllNodesRequestHelper(all_types, callback); | 2261 new GetAllNodesRequestHelper(all_types, callback); |
| 2275 | 2262 |
| 2276 if (!backend_initialized_) { | 2263 if (!backend_initialized_) { |
| 2277 // If there's no backend available to fulfill the request, handle it here. | 2264 // 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()) { | 2265 for (ModelTypeSet::Iterator it = all_types.First(); it.Good(); it.Inc()) { |
| 2281 type_vector.push_back(it.Get()); | 2266 helper->OnReceivedNodesForType(it.Get(), |
| 2282 empty_results.push_back(new base::ListValue()); | 2267 base::WrapUnique(new base::ListValue())); |
|
maxbogue
2016/08/29 21:21:16
nit: in this case you could just use base::MakeUni
Gang Wu
2016/08/30 20:56:01
Done.
| |
| 2283 } | 2268 } |
| 2284 helper->OnReceivedNodesForTypes(type_vector, std::move(empty_results)); | |
| 2285 } else { | 2269 } else { |
| 2286 backend_->GetAllNodesForTypes( | 2270 GetAllNodesForTypes( |
|
maxbogue
2016/08/29 21:21:16
I'm all for modularity, but GetAllNodesForTypes do
Gang Wu
2016/08/30 20:56:01
Done.
| |
| 2287 all_types, | 2271 all_types, |
| 2288 base::Bind(&GetAllNodesRequestHelper::OnReceivedNodesForTypes, helper)); | 2272 base::Bind(&GetAllNodesRequestHelper::OnReceivedNodesForType, helper)); |
| 2289 } | 2273 } |
| 2290 } | 2274 } |
| 2291 | 2275 |
| 2292 bool ProfileSyncService::HasObserver( | 2276 bool ProfileSyncService::HasObserver( |
| 2293 const sync_driver::SyncServiceObserver* observer) const { | 2277 const sync_driver::SyncServiceObserver* observer) const { |
| 2294 return observers_.HasObserver(observer); | 2278 return observers_.HasObserver(observer); |
| 2295 } | 2279 } |
| 2296 | 2280 |
| 2297 base::WeakPtr<syncer::JsController> ProfileSyncService::GetJsController() { | 2281 base::WeakPtr<syncer::JsController> ProfileSyncService::GetJsController() { |
| 2298 return sync_js_controller_.AsWeakPtr(); | 2282 return sync_js_controller_.AsWeakPtr(); |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2533 if (--outstanding_setup_in_progress_handles_ != 0) | 2517 if (--outstanding_setup_in_progress_handles_ != 0) |
| 2534 return; | 2518 return; |
| 2535 | 2519 |
| 2536 DCHECK(startup_controller_->IsSetupInProgress()); | 2520 DCHECK(startup_controller_->IsSetupInProgress()); |
| 2537 startup_controller_->SetSetupInProgress(false); | 2521 startup_controller_->SetSetupInProgress(false); |
| 2538 | 2522 |
| 2539 if (IsBackendInitialized()) | 2523 if (IsBackendInitialized()) |
| 2540 ReconfigureDatatypeManager(); | 2524 ReconfigureDatatypeManager(); |
| 2541 NotifyObservers(); | 2525 NotifyObservers(); |
| 2542 } | 2526 } |
| 2527 | |
| 2528 void ProfileSyncService::GetAllNodesForTypes( | |
| 2529 syncer::ModelTypeSet types, | |
| 2530 base::Callback<void(const syncer::ModelType, | |
| 2531 std::unique_ptr<base::ListValue>)> callback) { | |
| 2532 for (syncer::ModelTypeSet::Iterator it = types.First(); it.Good(); it.Inc()) { | |
| 2533 DataTypeController::TypeMap::const_iterator iter = | |
|
maxbogue
2016/08/29 21:21:16
This is really the sort of place it's great to use
Gang Wu
2016/08/30 20:56:01
Done.
| |
| 2534 data_type_controllers_.find(it.Get()); | |
| 2535 if (iter != data_type_controllers_.end()) { | |
| 2536 iter->second->GetAllNodes(callback); | |
| 2537 } else { | |
| 2538 // Control Types | |
| 2539 callback.Run(it.Get(), | |
| 2540 sync_driver::DirectoryDataTypeController:: | |
| 2541 GetAllNodesForTypeFromDirectory( | |
| 2542 it.Get(), GetUserShare()->directory.get())); | |
| 2543 } | |
| 2544 } | |
| 2545 } | |
| OLD | NEW |