| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef COMPONENTS_BROWSER_SYNC_BROWSER_SIGNIN_CONFIRMATION_HELPER_ | |
| 6 #define COMPONENTS_BROWSER_SYNC_BROWSER_SIGNIN_CONFIRMATION_HELPER_ | |
| 7 | |
| 8 #include <stddef.h> | |
| 9 | |
| 10 #include "base/macros.h" | |
| 11 #include "base/memory/ref_counted.h" | |
| 12 #include "base/task/cancelable_task_tracker.h" | |
| 13 | |
| 14 namespace history { | |
| 15 class HistoryService; | |
| 16 class QueryResults; | |
| 17 } | |
| 18 | |
| 19 namespace sync_driver { | |
| 20 | |
| 21 // Helper class for sync signin to check some asynchronous conditions. Call | |
| 22 // either CheckHasHistory or CheckHasTypedUrls or both, and |return_result| | |
| 23 // will be called with true if either returns true, otherwise false. | |
| 24 class SigninConfirmationHelper { | |
| 25 public: | |
| 26 SigninConfirmationHelper(history::HistoryService* history_service, | |
| 27 const base::Callback<void(bool)>& return_result); | |
| 28 | |
| 29 // This helper checks if there are history entries in the history service. | |
| 30 void CheckHasHistory(int max_entries); | |
| 31 | |
| 32 // This helper checks if there are typed URLs in the history service. | |
| 33 void CheckHasTypedURLs(); | |
| 34 | |
| 35 private: | |
| 36 // Deletes itself. | |
| 37 ~SigninConfirmationHelper(); | |
| 38 | |
| 39 // Callback helper function for CheckHasHistory. | |
| 40 void OnHistoryQueryResults(size_t max_entries, | |
| 41 history::QueryResults* results); | |
| 42 | |
| 43 // Posts the given result to the origin thread. | |
| 44 void PostResult(bool result); | |
| 45 | |
| 46 // Calls |return_result_| if |result| == true or if it's the result of the | |
| 47 // last pending check. | |
| 48 void ReturnResult(bool result); | |
| 49 | |
| 50 // The task runner for the thread this object was constructed on. | |
| 51 const scoped_refptr<base::SingleThreadTaskRunner> origin_thread_; | |
| 52 | |
| 53 // Pointer to the history service. | |
| 54 history::HistoryService* history_service_; | |
| 55 | |
| 56 // Used for async tasks. | |
| 57 base::CancelableTaskTracker task_tracker_; | |
| 58 | |
| 59 // Keep track of how many async requests are pending. | |
| 60 int pending_requests_; | |
| 61 | |
| 62 // Callback to pass the result back to the caller. | |
| 63 const base::Callback<void(bool)> return_result_; | |
| 64 | |
| 65 DISALLOW_COPY_AND_ASSIGN(SigninConfirmationHelper); | |
| 66 }; | |
| 67 | |
| 68 } // namespace sync_driver | |
| 69 | |
| 70 #endif // COMPONENTS_BROWSER_SYNC_BROWSER_SIGNIN_CONFIRMATION_HELPER_ | |
| OLD | NEW |