Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/string16.h" | 10 #include "base/string16.h" |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 75 } | 75 } |
| 76 return false; | 76 return false; |
| 77 } | 77 } |
| 78 | 78 |
| 79 // Helper functions for Chrome profile signin. | 79 // Helper functions for Chrome profile signin. |
| 80 class ProfileSigninConfirmationHelper | 80 class ProfileSigninConfirmationHelper |
| 81 : public base::RefCounted<ProfileSigninConfirmationHelper> { | 81 : public base::RefCounted<ProfileSigninConfirmationHelper> { |
| 82 public: | 82 public: |
| 83 ProfileSigninConfirmationHelper( | 83 ProfileSigninConfirmationHelper( |
| 84 Profile* profile, | 84 Profile* profile, |
| 85 const base::Callback<void(bool)>& return_result); | 85 const base::Callback |
| 86 <void(ui::DisplayCreateProfilePrompt)>& return_result); | |
| 86 void CheckHasHistory(int max_entries); | 87 void CheckHasHistory(int max_entries); |
| 87 void CheckHasTypedURLs(); | 88 void CheckHasTypedURLs(); |
| 88 void set_pending_requests(int requests); | 89 void set_pending_requests(int requests); |
| 89 | 90 |
| 90 private: | 91 private: |
| 91 friend class base::RefCounted<ProfileSigninConfirmationHelper>; | 92 friend class base::RefCounted<ProfileSigninConfirmationHelper>; |
| 92 | 93 |
| 93 ~ProfileSigninConfirmationHelper(); | 94 ~ProfileSigninConfirmationHelper(); |
| 94 | 95 |
| 95 void OnHistoryQueryResults(size_t max_entries, | 96 void OnHistoryQueryResults(size_t max_entries, |
| 96 CancelableRequestProvider::Handle handle, | 97 CancelableRequestProvider::Handle handle, |
| 97 history::QueryResults* results); | 98 history::QueryResults* results); |
| 98 void ReturnResult(bool result); | 99 void ReturnResult(bool result); |
| 99 | 100 |
| 100 // Weak pointer to the profile being signed-in. | 101 // Weak pointer to the profile being signed-in. |
| 101 Profile* profile_; | 102 Profile* profile_; |
| 102 | 103 |
| 103 // Used for async tasks. | 104 // Used for async tasks. |
| 104 CancelableRequestConsumer request_consumer_; | 105 CancelableRequestConsumer request_consumer_; |
| 105 | 106 |
| 106 // Keep track of how many async requests are pending. | 107 // Keep track of how many async requests are pending. |
| 107 int pending_requests_; | 108 int pending_requests_; |
| 108 | 109 |
| 109 // Indicates whether the result has already been returned to caller. | 110 // Indicates whether the result has already been returned to caller. |
| 110 bool result_returned_; | 111 bool result_returned_; |
| 111 | 112 |
| 112 // Callback to pass the result back to the caller. | 113 // Callback to pass the result back to the caller. |
| 113 const base::Callback<void(bool)> return_result_; | 114 const base::Callback<void(ui::DisplayCreateProfilePrompt)> return_result_; |
| 114 | 115 |
| 115 DISALLOW_COPY_AND_ASSIGN(ProfileSigninConfirmationHelper); | 116 DISALLOW_COPY_AND_ASSIGN(ProfileSigninConfirmationHelper); |
| 116 }; | 117 }; |
| 117 | 118 |
| 118 ProfileSigninConfirmationHelper::ProfileSigninConfirmationHelper( | 119 ProfileSigninConfirmationHelper::ProfileSigninConfirmationHelper( |
| 119 Profile* profile, | 120 Profile* profile, |
| 120 const base::Callback<void(bool)>& return_result) | 121 const base::Callback<void(ui::DisplayCreateProfilePrompt)>& return_result) |
| 121 : profile_(profile), | 122 : profile_(profile), |
| 122 pending_requests_(0), | 123 pending_requests_(0), |
| 123 result_returned_(false), | 124 result_returned_(false), |
| 124 return_result_(return_result) { | 125 return_result_(return_result) { |
| 125 } | 126 } |
| 126 | 127 |
| 127 ProfileSigninConfirmationHelper::~ProfileSigninConfirmationHelper() { | 128 ProfileSigninConfirmationHelper::~ProfileSigninConfirmationHelper() { |
| 128 } | 129 } |
| 129 | 130 |
| 130 void ProfileSigninConfirmationHelper::OnHistoryQueryResults( | 131 void ProfileSigninConfirmationHelper::OnHistoryQueryResults( |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 170 void ProfileSigninConfirmationHelper::set_pending_requests(int requests) { | 171 void ProfileSigninConfirmationHelper::set_pending_requests(int requests) { |
| 171 pending_requests_ = requests; | 172 pending_requests_ = requests; |
| 172 } | 173 } |
| 173 | 174 |
| 174 void ProfileSigninConfirmationHelper::ReturnResult(bool result) { | 175 void ProfileSigninConfirmationHelper::ReturnResult(bool result) { |
| 175 // Pass |true| into the callback as soon as one of the tasks passes a | 176 // Pass |true| into the callback as soon as one of the tasks passes a |
| 176 // result of |true|, otherwise pass the last returned result. | 177 // result of |true|, otherwise pass the last returned result. |
| 177 if (!result_returned_ && (--pending_requests_ == 0 || result)) { | 178 if (!result_returned_ && (--pending_requests_ == 0 || result)) { |
| 178 result_returned_ = true; | 179 result_returned_ = true; |
| 179 request_consumer_.CancelAllRequests(); | 180 request_consumer_.CancelAllRequests(); |
| 180 return_result_.Run(result); | 181 return_result_.Run(result ? ui::PROMPT_TO_CREATE_PROFILE |
| 182 : ui::DO_NOT_PROMPT_TO_CREATE_PROFILE); | |
|
Peter Kasting
2013/05/15 00:11:03
Nit: Illegal wrapping style; operators go on the e
dconnelly
2013/05/17 13:01:55
Removed now that I brought back the bool.
| |
| 181 } | 183 } |
| 182 } | 184 } |
| 183 | 185 |
| 184 } // namespace | 186 } // namespace |
| 185 | 187 |
| 186 namespace ui { | 188 namespace ui { |
| 187 | 189 |
| 188 bool HasBeenShutdown(Profile* profile) { | 190 bool HasBeenShutdown(Profile* profile) { |
| 189 return !profile->IsNewProfile(); | 191 return !profile->IsNewProfile(); |
| 190 } | 192 } |
| 191 | 193 |
| 192 void CheckShouldPromptForNewProfile( | 194 void CheckShouldPromptForNewProfile( |
| 193 Profile* profile, | 195 Profile* profile, |
| 194 const base::Callback<void(bool)>& return_result) { | 196 const base::Callback<void(DisplayCreateProfilePrompt)>& return_result) { |
| 195 if (HasBeenShutdown(profile) || | 197 if (HasBeenShutdown(profile) || |
| 196 HasBookmarks(profile) || | 198 HasBookmarks(profile) || |
| 197 HasSyncedExtensions(profile)) { | 199 HasSyncedExtensions(profile)) { |
| 198 return_result.Run(true); | 200 return_result.Run(PROMPT_TO_CREATE_PROFILE); |
| 199 return; | 201 return; |
| 200 } | 202 } |
| 201 // Fire asynchronous queries for profile data. | 203 // Fire asynchronous queries for profile data. |
| 202 scoped_refptr<ProfileSigninConfirmationHelper> helper = | 204 scoped_refptr<ProfileSigninConfirmationHelper> helper = |
| 203 new ProfileSigninConfirmationHelper(profile, return_result); | 205 new ProfileSigninConfirmationHelper(profile, return_result); |
| 204 const int requests = 2; | 206 const int requests = 2; |
| 205 helper->set_pending_requests(requests); | 207 helper->set_pending_requests(requests); |
| 206 helper->CheckHasHistory(kHistoryEntriesBeforeNewProfilePrompt); | 208 helper->CheckHasHistory(kHistoryEntriesBeforeNewProfilePrompt); |
| 207 helper->CheckHasTypedURLs(); | 209 helper->CheckHasTypedURLs(); |
| 208 } | 210 } |
| 209 | 211 |
| 210 } // namespace ui | 212 } // namespace ui |
| OLD | NEW |