Index: chrome/browser/autocomplete/contact_provider_chromeos.cc |
diff --git a/chrome/browser/autocomplete/contact_provider_chromeos.cc b/chrome/browser/autocomplete/contact_provider_chromeos.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..be2eb38f0c9925f786bb373ac91a920c8f6c040d |
--- /dev/null |
+++ b/chrome/browser/autocomplete/contact_provider_chromeos.cc |
@@ -0,0 +1,89 @@ |
+// 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. |
+ |
+#include "chrome/browser/autocomplete/contact_provider_chromeos.h" |
+ |
+#include <vector> |
+ |
+#include "base/i18n/string_search.h" |
+#include "base/string16.h" |
+#include "base/utf_string_conversions.h" |
+#include "chrome/browser/autocomplete/autocomplete_input.h" |
+#include "chrome/browser/autocomplete/autocomplete_match.h" |
+#include "chrome/browser/chromeos/contacts/contact.h" |
+#include "chrome/browser/chromeos/contacts/contact_manager.h" |
+#include "chrome/browser/profiles/profile.h" |
+ |
+ContactProvider::ContactProvider( |
+ AutocompleteProviderListener* listener, |
+ Profile* profile) |
+ : AutocompleteProvider(listener, profile, "Contacts") { |
+ contacts::ContactManager* manager = contacts::ContactManager::GetInstance(); |
+ DCHECK(manager); |
+ manager->AddObserver(this); |
+ RefreshContacts(manager); |
+} |
+ |
+void ContactProvider::Start(const AutocompleteInput& input, |
+ bool minimal_changes) { |
+ matches_.clear(); |
+ |
+ if ((input.type() == AutocompleteInput::INVALID) || |
+ (input.type() == AutocompleteInput::FORCED_QUERY)) |
+ return; |
+ |
+ if (input.text().empty()) |
+ return; |
+ |
+ for (ContactDataVector::const_iterator it = contacts_.begin(); |
+ it != contacts_.end(); ++it) { |
+ const ContactData& contact = *it; |
+ // FIXME: do something better than this |
+ string16 name = UTF8ToUTF16(contact.name); |
+ if (base::i18n::StringSearchIgnoringCaseAndAccents(input.text(), name)) { |
+ AutocompleteMatch match(this, 0, false, AutocompleteMatch::CONTACT); |
+ match.fill_into_edit = input.text(); |
+ match.inline_autocomplete_offset = string16::npos; |
+ match.contents = AutocompleteMatch::SanitizeString(name); |
+ match.destination_url = GURL(contact.provider_id); // FIXME: this is bogus |
+ AutocompleteMatch::ClassifyMatchInString( |
+ input.text(), |
+ name, |
+ AutocompleteMatch::ACMatchClassification::MATCH, |
+ &match.contents_class); |
+ match.relevance = 1000; // FIXME: update autocomplete_provider.h |
+ matches_.push_back(match); |
+ } |
+ } |
+} |
+ |
+void ContactProvider::OnContactsUpdated(contacts::ContactManager* manager) { |
+ RefreshContacts(manager); |
+} |
+ |
+ContactProvider::ContactData::ContactData(const std::string& name, |
+ const std::string& provider_id) |
+ : name(name), |
+ provider_id(provider_id) { |
+} |
+ |
+ContactProvider::~ContactProvider() { |
+ contacts::ContactManager* manager = contacts::ContactManager::GetInstance(); |
+ DCHECK(manager); |
+ manager->RemoveObserver(this); |
+} |
+ |
+void ContactProvider::RefreshContacts(contacts::ContactManager* manager) { |
+ DCHECK(manager); |
+ typedef std::vector<const contacts::Contact*> ContactPointers; |
+ ContactPointers contacts; |
+ manager->GetAllContacts(&contacts); |
+ |
+ contacts_.clear(); |
+ for (ContactPointers::const_iterator it = contacts.begin(); |
+ it != contacts.end(); ++it) { |
+ const contacts::Contact& contact = **it; |
+ contacts_.push_back(ContactData(contact.full_name, contact.provider_id)); |
+ } |
+} |