| 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.h" | 5 #include "chrome/browser/chromeos/contacts/contact_manager.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" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 // static | 30 // static |
| 31 ContactManager* ContactManager::GetInstance() { | 31 ContactManager* ContactManager::GetInstance() { |
| 32 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 32 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 33 DCHECK(g_instance); | 33 DCHECK(g_instance); |
| 34 return g_instance; | 34 return g_instance; |
| 35 } | 35 } |
| 36 | 36 |
| 37 ContactManager::ContactManager() | 37 ContactManager::ContactManager() |
| 38 : profile_observers_deleter_(&profile_observers_), | 38 : profile_observers_deleter_(&profile_observers_), |
| 39 contact_store_factory_(new GoogleContactStoreFactory), | 39 contact_store_factory_(new GoogleContactStoreFactory), |
| 40 contact_stores_deleter_(&contact_stores_) { | 40 contact_stores_deleter_(&contact_stores_), |
| 41 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { |
| 41 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 42 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 42 DCHECK(!g_instance); | 43 DCHECK(!g_instance); |
| 43 g_instance = this; | 44 g_instance = this; |
| 44 } | 45 } |
| 45 | 46 |
| 46 ContactManager::~ContactManager() { | 47 ContactManager::~ContactManager() { |
| 47 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 48 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 48 DCHECK_EQ(g_instance, this); | 49 DCHECK_EQ(g_instance, this); |
| 50 weak_ptr_factory_.InvalidateWeakPtrs(); |
| 49 g_instance = NULL; | 51 g_instance = NULL; |
| 50 for (ContactStoreMap::const_iterator it = contact_stores_.begin(); | 52 for (ContactStoreMap::const_iterator it = contact_stores_.begin(); |
| 51 it != contact_stores_.end(); ++it) { | 53 it != contact_stores_.end(); ++it) { |
| 52 it->second->RemoveObserver(this); | 54 it->second->RemoveObserver(this); |
| 53 } | 55 } |
| 54 } | 56 } |
| 55 | 57 |
| 56 void ContactManager::SetContactStoreForTesting( | 58 void ContactManager::SetContactStoreForTesting( |
| 57 scoped_ptr<ContactStoreFactory> factory) { | 59 scoped_ptr<ContactStoreFactory> factory) { |
| 58 DCHECK(contact_stores_.empty()); | 60 DCHECK(contact_stores_.empty()); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 70 chrome::NOTIFICATION_PROFILE_DESTROYED, | 72 chrome::NOTIFICATION_PROFILE_DESTROYED, |
| 71 content::NotificationService::AllSources()); | 73 content::NotificationService::AllSources()); |
| 72 | 74 |
| 73 // Notify about any already-existing profiles. | 75 // Notify about any already-existing profiles. |
| 74 std::vector<Profile*> profiles( | 76 std::vector<Profile*> profiles( |
| 75 g_browser_process->profile_manager()->GetLoadedProfiles()); | 77 g_browser_process->profile_manager()->GetLoadedProfiles()); |
| 76 for (size_t i = 0; i < profiles.size(); ++i) | 78 for (size_t i = 0; i < profiles.size(); ++i) |
| 77 HandleProfileCreated(profiles[i]); | 79 HandleProfileCreated(profiles[i]); |
| 78 } | 80 } |
| 79 | 81 |
| 82 base::WeakPtr<ContactManagerInterface> ContactManager::GetWeakPtr() { |
| 83 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 84 return weak_ptr_factory_.GetWeakPtr(); |
| 85 } |
| 86 |
| 80 void ContactManager::AddObserver(ContactManagerObserver* observer, | 87 void ContactManager::AddObserver(ContactManagerObserver* observer, |
| 81 Profile* profile) { | 88 Profile* profile) { |
| 82 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 89 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 83 DCHECK(observer); | 90 DCHECK(observer); |
| 84 DCHECK(profile); | 91 DCHECK(profile); |
| 85 Observers* observers = GetObserversForProfile(profile, true); | 92 Observers* observers = GetObserversForProfile(profile, true); |
| 86 observers->AddObserver(observer); | 93 observers->AddObserver(observer); |
| 87 } | 94 } |
| 88 | 95 |
| 89 void ContactManager::RemoveObserver(ContactManagerObserver* observer, | 96 void ContactManager::RemoveObserver(ContactManagerObserver* observer, |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 } | 207 } |
| 201 | 208 |
| 202 ProfileObserversMap::iterator observer_it = profile_observers_.find(profile); | 209 ProfileObserversMap::iterator observer_it = profile_observers_.find(profile); |
| 203 if (observer_it != profile_observers_.end()) { | 210 if (observer_it != profile_observers_.end()) { |
| 204 delete observer_it->second; | 211 delete observer_it->second; |
| 205 profile_observers_.erase(observer_it); | 212 profile_observers_.erase(observer_it); |
| 206 } | 213 } |
| 207 } | 214 } |
| 208 | 215 |
| 209 } // namespace contacts | 216 } // namespace contacts |
| OLD | NEW |