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 "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 Loading... |
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 Loading... |
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 const base::Callback<void(scoped_ptr<base::ListValue>)>& callback); |
| 2089 |
| 2090 void OnReceivedNodesForTypes( |
| 2091 const std::vector<syncer::ModelType>& types, |
| 2092 ScopedVector<base::ListValue> scoped_node_lists); |
| 2093 |
| 2094 private: |
| 2095 friend class base::RefCountedThreadSafe<GetAllNodesRequestHelper>; |
| 2096 virtual ~GetAllNodesRequestHelper(); |
| 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 const base::Callback<void(scoped_ptr<base::ListValue>)>& callback) |
| 2107 : result_accumulator_(new base::ListValue()), |
| 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 // Called when the set of nodes for a type or set of types has been returned. |
| 2120 // |
| 2121 // The nodes for several types can be returned at the same time by specifying |
| 2122 // their types in the |types| array, and putting their results at the |
| 2123 // correspnding indices in the |scoped_node_lists|. |
| 2124 void GetAllNodesRequestHelper::OnReceivedNodesForTypes( |
| 2125 const std::vector<syncer::ModelType>& types, |
| 2126 ScopedVector<base::ListValue> scoped_node_lists) { |
| 2127 DCHECK_EQ(types.size(), scoped_node_lists.size()); |
| 2128 |
| 2129 // Take unsafe ownership of the node list. |
| 2130 std::vector<base::ListValue*> node_lists; |
| 2131 scoped_node_lists.release(&node_lists); |
| 2132 |
| 2133 for (size_t i = 0; i < node_lists.size() && i < types.size(); ++i) { |
| 2134 const ModelType type = types[i]; |
| 2135 base::ListValue* node_list = node_lists[i]; |
| 2136 |
| 2137 // Add these results to our list. |
| 2138 scoped_ptr<base::DictionaryValue> type_dict(new base::DictionaryValue()); |
| 2139 type_dict->SetString("type", ModelTypeToString(type)); |
| 2140 type_dict->Set("nodes", node_list); |
| 2141 result_accumulator_->Append(type_dict.release()); |
| 2142 |
| 2143 // Remember that this part of the request is satisfied. |
| 2144 awaiting_types_.Remove(type); |
| 2145 } |
| 2146 |
| 2147 if (awaiting_types_.Empty()) { |
| 2148 callback_.Run(result_accumulator_.Pass()); |
| 2149 callback_.Reset(); |
| 2150 } |
| 2151 } |
| 2152 |
| 2153 } // namespace |
| 2154 |
| 2155 void ProfileSyncService::GetAllNodes( |
| 2156 const base::Callback<void(scoped_ptr<base::ListValue>)>& callback) { |
| 2157 // TODO(rlarocque): Should be GetRegisteredDirectoryTypes. |
| 2158 const ModelTypeSet directory_types = GetRegisteredDataTypes(); |
| 2159 scoped_refptr<GetAllNodesRequestHelper> helper = |
| 2160 new GetAllNodesRequestHelper(directory_types, callback); |
| 2161 |
| 2162 if (!backend_initialized_) { |
| 2163 // If there's no backend available to fulfill the request, handle it here. |
| 2164 ScopedVector<base::ListValue> empty_results; |
| 2165 std::vector<ModelType> type_vector; |
| 2166 for (ModelTypeSet::Iterator it = directory_types.First(); |
| 2167 it.Good(); it.Inc()) { |
| 2168 type_vector.push_back(it.Get()); |
| 2169 empty_results.push_back(new base::ListValue()); |
| 2170 } |
| 2171 helper->OnReceivedNodesForTypes(type_vector, empty_results.Pass()); |
| 2172 } else { |
| 2173 backend_->GetAllNodesForTypes( |
| 2174 directory_types, |
| 2175 base::Bind(&GetAllNodesRequestHelper::OnReceivedNodesForTypes, helper)); |
| 2176 } |
| 2177 } |
| 2178 |
2082 bool ProfileSyncService::HasObserver( | 2179 bool ProfileSyncService::HasObserver( |
2083 ProfileSyncServiceBase::Observer* observer) const { | 2180 ProfileSyncServiceBase::Observer* observer) const { |
2084 return observers_.HasObserver(observer); | 2181 return observers_.HasObserver(observer); |
2085 } | 2182 } |
2086 | 2183 |
2087 base::WeakPtr<syncer::JsController> ProfileSyncService::GetJsController() { | 2184 base::WeakPtr<syncer::JsController> ProfileSyncService::GetJsController() { |
2088 return sync_js_controller_.AsWeakPtr(); | 2185 return sync_js_controller_.AsWeakPtr(); |
2089 } | 2186 } |
2090 | 2187 |
2091 void ProfileSyncService::SyncEvent(SyncEventCodes code) { | 2188 void ProfileSyncService::SyncEvent(SyncEventCodes code) { |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2215 status.last_get_token_error = last_get_token_error_; | 2312 status.last_get_token_error = last_get_token_error_; |
2216 if (request_access_token_retry_timer_.IsRunning()) | 2313 if (request_access_token_retry_timer_.IsRunning()) |
2217 status.next_token_request_time = next_token_request_time_; | 2314 status.next_token_request_time = next_token_request_time_; |
2218 return status; | 2315 return status; |
2219 } | 2316 } |
2220 | 2317 |
2221 void ProfileSyncService::OverrideNetworkResourcesForTest( | 2318 void ProfileSyncService::OverrideNetworkResourcesForTest( |
2222 scoped_ptr<syncer::NetworkResources> network_resources) { | 2319 scoped_ptr<syncer::NetworkResources> network_resources) { |
2223 network_resources_ = network_resources.Pass(); | 2320 network_resources_ = network_resources.Pass(); |
2224 } | 2321 } |
OLD | NEW |