Index: chrome/browser/autocomplete/contact_provider_chromeos.h |
diff --git a/chrome/browser/autocomplete/contact_provider_chromeos.h b/chrome/browser/autocomplete/contact_provider_chromeos.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..d11693c956e945a0d595a97605e75962cdb87e0b |
--- /dev/null |
+++ b/chrome/browser/autocomplete/contact_provider_chromeos.h |
@@ -0,0 +1,93 @@ |
+// Copyright (c) 2012 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. |
+ |
+#ifndef CHROME_BROWSER_AUTOCOMPLETE_CONTACT_PROVIDER_CHROMEOS_H_ |
+#define CHROME_BROWSER_AUTOCOMPLETE_CONTACT_PROVIDER_CHROMEOS_H_ |
+ |
+#include <utility> |
+#include <vector> |
+ |
+#include "base/basictypes.h" |
+#include "base/compiler_specific.h" |
+#include "base/memory/weak_ptr.h" |
+#include "base/string16.h" |
+#include "chrome/browser/autocomplete/autocomplete_match.h" |
+#include "chrome/browser/autocomplete/autocomplete_provider.h" |
+#include "chrome/browser/chromeos/contacts/contact_manager_observer.h" |
+ |
+class AutocompleteInput; |
+ |
+namespace contacts { |
+class ContactManagerInterface; |
+} |
+ |
+// AutocompleteProvider implementation that searches through the contacts |
+// provided by contacts::ContactManager. |
+class ContactProvider : public AutocompleteProvider, |
+ public contacts::ContactManagerObserver { |
+ public: |
+ typedef std::pair<size_t, size_t> MatchSpan; |
+ typedef std::vector<MatchSpan> MatchSpans; |
+ |
+ // Key within AutocompleteMatch::additional_info where the corresponding |
+ // contact's ID is stored. |
+ static const char kMatchContactIdKey[]; |
+ |
+ class TestAPI { |
+ public: |
+ explicit TestAPI(ContactProvider* provider); |
+ ~TestAPI(); |
+ |
+ // Runs the FillACMatchClassifications() function. |
+ static AutocompleteMatch::ACMatchClassifications |
+ RunFillACMatchClassifications( |
+ const MatchSpans& match_spans, |
+ size_t text_length); |
+ |
+ private: |
+ ContactProvider* provider_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(TestAPI); |
+ }; |
+ |
+ ContactProvider( |
+ AutocompleteProviderListener* listener, |
+ Profile* profile, |
+ base::WeakPtr<contacts::ContactManagerInterface> contact_manager); |
+ |
+ // AutocompleteProvider overrides: |
+ virtual void Start(const AutocompleteInput& input, |
+ bool minimal_changes) OVERRIDE; |
+ |
+ // contacts::ContactManagerObserver overrides: |
+ virtual void OnContactsUpdated(Profile* profile) OVERRIDE; |
+ |
+ private: |
+ struct ContactData; |
+ typedef std::vector<ContactData> ContactDataVector; |
+ |
+ virtual ~ContactProvider(); |
+ |
+ // Updates |contacts_| to match the contacts currently reported by |
+ // ContactManager. |
+ void RefreshContacts(); |
+ |
+ // Returns an AutocompleteMatch object corresponding to the passed-in data. |
+ // |match_spans| contains sorted (but possibly overlapping) [index, length] |
+ // pairs describing the spans within |contact.full_name| that were matched by |
+ // |input|. |
+ AutocompleteMatch CreateAutocompleteMatch( |
+ const AutocompleteInput& input, |
+ const ContactData& contact, |
+ const MatchSpans& match_spans); |
+ |
+ base::WeakPtr<contacts::ContactManagerInterface> contact_manager_; |
+ |
+ // Contacts through which we search. |
+ ContactDataVector contacts_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(ContactProvider); |
+}; |
+ |
+#endif // CHROME_BROWSER_AUTOCOMPLETE_CONTACT_PROVIDER_CHROMEOS_H_ |