summaryrefslogtreecommitdiff
path: root/chromium/components/autofill/core/browser/autofill_driver_factory.cc
blob: 58ec815c2ba37e7de637d7e162adbe4245c348e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/autofill/core/browser/autofill_driver_factory.h"

#include "base/callback.h"
#include "components/autofill/core/browser/autofill_client.h"
#include "components/autofill/core/browser/autofill_driver.h"

namespace autofill {

AutofillDriverFactory::AutofillDriverFactory(AutofillClient* client)
    : client_(client) {}

AutofillDriverFactory::~AutofillDriverFactory() {}

AutofillDriver* AutofillDriverFactory::DriverForKey(void* key) {
  auto mapping = driver_map_.find(key);
  return mapping == driver_map_.end() ? nullptr : mapping->second.get();
}

void AutofillDriverFactory::NavigationFinished() {
  client_->HideAutofillPopup();
}

void AutofillDriverFactory::TabHidden() {
  client_->HideAutofillPopup();
}

void AutofillDriverFactory::AddForKey(
    void* key,
    base::Callback<std::unique_ptr<AutofillDriver>()> factory_method) {
  auto insertion_result = driver_map_.insert(std::make_pair(key, nullptr));
  // This can be called twice for the key representing the main frame.
  if (insertion_result.second) {
    insertion_result.first->second = factory_method.Run();
  }
}

void AutofillDriverFactory::DeleteForKey(void* key) {
  driver_map_.erase(key);
}

}  // namespace autofill