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