| Index: chrome/browser/ui/sync/profile_signin_confirmation_helper.cc
|
| diff --git a/chrome/browser/ui/sync/profile_signin_confirmation_helper.cc b/chrome/browser/ui/sync/profile_signin_confirmation_helper.cc
|
| index 4e9ce18ea9897fe4f313df7529d6e8ee59985325..9585fb97b11e7a046013018615e1ac8aa9b7a8e5 100644
|
| --- a/chrome/browser/ui/sync/profile_signin_confirmation_helper.cc
|
| +++ b/chrome/browser/ui/sync/profile_signin_confirmation_helper.cc
|
| @@ -21,6 +21,7 @@
|
| #include "chrome/common/extensions/extension_constants.h"
|
| #include "chrome/common/extensions/sync_helper.h"
|
| #include "components/bookmarks/browser/bookmark_model.h"
|
| +#include "content/public/browser/browser_thread.h"
|
| #include "extensions/browser/extension_system.h"
|
| #include "extensions/common/extension.h"
|
| #include "extensions/common/extension_set.h"
|
| @@ -56,6 +57,7 @@ class HasTypedURLsTask : public history::HistoryDBTask {
|
|
|
| private:
|
| virtual ~HasTypedURLsTask() {}
|
| +
|
| bool has_typed_urls_;
|
| base::Callback<void(bool)> cb_;
|
| };
|
| @@ -69,19 +71,16 @@ bool HasBookmarks(Profile* profile) {
|
| }
|
|
|
| // Helper functions for Chrome profile signin.
|
| -class ProfileSigninConfirmationHelper
|
| - : public base::RefCounted<ProfileSigninConfirmationHelper> {
|
| +class ProfileSigninConfirmationHelper {
|
| public:
|
| ProfileSigninConfirmationHelper(
|
| Profile* profile,
|
| const base::Callback<void(bool)>& return_result);
|
| void CheckHasHistory(int max_entries);
|
| void CheckHasTypedURLs();
|
| - void set_pending_requests(int requests);
|
|
|
| private:
|
| - friend class base::RefCounted<ProfileSigninConfirmationHelper>;
|
| -
|
| + // Deletes itself.
|
| ~ProfileSigninConfirmationHelper();
|
|
|
| void OnHistoryQueryResults(size_t max_entries,
|
| @@ -97,9 +96,6 @@ class ProfileSigninConfirmationHelper
|
| // Keep track of how many async requests are pending.
|
| int pending_requests_;
|
|
|
| - // Indicates whether the result has already been returned to caller.
|
| - bool result_returned_;
|
| -
|
| // Callback to pass the result back to the caller.
|
| const base::Callback<void(bool)> return_result_;
|
|
|
| @@ -111,11 +107,11 @@ ProfileSigninConfirmationHelper::ProfileSigninConfirmationHelper(
|
| const base::Callback<void(bool)>& return_result)
|
| : profile_(profile),
|
| pending_requests_(0),
|
| - result_returned_(false),
|
| return_result_(return_result) {
|
| }
|
|
|
| ProfileSigninConfirmationHelper::~ProfileSigninConfirmationHelper() {
|
| + DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
|
| }
|
|
|
| void ProfileSigninConfirmationHelper::OnHistoryQueryResults(
|
| @@ -134,6 +130,7 @@ void ProfileSigninConfirmationHelper::OnHistoryQueryResults(
|
| void ProfileSigninConfirmationHelper::CheckHasHistory(int max_entries) {
|
| HistoryService* service =
|
| HistoryServiceFactory::GetForProfileWithoutCreating(profile_);
|
| + pending_requests_++;
|
| if (!service) {
|
| ReturnResult(false);
|
| return;
|
| @@ -144,7 +141,7 @@ void ProfileSigninConfirmationHelper::CheckHasHistory(int max_entries) {
|
| base::string16(),
|
| opts,
|
| base::Bind(&ProfileSigninConfirmationHelper::OnHistoryQueryResults,
|
| - this,
|
| + base::Unretained(this),
|
| max_entries),
|
| &task_tracker_);
|
| }
|
| @@ -152,27 +149,28 @@ void ProfileSigninConfirmationHelper::CheckHasHistory(int max_entries) {
|
| void ProfileSigninConfirmationHelper::CheckHasTypedURLs() {
|
| HistoryService* service =
|
| HistoryServiceFactory::GetForProfileWithoutCreating(profile_);
|
| + pending_requests_++;
|
| if (!service) {
|
| ReturnResult(false);
|
| return;
|
| }
|
| service->ScheduleDBTask(
|
| new HasTypedURLsTask(
|
| - base::Bind(&ProfileSigninConfirmationHelper::ReturnResult, this)),
|
| + base::Bind(&ProfileSigninConfirmationHelper::ReturnResult,
|
| + base::Unretained(this))),
|
| &task_tracker_);
|
| }
|
|
|
| -void ProfileSigninConfirmationHelper::set_pending_requests(int requests) {
|
| - pending_requests_ = requests;
|
| -}
|
| -
|
| void ProfileSigninConfirmationHelper::ReturnResult(bool result) {
|
| + DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
|
| // Pass |true| into the callback as soon as one of the tasks passes a
|
| // result of |true|, otherwise pass the last returned result.
|
| - if (!result_returned_ && (--pending_requests_ == 0 || result)) {
|
| - result_returned_ = true;
|
| - task_tracker_.TryCancelAll();
|
| + if (--pending_requests_ == 0 || result) {
|
| return_result_.Run(result);
|
| +
|
| + // This leaks at shutdown if the HistoryService is destroyed, but
|
| + // the process is going to die anyway.
|
| + delete this;
|
| }
|
| }
|
|
|
| @@ -220,6 +218,8 @@ bool HasSyncedExtensions(Profile* profile) {
|
| void CheckShouldPromptForNewProfile(
|
| Profile* profile,
|
| const base::Callback<void(bool)>& return_result) {
|
| + DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
|
| +
|
| if (HasBeenShutdown(profile) ||
|
| HasBookmarks(profile) ||
|
| HasSyncedExtensions(profile)) {
|
| @@ -227,10 +227,8 @@ void CheckShouldPromptForNewProfile(
|
| return;
|
| }
|
| // Fire asynchronous queries for profile data.
|
| - scoped_refptr<ProfileSigninConfirmationHelper> helper =
|
| + ProfileSigninConfirmationHelper* helper =
|
| new ProfileSigninConfirmationHelper(profile, return_result);
|
| - const int requests = 2;
|
| - helper->set_pending_requests(requests);
|
| helper->CheckHasHistory(kHistoryEntriesBeforeNewProfilePrompt);
|
| helper->CheckHasTypedURLs();
|
| }
|
|
|