| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/chromeos/contacts/contact_manager_stub.h" | 5 #include "chrome/browser/chromeos/contacts/contact_manager_stub.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
| 9 #include "chrome/browser/chromeos/contacts/contact.pb.h" | 9 #include "chrome/browser/chromeos/contacts/contact.pb.h" |
| 10 #include "chrome/browser/chromeos/contacts/contact_manager_observer.h" | 10 #include "chrome/browser/chromeos/contacts/contact_manager_observer.h" |
| 11 #include "chrome/browser/chromeos/contacts/contact_test_util.h" | 11 #include "chrome/browser/chromeos/contacts/contact_test_util.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 13 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
| 14 | 14 |
| 15 using content::BrowserThread; | 15 using content::BrowserThread; |
| 16 | 16 |
| 17 namespace contacts { | 17 namespace contacts { |
| 18 | 18 |
| 19 ContactManagerStub::ContactManagerStub(Profile* profile) : profile_(profile) {} | 19 ContactManagerStub::ContactManagerStub(Profile* profile) |
| 20 : profile_(profile), |
| 21 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { |
| 22 } |
| 20 | 23 |
| 21 ContactManagerStub::~ContactManagerStub() {} | 24 ContactManagerStub::~ContactManagerStub() {} |
| 22 | 25 |
| 23 void ContactManagerStub::NotifyObserversAboutUpdatedContacts() { | 26 void ContactManagerStub::NotifyObserversAboutUpdatedContacts() { |
| 24 FOR_EACH_OBSERVER(ContactManagerObserver, | 27 FOR_EACH_OBSERVER(ContactManagerObserver, |
| 25 observers_, | 28 observers_, |
| 26 OnContactsUpdated(profile_)); | 29 OnContactsUpdated(profile_)); |
| 27 } | 30 } |
| 28 | 31 |
| 29 void ContactManagerStub::SetContacts(const ContactPointers& contacts) { | 32 void ContactManagerStub::SetContacts(const ContactPointers& contacts) { |
| 30 test::CopyContacts(contacts, &contacts_); | 33 test::CopyContacts(contacts, &contacts_); |
| 31 } | 34 } |
| 32 | 35 |
| 36 base::WeakPtr<ContactManagerInterface> ContactManagerStub::GetWeakPtr() { |
| 37 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 38 return weak_ptr_factory_.GetWeakPtr(); |
| 39 } |
| 40 |
| 33 void ContactManagerStub::AddObserver(ContactManagerObserver* observer, | 41 void ContactManagerStub::AddObserver(ContactManagerObserver* observer, |
| 34 Profile* profile) { | 42 Profile* profile) { |
| 35 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 43 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 36 CHECK(observer); | 44 CHECK(observer); |
| 37 CHECK_EQ(profile, profile_); | 45 CHECK_EQ(profile, profile_); |
| 38 CHECK(!observers_.HasObserver(observer)); | 46 CHECK(!observers_.HasObserver(observer)); |
| 39 observers_.AddObserver(observer); | 47 observers_.AddObserver(observer); |
| 40 } | 48 } |
| 41 | 49 |
| 42 void ContactManagerStub::RemoveObserver(ContactManagerObserver* observer, | 50 void ContactManagerStub::RemoveObserver(ContactManagerObserver* observer, |
| (...skipping 21 matching lines...) Expand all Loading... |
| 64 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 72 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 65 CHECK_EQ(profile, profile_); | 73 CHECK_EQ(profile, profile_); |
| 66 for (size_t i = 0; i < contacts_.size(); ++i) { | 74 for (size_t i = 0; i < contacts_.size(); ++i) { |
| 67 if (contacts_[i]->contact_id() == contact_id) | 75 if (contacts_[i]->contact_id() == contact_id) |
| 68 return contacts_[i]; | 76 return contacts_[i]; |
| 69 } | 77 } |
| 70 return NULL; | 78 return NULL; |
| 71 } | 79 } |
| 72 | 80 |
| 73 } // namespace contacts | 81 } // namespace contacts |
| OLD | NEW |