Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5161)

Unified Diff: chrome/browser/autocomplete/contact_provider_chromeos.cc

Issue 10542076: ABANDONED: chromeos: Download contacts (work in progress). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: minor changes Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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));
+ }
+}
« no previous file with comments | « chrome/browser/autocomplete/contact_provider_chromeos.h ('k') | chrome/browser/chromeos/chrome_browser_main_chromeos.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698