Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / components / password_manager / core / browser / password_store_consumer.h
1 // Copyright 2014 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_PASSWORD_MANAGER_CORE_BROWSER_PASSWORD_STORE_CONSUMER_H_
6 #define COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_PASSWORD_STORE_CONSUMER_H_
7
8 #include <vector>
9
10 #include "base/task/cancelable_task_tracker.h"
11
12 namespace autofill {
13 struct PasswordForm;
14 }
15
16 // Reads from the PasswordStore are done asynchronously on a separate
17 // thread. PasswordStoreConsumer provides the virtual callback method, which is
18 // guaranteed to be executed on this (the UI) thread. It also provides the
19 // base::CancelableTaskTracker member, which cancels any outstanding
20 // tasks upon destruction.
21 class PasswordStoreConsumer {
22  public:
23   PasswordStoreConsumer();
24
25   // Called when the request is finished. If there are no results, it is called
26   // with an empty vector.
27   // Note: The implementation owns all PasswordForms in the vector.
28   virtual void OnGetPasswordStoreResults(
29       const std::vector<autofill::PasswordForm*>& results) = 0;
30
31   // The base::CancelableTaskTracker can be used for cancelling the
32   // tasks associated with the consumer.
33   base::CancelableTaskTracker* cancelable_task_tracker() {
34     return &cancelable_task_tracker_;
35   }
36
37   base::WeakPtr<PasswordStoreConsumer> GetWeakPtr() {
38     return weak_ptr_factory_.GetWeakPtr();
39   }
40
41  protected:
42   virtual ~PasswordStoreConsumer();
43
44  private:
45   base::CancelableTaskTracker cancelable_task_tracker_;
46   base::WeakPtrFactory<PasswordStoreConsumer> weak_ptr_factory_;
47 };
48
49 #endif  // COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_PASSWORD_STORE_CONSUMER_H_