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

Side by Side Diff: chrome/browser/chromeos/contacts/contact_manager.h

Issue 10831162: contacts: Add ContactManager. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: apply review feedback and merge Created 8 years, 4 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_CHROMEOS_CONTACTS_CONTACT_MANAGER_H_
6 #define CHROME_BROWSER_CHROMEOS_CONTACTS_CONTACT_MANAGER_H_
7
8 #include <map>
9 #include <vector>
10
11 #include "base/basictypes.h"
12 #include "base/compiler_specific.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/observer_list.h"
15 #include "base/stl_util.h"
16 #include "chrome/browser/chromeos/contacts/contact_store_observer.h"
17 #include "content/public/browser/notification_observer.h"
18 #include "content/public/browser/notification_registrar.h"
19
20 class Profile;
21
22 namespace contacts {
23
24 class Contact;
25 typedef std::vector<const Contact*> ContactPointers;
26
27 class ContactManagerObserver;
28 class ContactStore;
29 class ContactStoreFactory;
30
31 // Singleton class that exposes contacts to rest of the browser.
32 class ContactManager : public ContactStoreObserver,
33 public content::NotificationObserver {
34 public:
35 static ContactManager* GetInstance();
36
37 ContactManager();
38 ~ContactManager();
39
40 // Swaps in a new factory to use for creating ContactStores.
41 // Must be called before any stores have been created.
42 void SetContactStoreForTesting(scoped_ptr<ContactStoreFactory> factory);
43
44 void Init();
45
46 // Adds or removes an observer for changes to |profile|'s contacts.
47 void AddObserver(ContactManagerObserver* observer, Profile* profile);
48 void RemoveObserver(ContactManagerObserver* observer, Profile* profile);
49
50 // Returns pointers to all currently-loaded contacts for |profile|. The
51 // returned Contact objects may not persist indefinitely; the caller must not
52 // refer to them again after unblocking the UI thread.
53 scoped_ptr<ContactPointers> GetAllContacts(Profile* profile);
54
55 // Returns the contact identified by |provider_id|.
56 // NULL is returned if the contact doesn't exist.
57 const Contact* GetContactByProviderId(Profile* profile,
58 const std::string& provider_id);
59
60 // ContactStoreObserver overrides:
61 virtual void OnContactsUpdated(ContactStore* store) OVERRIDE;
62
63 // content::NotificationObserver overrides:
64 virtual void Observe(int type,
65 const content::NotificationSource& source,
66 const content::NotificationDetails& details) OVERRIDE;
67
68 private:
69 typedef ObserverList<ContactManagerObserver> Observers;
70 typedef std::map<Profile*, ContactStore*> ContactStoreMap;
71 typedef std::map<Profile*, Observers*> ProfileObserversMap;
72
73 // Returns the list of observers interested in |profile|. If not present,
74 // creates a new list if |create| is true and returns NULL otherwise.
75 Observers* GetObserversForProfile(Profile* profile, bool create);
76
77 // Handles profile creation and destruction.
78 void HandleProfileCreated(Profile* profile);
79 void HandleProfileDestroyed(Profile* profile);
80
81 content::NotificationRegistrar registrar_;
82
83 // Maps from a profile to observers that are interested in changes to that
84 // profile's contacts.
85 ProfileObserversMap profile_observers_;
86
87 // Deletes values in |profile_observers_|.
88 STLValueDeleter<ProfileObserversMap> profile_observers_deleter_;
89
90 // Creates objects for |contact_stores_|.
91 scoped_ptr<ContactStoreFactory> contact_store_factory_;
92
93 // Maps from a profile to a store for getting the profile's contacts.
94 ContactStoreMap contact_stores_;
95
96 // Deletes values in |contact_stores_|.
97 STLValueDeleter<ContactStoreMap> contact_stores_deleter_;
98
99 DISALLOW_COPY_AND_ASSIGN(ContactManager);
100 };
101
102 } // namespace contacts
103
104 #endif // CHROME_BROWSER_CHROMEOS_CONTACTS_CONTACT_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698