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

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: Fix lifetime of base::CancelableTaskTracker for HistoryModelWorker 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 151
153 void ProfileSigninConfirmationHelper::CheckHasTypedURLs() { 152 void ProfileSigninConfirmationHelper::CheckHasTypedURLs() {
154 HistoryService* service = 153 HistoryService* service =
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(&ProfileSigninConfirmationHelper::ReturnResult, this)),
163 &ProfileSigninConfirmationHelper::ReturnResult, 162 &task_tracker_);
164 this)),
165 &request_consumer_);
166 } 163 }
167 164
168 void ProfileSigninConfirmationHelper::set_pending_requests(int requests) { 165 void ProfileSigninConfirmationHelper::set_pending_requests(int requests) {
169 pending_requests_ = requests; 166 pending_requests_ = requests;
170 } 167 }
171 168
172 void ProfileSigninConfirmationHelper::ReturnResult(bool result) { 169 void ProfileSigninConfirmationHelper::ReturnResult(bool result) {
173 // Pass |true| into the callback as soon as one of the tasks passes a 170 // Pass |true| into the callback as soon as one of the tasks passes a
174 // result of |true|, otherwise pass the last returned result. 171 // result of |true|, otherwise pass the last returned result.
175 if (!result_returned_ && (--pending_requests_ == 0 || result)) { 172 if (!result_returned_ && (--pending_requests_ == 0 || result)) {
176 result_returned_ = true; 173 result_returned_ = true;
177 request_consumer_.CancelAllRequests(); 174 task_tracker_.TryCancelAll();
178 return_result_.Run(result); 175 return_result_.Run(result);
179 } 176 }
180 } 177 }
181 178
182 } // namespace 179 } // namespace
183 180
184 namespace ui { 181 namespace ui {
185 182
186 SkColor GetSigninConfirmationPromptBarColor(SkAlpha alpha) { 183 SkColor GetSigninConfirmationPromptBarColor(SkAlpha alpha) {
187 static const SkColor kBackgroundColor = 184 static const SkColor kBackgroundColor =
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 // Fire asynchronous queries for profile data. 229 // Fire asynchronous queries for profile data.
233 scoped_refptr<ProfileSigninConfirmationHelper> helper = 230 scoped_refptr<ProfileSigninConfirmationHelper> helper =
234 new ProfileSigninConfirmationHelper(profile, return_result); 231 new ProfileSigninConfirmationHelper(profile, return_result);
235 const int requests = 2; 232 const int requests = 2;
236 helper->set_pending_requests(requests); 233 helper->set_pending_requests(requests);
237 helper->CheckHasHistory(kHistoryEntriesBeforeNewProfilePrompt); 234 helper->CheckHasHistory(kHistoryEntriesBeforeNewProfilePrompt);
238 helper->CheckHasTypedURLs(); 235 helper->CheckHasTypedURLs();
239 } 236 }
240 237
241 } // namespace ui 238 } // namespace ui
OLDNEW
« no previous file with comments | « chrome/browser/ui/search/instant_extended_interactive_uitest.cc ('k') | chrome/test/base/testing_profile.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698