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

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

Issue 2284283002: Remove stl_util's STLElementDeleter from sync. (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
« no previous file with comments | « no previous file | components/sync/core/sync_manager.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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>
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 2161 matching lines...) Expand 10 before | Expand all | Expand 10 after
2194 2195
2195 class GetAllNodesRequestHelper 2196 class GetAllNodesRequestHelper
2196 : public base::RefCountedThreadSafe<GetAllNodesRequestHelper> { 2197 : public base::RefCountedThreadSafe<GetAllNodesRequestHelper> {
2197 public: 2198 public:
2198 GetAllNodesRequestHelper( 2199 GetAllNodesRequestHelper(
2199 syncer::ModelTypeSet requested_types, 2200 syncer::ModelTypeSet requested_types,
2200 const base::Callback<void(std::unique_ptr<base::ListValue>)>& callback); 2201 const base::Callback<void(std::unique_ptr<base::ListValue>)>& callback);
2201 2202
2202 void OnReceivedNodesForTypes( 2203 void OnReceivedNodesForTypes(
2203 const std::vector<syncer::ModelType>& types, 2204 const std::vector<syncer::ModelType>& types,
2204 ScopedVector<base::ListValue> scoped_node_lists); 2205 std::vector<std::unique_ptr<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 };
(...skipping 10 matching lines...) Expand all
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 or set of types has been returned.
2232 // 2233 //
2233 // The nodes for several types can be returned at the same time by specifying 2234 // The nodes for several types can be returned at the same time by specifying
2234 // their types in the |types| array, and putting their results at the 2235 // their types in the |types| array, and putting their results at the
2235 // correspnding indices in the |scoped_node_lists|. 2236 // corresponding indices in the |node_lists|.
2236 void GetAllNodesRequestHelper::OnReceivedNodesForTypes( 2237 void GetAllNodesRequestHelper::OnReceivedNodesForTypes(
2237 const std::vector<syncer::ModelType>& types, 2238 const std::vector<syncer::ModelType>& types,
2238 ScopedVector<base::ListValue> scoped_node_lists) { 2239 std::vector<std::unique_ptr<base::ListValue>> node_lists) {
2239 DCHECK_EQ(types.size(), scoped_node_lists.size()); 2240 DCHECK_EQ(types.size(), node_lists.size());
2240
2241 // Take unsafe ownership of the node list.
2242 std::vector<base::ListValue*> node_lists;
2243 scoped_node_lists.release(&node_lists);
2244 2241
2245 for (size_t i = 0; i < node_lists.size() && i < types.size(); ++i) { 2242 for (size_t i = 0; i < node_lists.size() && i < types.size(); ++i) {
2246 const ModelType type = types[i]; 2243 const ModelType type = types[i];
2247 base::ListValue* node_list = node_lists[i]; 2244 std::unique_ptr<base::Value> node_list = std::move(node_lists[i]);
2248 2245
2249 // Add these results to our list. 2246 // Add these results to our list.
2250 std::unique_ptr<base::DictionaryValue> type_dict( 2247 std::unique_ptr<base::DictionaryValue> type_dict(
2251 new base::DictionaryValue()); 2248 new base::DictionaryValue());
2252 type_dict->SetString("type", ModelTypeToString(type)); 2249 type_dict->SetString("type", ModelTypeToString(type));
2253 type_dict->Set("nodes", node_list); 2250 type_dict->Set("nodes", std::move(node_list));
2254 result_accumulator_->Append(std::move(type_dict)); 2251 result_accumulator_->Append(std::move(type_dict));
2255 2252
2256 // Remember that this part of the request is satisfied. 2253 // Remember that this part of the request is satisfied.
2257 awaiting_types_.Remove(type); 2254 awaiting_types_.Remove(type);
2258 } 2255 }
2259 2256
2260 if (awaiting_types_.Empty()) { 2257 if (awaiting_types_.Empty()) {
2261 callback_.Run(std::move(result_accumulator_)); 2258 callback_.Run(std::move(result_accumulator_));
2262 callback_.Reset(); 2259 callback_.Reset();
2263 } 2260 }
2264 } 2261 }
2265 2262
2266 } // namespace 2263 } // namespace
2267 2264
2268 void ProfileSyncService::GetAllNodes( 2265 void ProfileSyncService::GetAllNodes(
2269 const base::Callback<void(std::unique_ptr<base::ListValue>)>& callback) { 2266 const base::Callback<void(std::unique_ptr<base::ListValue>)>& callback) {
2270 // TODO(stanisc): crbug.com/328606: Make this work for USS datatypes. 2267 // TODO(stanisc): crbug.com/328606: Make this work for USS datatypes.
2271 ModelTypeSet all_types = GetRegisteredDataTypes(); 2268 ModelTypeSet all_types = GetRegisteredDataTypes();
2272 all_types.PutAll(syncer::ControlTypes()); 2269 all_types.PutAll(syncer::ControlTypes());
2273 scoped_refptr<GetAllNodesRequestHelper> helper = 2270 scoped_refptr<GetAllNodesRequestHelper> helper =
2274 new GetAllNodesRequestHelper(all_types, callback); 2271 new GetAllNodesRequestHelper(all_types, callback);
2275 2272
2276 if (!backend_initialized_) { 2273 if (!backend_initialized_) {
2277 // If there's no backend available to fulfill the request, handle it here. 2274 // If there's no backend available to fulfill the request, handle it here.
2278 ScopedVector<base::ListValue> empty_results; 2275 std::vector<std::unique_ptr<base::ListValue>> empty_results;
2279 std::vector<ModelType> type_vector; 2276 std::vector<ModelType> type_vector;
2280 for (ModelTypeSet::Iterator it = all_types.First(); it.Good(); it.Inc()) { 2277 for (ModelTypeSet::Iterator it = all_types.First(); it.Good(); it.Inc()) {
2281 type_vector.push_back(it.Get()); 2278 type_vector.push_back(it.Get());
2282 empty_results.push_back(new base::ListValue()); 2279 empty_results.push_back(base::MakeUnique<base::ListValue>());
2283 } 2280 }
2284 helper->OnReceivedNodesForTypes(type_vector, std::move(empty_results)); 2281 helper->OnReceivedNodesForTypes(type_vector, std::move(empty_results));
2285 } else { 2282 } else {
2286 backend_->GetAllNodesForTypes( 2283 backend_->GetAllNodesForTypes(
2287 all_types, 2284 all_types,
2288 base::Bind(&GetAllNodesRequestHelper::OnReceivedNodesForTypes, helper)); 2285 base::Bind(&GetAllNodesRequestHelper::OnReceivedNodesForTypes, helper));
2289 } 2286 }
2290 } 2287 }
2291 2288
2292 bool ProfileSyncService::HasObserver( 2289 bool ProfileSyncService::HasObserver(
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
2533 if (--outstanding_setup_in_progress_handles_ != 0) 2530 if (--outstanding_setup_in_progress_handles_ != 0)
2534 return; 2531 return;
2535 2532
2536 DCHECK(startup_controller_->IsSetupInProgress()); 2533 DCHECK(startup_controller_->IsSetupInProgress());
2537 startup_controller_->SetSetupInProgress(false); 2534 startup_controller_->SetSetupInProgress(false);
2538 2535
2539 if (IsBackendInitialized()) 2536 if (IsBackendInitialized())
2540 ReconfigureDatatypeManager(); 2537 ReconfigureDatatypeManager();
2541 NotifyObservers(); 2538 NotifyObservers();
2542 } 2539 }
OLDNEW
« no previous file with comments | « no previous file | components/sync/core/sync_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698