1 // Copyright (c) 2012 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.
5 #ifndef CHROME_BROWSER_AUTOCOMPLETE_CONTACT_PROVIDER_CHROMEOS_H_
6 #define CHROME_BROWSER_AUTOCOMPLETE_CONTACT_PROVIDER_CHROMEOS_H_
11 #include "base/basictypes.h"
12 #include "base/compiler_specific.h"
13 #include "base/memory/weak_ptr.h"
14 #include "chrome/browser/autocomplete/autocomplete_match.h"
15 #include "chrome/browser/autocomplete/autocomplete_provider.h"
16 #include "chrome/browser/chromeos/contacts/contact_manager_observer.h"
18 class AutocompleteInput
;
21 class ContactManagerInterface
;
24 // AutocompleteProvider implementation that searches through the contacts
25 // provided by contacts::ContactManager.
26 class ContactProvider
: public AutocompleteProvider
,
27 public contacts::ContactManagerObserver
{
29 // Key within AutocompleteMatch::additional_info where the corresponding
30 // contact's ID is stored.
31 static const char kMatchContactIdKey
[];
34 AutocompleteProviderListener
* listener
,
36 base::WeakPtr
<contacts::ContactManagerInterface
> contact_manager
);
38 // AutocompleteProvider overrides:
39 virtual void Start(const AutocompleteInput
& input
,
40 bool minimal_changes
) OVERRIDE
;
42 // contacts::ContactManagerObserver overrides:
43 virtual void OnContactsUpdated(Profile
* profile
) OVERRIDE
;
47 typedef std::vector
<ContactData
> ContactDataVector
;
49 virtual ~ContactProvider();
51 // Returns true if |a|'s affinity is greater than |b|'s affinity.
52 static bool CompareAffinity(const ContactData
& a
, const ContactData
& b
);
54 // Updates |contacts_| to match the contacts currently reported by
56 void RefreshContacts();
58 // Adds an AutocompleteMatch object for |contact| to |matches_| if |contact|
59 // is matched by |input|. |input_words| is |input.text()| split on word
61 void AddContactIfMatched(const AutocompleteInput
& input
,
62 const std::vector
<base::string16
>& input_words
,
63 const ContactData
& contact
);
65 // Returns an AutocompleteMatch object corresponding to the passed-in data.
66 AutocompleteMatch
CreateAutocompleteMatch(const AutocompleteInput
& input
,
67 const ContactData
& contact
);
69 base::WeakPtr
<contacts::ContactManagerInterface
> contact_manager_
;
71 // Contacts through which we search, ordered by descending affinity.
72 ContactDataVector contacts_
;
74 DISALLOW_COPY_AND_ASSIGN(ContactProvider
);
77 #endif // CHROME_BROWSER_AUTOCOMPLETE_CONTACT_PROVIDER_CHROMEOS_H_