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

Side by Side Diff: chrome/browser/ui/sync/profile_signin_confirmation_helper.cc

Issue 352913002: Port HistoryService::ScheduleDBTask to CancelableTaskTracker (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/ui/sync/profile_signin_confirmation_helper.h" 5 #include "chrome/browser/ui/sync/profile_signin_confirmation_helper.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
9 #include "base/prefs/pref_service.h" 9 #include "base/prefs/pref_service.h"
10 #include "base/strings/string16.h" 10 #include "base/strings/string16.h"
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 ~ProfileSigninConfirmationHelper(); 85 ~ProfileSigninConfirmationHelper();
86 86
87 void OnHistoryQueryResults(size_t max_entries, 87 void OnHistoryQueryResults(size_t max_entries,
88 history::QueryResults* results); 88 history::QueryResults* results);
89 void ReturnResult(bool result); 89 void ReturnResult(bool result);
90 90
91 // Weak pointer to the profile being signed-in. 91 // Weak pointer to the profile being signed-in.
92 Profile* profile_; 92 Profile* profile_;
93 93
94 // Used for async tasks. 94 // Used for async tasks.
95 CancelableRequestConsumer request_consumer_;
96 base::CancelableTaskTracker task_tracker_; 95 base::CancelableTaskTracker task_tracker_;
97 96
98 // Keep track of how many async requests are pending. 97 // Keep track of how many async requests are pending.
99 int pending_requests_; 98 int pending_requests_;
100 99
101 // Indicates whether the result has already been returned to caller. 100 // Indicates whether the result has already been returned to caller.
102 bool result_returned_; 101 bool result_returned_;
103 102
104 // Callback to pass the result back to the caller. 103 // Callback to pass the result back to the caller.
105 const base::Callback<void(bool)> return_result_; 104 const base::Callback<void(bool)> return_result_;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 HistoryServiceFactory::GetForProfileWithoutCreating(profile_); 154 HistoryServiceFactory::GetForProfileWithoutCreating(profile_);
156 if (!service) { 155 if (!service) {
157 ReturnResult(false); 156 ReturnResult(false);
158 return; 157 return;
159 } 158 }
160 service->ScheduleDBTask( 159 service->ScheduleDBTask(
161 new HasTypedURLsTask( 160 new HasTypedURLsTask(
162 base::Bind( 161 base::Bind(
163 &ProfileSigninConfirmationHelper::ReturnResult, 162 &ProfileSigninConfirmationHelper::ReturnResult,
164 this)), 163 this)),
165 &request_consumer_); 164 &task_tracker_);
166 } 165 }
167 166
168 void ProfileSigninConfirmationHelper::set_pending_requests(int requests) { 167 void ProfileSigninConfirmationHelper::set_pending_requests(int requests) {
169 pending_requests_ = requests; 168 pending_requests_ = requests;
170 } 169 }
171 170
172 void ProfileSigninConfirmationHelper::ReturnResult(bool result) { 171 void ProfileSigninConfirmationHelper::ReturnResult(bool result) {
173 // Pass |true| into the callback as soon as one of the tasks passes a 172 // Pass |true| into the callback as soon as one of the tasks passes a
174 // result of |true|, otherwise pass the last returned result. 173 // result of |true|, otherwise pass the last returned result.
175 if (!result_returned_ && (--pending_requests_ == 0 || result)) { 174 if (!result_returned_ && (--pending_requests_ == 0 || result)) {
176 result_returned_ = true; 175 result_returned_ = true;
177 request_consumer_.CancelAllRequests(); 176 task_tracker_.TryCancelAll();
178 return_result_.Run(result); 177 return_result_.Run(result);
179 } 178 }
180 } 179 }
181 180
182 } // namespace 181 } // namespace
183 182
184 namespace ui { 183 namespace ui {
185 184
186 SkColor GetSigninConfirmationPromptBarColor(SkAlpha alpha) { 185 SkColor GetSigninConfirmationPromptBarColor(SkAlpha alpha) {
187 static const SkColor kBackgroundColor = 186 static const SkColor kBackgroundColor =
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 // Fire asynchronous queries for profile data. 231 // Fire asynchronous queries for profile data.
233 scoped_refptr<ProfileSigninConfirmationHelper> helper = 232 scoped_refptr<ProfileSigninConfirmationHelper> helper =
234 new ProfileSigninConfirmationHelper(profile, return_result); 233 new ProfileSigninConfirmationHelper(profile, return_result);
235 const int requests = 2; 234 const int requests = 2;
236 helper->set_pending_requests(requests); 235 helper->set_pending_requests(requests);
237 helper->CheckHasHistory(kHistoryEntriesBeforeNewProfilePrompt); 236 helper->CheckHasHistory(kHistoryEntriesBeforeNewProfilePrompt);
238 helper->CheckHasTypedURLs(); 237 helper->CheckHasTypedURLs();
239 } 238 }
240 239
241 } // namespace ui 240 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698