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

Side by Side Diff: chrome/browser/sync/profile_sync_service.cc

Issue 224563004: sync: Re-implement getAllNodes WebUI function (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Style fixes + comments Created 6 years, 8 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 | Annotate | Revision Log
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 "chrome/browser/sync/profile_sync_service.h" 5 #include "chrome/browser/sync/profile_sync_service.h"
6 6
7 #include <cstddef> 7 #include <cstddef>
8 #include <map> 8 #include <map>
9 #include <set> 9 #include <set>
10 #include <utility> 10 #include <utility>
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 #include "grit/generated_resources.h" 75 #include "grit/generated_resources.h"
76 #include "net/cookies/cookie_monster.h" 76 #include "net/cookies/cookie_monster.h"
77 #include "net/url_request/url_request_context_getter.h" 77 #include "net/url_request/url_request_context_getter.h"
78 #include "sync/api/sync_error.h" 78 #include "sync/api/sync_error.h"
79 #include "sync/internal_api/public/configure_reason.h" 79 #include "sync/internal_api/public/configure_reason.h"
80 #include "sync/internal_api/public/http_bridge_network_resources.h" 80 #include "sync/internal_api/public/http_bridge_network_resources.h"
81 #include "sync/internal_api/public/network_resources.h" 81 #include "sync/internal_api/public/network_resources.h"
82 #include "sync/internal_api/public/sync_encryption_handler.h" 82 #include "sync/internal_api/public/sync_encryption_handler.h"
83 #include "sync/internal_api/public/util/experiments.h" 83 #include "sync/internal_api/public/util/experiments.h"
84 #include "sync/internal_api/public/util/sync_string_conversions.h" 84 #include "sync/internal_api/public/util/sync_string_conversions.h"
85 #include "sync/js/js_arg_list.h"
86 #include "sync/js/js_event_details.h" 85 #include "sync/js/js_event_details.h"
87 #include "sync/util/cryptographer.h" 86 #include "sync/util/cryptographer.h"
88 #include "ui/base/l10n/l10n_util.h" 87 #include "ui/base/l10n/l10n_util.h"
89 #include "ui/base/l10n/time_format.h" 88 #include "ui/base/l10n/time_format.h"
90 89
91 #if defined(ENABLE_MANAGED_USERS) 90 #if defined(ENABLE_MANAGED_USERS)
92 #include "chrome/browser/managed_mode/managed_user_constants.h" 91 #include "chrome/browser/managed_mode/managed_user_constants.h"
93 #endif 92 #endif
94 93
95 #if defined(OS_ANDROID) 94 #if defined(OS_ANDROID)
(...skipping 1976 matching lines...) Expand 10 before | Expand all | Expand 10 after
2072 } 2071 }
2073 2072
2074 void ProfileSyncService::RemoveProtocolEventObserver( 2073 void ProfileSyncService::RemoveProtocolEventObserver(
2075 browser_sync::ProtocolEventObserver* observer) { 2074 browser_sync::ProtocolEventObserver* observer) {
2076 protocol_event_observers_.RemoveObserver(observer); 2075 protocol_event_observers_.RemoveObserver(observer);
2077 if (backend_ && !protocol_event_observers_.might_have_observers()) { 2076 if (backend_ && !protocol_event_observers_.might_have_observers()) {
2078 backend_->DisableProtocolEventForwarding(); 2077 backend_->DisableProtocolEventForwarding();
2079 } 2078 }
2080 } 2079 }
2081 2080
2081 namespace {
2082
2083 class GetAllNodesRequestHelper
2084 : public base::RefCountedThreadSafe<GetAllNodesRequestHelper> {
2085 public:
2086 GetAllNodesRequestHelper(
2087 syncer::ModelTypeSet requested_types,
2088 base::Callback<void(scoped_ptr<base::ListValue>)> callback);
Nicolas Zea 2014/04/04 23:01:27 pass callbacks by const ref, here and elsewhere
rlarocque 2014/04/05 00:07:27 Done.
2089
2090 void OnReceivedNodesForTypes(
Nicolas Zea 2014/04/04 23:01:27 Comment for method. In particular, what is |types|
rlarocque 2014/04/05 00:07:27 Done.
2091 std::vector<syncer::ModelType> types,
Nicolas Zea 2014/04/04 23:01:27 pass types by const ref (and maybe scoped_node_lis
rlarocque 2014/04/05 00:07:27 The scoped_node_list is not const for a reason. T
2092 ScopedVector<base::ListValue> scoped_node_lists);
2093
2094 private:
2095 friend class base::RefCountedThreadSafe<GetAllNodesRequestHelper>;
2096 ~GetAllNodesRequestHelper();
Nicolas Zea 2014/04/04 23:01:27 virtual
rlarocque 2014/04/05 00:07:27 Done.
2097
2098 scoped_ptr<base::ListValue> result_accumulator_;
2099
2100 syncer::ModelTypeSet awaiting_types_;
2101 base::Callback<void(scoped_ptr<base::ListValue>)> callback_;
2102 };
2103
2104 GetAllNodesRequestHelper::GetAllNodesRequestHelper(
2105 syncer::ModelTypeSet requested_types,
2106 base::Callback<void(scoped_ptr<base::ListValue>)> callback)
2107 : result_accumulator_(new base::ListValue()),
Nicolas Zea 2014/04/04 23:01:27 indent by two more spaces
rlarocque 2014/04/05 00:07:27 Done.
2108 awaiting_types_(requested_types),
2109 callback_(callback) {}
2110
2111 GetAllNodesRequestHelper::~GetAllNodesRequestHelper() {
2112 if (!awaiting_types_.Empty()) {
2113 DLOG(WARNING)
2114 << "GetAllNodesRequest deleted before request was fulfilled. "
2115 << "Missing types are: " << ModelTypeSetToString(awaiting_types_);
2116 }
2117 }
2118
2119 void GetAllNodesRequestHelper::OnReceivedNodesForTypes(
2120 std::vector<syncer::ModelType> types,
2121 ScopedVector<base::ListValue> scoped_node_lists) {
2122 DCHECK_EQ(types.size(), scoped_node_lists.size());
2123
2124 // Take unsafe ownership of the node list.
2125 std::vector<base::ListValue*> node_lists;
2126 scoped_node_lists.release(&node_lists);
2127
2128 for (size_t i = 0; i < node_lists.size() && i < types.size(); ++i) {
2129 const ModelType type = types[i];
2130 base::ListValue* node_list = node_lists[i];
2131
2132 // Add these results to our list.
2133 scoped_ptr<base::DictionaryValue> type_dict(new base::DictionaryValue());
2134 type_dict->SetString("type", ModelTypeToString(type));
2135 type_dict->Set("nodes", node_list);
2136 result_accumulator_->Append(type_dict.release());
2137
2138 // Remember that this part of the request is satisfied.
2139 awaiting_types_.Remove(type);
2140 }
2141
2142 if (awaiting_types_.Empty()) {
2143 callback_.Run(result_accumulator_.Pass());
2144 callback_ = base::Callback<void(scoped_ptr<base::ListValue>)>();
Nicolas Zea 2014/04/04 23:01:27 callback_.Reset()?
rlarocque 2014/04/05 00:07:27 Thanks. I was looking for that method, but I coul
2145 }
2146 }
2147
2148 } // namespace
2149
2150 void ProfileSyncService::GetAllNodes(
2151 base::Callback<void(scoped_ptr<base::ListValue>)> callback) {
2152 // TODO(rlarocque): Should be GetRegisteredDirectoryTypes.
2153 const ModelTypeSet directory_types = GetRegisteredDataTypes();
2154 scoped_refptr<GetAllNodesRequestHelper> helper =
Nicolas Zea 2014/04/04 23:01:27 Do we want to support multiple oustanding requests
rlarocque 2014/04/05 00:07:27 It does support multiple outstanding requests. Th
Nicolas Zea 2014/04/05 00:30:29 I realize it wasn't clear, but I was actually argu
rlarocque 2014/04/05 00:42:05 Fortunately, the UI greys out the refresh button w
2155 new GetAllNodesRequestHelper(directory_types, callback);
2156
2157 if (!backend_initialized_) {
2158 // If there's no backend available to fulfill the request, handle it here.
2159 ScopedVector<base::ListValue> empty_results;
2160 std::vector<ModelType> type_vector;
2161 for (ModelTypeSet::Iterator it = directory_types.First();
2162 it.Good(); it.Inc()) {
2163 type_vector.push_back(it.Get());
2164 empty_results.push_back(new base::ListValue());
2165 }
2166 helper->OnReceivedNodesForTypes(type_vector, empty_results.Pass());
2167 } else {
2168 backend_->GetAllNodesForTypes(
2169 directory_types,
2170 base::Bind(&GetAllNodesRequestHelper::OnReceivedNodesForTypes, helper));
2171 }
2172 }
2173
2082 bool ProfileSyncService::HasObserver( 2174 bool ProfileSyncService::HasObserver(
2083 ProfileSyncServiceBase::Observer* observer) const { 2175 ProfileSyncServiceBase::Observer* observer) const {
2084 return observers_.HasObserver(observer); 2176 return observers_.HasObserver(observer);
2085 } 2177 }
2086 2178
2087 base::WeakPtr<syncer::JsController> ProfileSyncService::GetJsController() { 2179 base::WeakPtr<syncer::JsController> ProfileSyncService::GetJsController() {
2088 return sync_js_controller_.AsWeakPtr(); 2180 return sync_js_controller_.AsWeakPtr();
2089 } 2181 }
2090 2182
2091 void ProfileSyncService::SyncEvent(SyncEventCodes code) { 2183 void ProfileSyncService::SyncEvent(SyncEventCodes code) {
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
2215 status.last_get_token_error = last_get_token_error_; 2307 status.last_get_token_error = last_get_token_error_;
2216 if (request_access_token_retry_timer_.IsRunning()) 2308 if (request_access_token_retry_timer_.IsRunning())
2217 status.next_token_request_time = next_token_request_time_; 2309 status.next_token_request_time = next_token_request_time_;
2218 return status; 2310 return status;
2219 } 2311 }
2220 2312
2221 void ProfileSyncService::OverrideNetworkResourcesForTest( 2313 void ProfileSyncService::OverrideNetworkResourcesForTest(
2222 scoped_ptr<syncer::NetworkResources> network_resources) { 2314 scoped_ptr<syncer::NetworkResources> network_resources) {
2223 network_resources_ = network_resources.Pass(); 2315 network_resources_ = network_resources.Pass();
2224 } 2316 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698