OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 // Note: Read the class comment of AffiliationService for the definition of the | 5 // Note: Read the class comment of AffiliationService for the definition of the |
6 // terms used below. | 6 // terms used below. |
7 // | 7 // |
8 // On-demand fetching strategy | 8 // On-demand fetching strategy |
9 // | 9 // |
10 // A GetAffiliations() request concerning facet X will be served from the cache | 10 // A GetAffiliations() request concerning facet X will be served from the cache |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 } | 103 } |
104 | 104 |
105 FacetManager::~FacetManager() { | 105 FacetManager::~FacetManager() { |
106 // The manager will be destroyed while there are pending requests only if the | 106 // The manager will be destroyed while there are pending requests only if the |
107 // entire backend is going away. Fail pending requests in this case. | 107 // entire backend is going away. Fail pending requests in this case. |
108 for (const auto& request_info : pending_requests_) | 108 for (const auto& request_info : pending_requests_) |
109 ServeRequestWithFailure(request_info); | 109 ServeRequestWithFailure(request_info); |
110 } | 110 } |
111 | 111 |
112 void FacetManager::GetAffiliations( | 112 void FacetManager::GetAffiliations( |
113 bool cached_only, | 113 StrategyOnCacheMiss cache_miss_strategy, |
114 const AffiliationService::ResultCallback& callback, | 114 const AffiliationService::ResultCallback& callback, |
115 const scoped_refptr<base::TaskRunner>& callback_task_runner) { | 115 const scoped_refptr<base::TaskRunner>& callback_task_runner) { |
116 RequestInfo request_info; | 116 RequestInfo request_info; |
117 request_info.callback = callback; | 117 request_info.callback = callback; |
118 request_info.callback_task_runner = callback_task_runner; | 118 request_info.callback_task_runner = callback_task_runner; |
119 if (IsCachedDataFresh()) { | 119 if (IsCachedDataFresh()) { |
120 AffiliatedFacetsWithUpdateTime affiliation; | 120 AffiliatedFacetsWithUpdateTime affiliation; |
121 if (!backend_->ReadAffiliationsFromDatabase(facet_uri_, &affiliation)) { | 121 if (!backend_->ReadAffiliationsFromDatabase(facet_uri_, &affiliation)) { |
122 // TODO(engedy): Implement this. crbug.com/437865. | 122 // TODO(engedy): Implement this. crbug.com/437865. |
123 NOTIMPLEMENTED(); | 123 NOTIMPLEMENTED(); |
124 } | 124 } |
125 DCHECK_EQ(affiliation.last_update_time, last_update_time_) << facet_uri_; | 125 DCHECK_EQ(affiliation.last_update_time, last_update_time_) << facet_uri_; |
126 ServeRequestWithSuccess(request_info, affiliation.facets); | 126 ServeRequestWithSuccess(request_info, affiliation.facets); |
127 } else if (cached_only) { | 127 } else if (cache_miss_strategy == StrategyOnCacheMiss::FETCH_OVER_NETWORK) { |
128 ServeRequestWithFailure(request_info); | |
129 } else { | |
130 pending_requests_.push_back(request_info); | 128 pending_requests_.push_back(request_info); |
131 backend_->SignalNeedNetworkRequest(); | 129 backend_->SignalNeedNetworkRequest(); |
| 130 } else { |
| 131 ServeRequestWithFailure(request_info); |
132 } | 132 } |
133 } | 133 } |
134 | 134 |
135 void FacetManager::Prefetch(const base::Time& keep_fresh_until) { | 135 void FacetManager::Prefetch(const base::Time& keep_fresh_until) { |
136 keep_fresh_until_thresholds_.insert(keep_fresh_until); | 136 keep_fresh_until_thresholds_.insert(keep_fresh_until); |
137 | 137 |
138 // If an initial fetch if needed, trigger that (the refetch will be scheduled | 138 // If an initial fetch if needed, trigger that (the refetch will be scheduled |
139 // once the initial fetch completes). Otherwise schedule the next refetch. | 139 // once the initial fetch completes). Otherwise schedule the next refetch. |
140 base::Time next_required_fetch(GetNextRequiredFetchTimeDueToPrefetch()); | 140 base::Time next_required_fetch(GetNextRequiredFetchTimeDueToPrefetch()); |
141 if (next_required_fetch <= clock_->Now()) | 141 if (next_required_fetch <= clock_->Now()) |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 FROM_HERE, base::Bind(request_info.callback, affiliation, true)); | 235 FROM_HERE, base::Bind(request_info.callback, affiliation, true)); |
236 } | 236 } |
237 | 237 |
238 // static | 238 // static |
239 void FacetManager::ServeRequestWithFailure(const RequestInfo& request_info) { | 239 void FacetManager::ServeRequestWithFailure(const RequestInfo& request_info) { |
240 request_info.callback_task_runner->PostTask( | 240 request_info.callback_task_runner->PostTask( |
241 FROM_HERE, base::Bind(request_info.callback, AffiliatedFacets(), false)); | 241 FROM_HERE, base::Bind(request_info.callback, AffiliatedFacets(), false)); |
242 } | 242 } |
243 | 243 |
244 } // namespace password_manager | 244 } // namespace password_manager |
OLD | NEW |