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

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: diff against the correct branch 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 set_contact_store_factory_for_testing(
satorux1 2012/08/03 21:16:22 maybe SetContactStore... because the function is n
Daniel Erat 2012/08/03 22:12:07 Done.
43 scoped_ptr<ContactStoreFactory> factory);
44
45 void Init();
46
47 // Adds or removes an observer for changes to |profile|'s contacts.
48 void AddObserver(ContactManagerObserver* observer, Profile* profile);
49 void RemoveObserver(ContactManagerObserver* observer, Profile* profile);
50
51 // Returns pointers to all currently-loaded contacts for |profile|. The
52 // returned Contact objects may not persist indefinitely; the caller must not
53 // refer to them again after unblocking the UI thread.
54 scoped_ptr<ContactPointers> GetAllContacts(Profile* profile);
55
56 // Returns the contact identified by |provider_id|.
57 // NULL is returned if the contact doesn't exist.
58 const Contact* GetContactByProviderId(Profile* profile,
59 const std::string& provider_id);
60
61 // ContactStoreObserver overrides:
62 virtual void OnContactsUpdated(ContactStore* store) OVERRIDE;
63
64 // content::NotificationObserver overrides:
65 virtual void Observe(int type,
66 const content::NotificationSource& source,
67 const content::NotificationDetails& details) OVERRIDE;
68
69 private:
70 typedef ObserverList<ContactManagerObserver> Observers;
71 typedef std::map<Profile*, ContactStore*> ContactStoreMap;
72 typedef std::map<Profile*, Observers*> ProfileObserversMap;
73
74 // Returns the list of observers interested in |profile|. If not present,
75 // creates a new list if |create| is true and returns NULL otherwise.
76 Observers* GetObserversForProfile(Profile* profile, bool create);
77
78 // Handles profile creation and destruction.
79 void HandleProfileCreated(Profile* profile);
80 void HandleProfileDestroyed(Profile* profile);
81
82 // Singleton instance.
83 static ContactManager* instance_;
satorux1 2012/08/03 21:16:22 matter of taste of the day: you might want to put
Daniel Erat 2012/08/03 22:12:07 Done.
84
85 content::NotificationRegistrar registrar_;
86
87 // Maps from a profile to observers that are interested in changes to that
88 // profile's contacts.
89 ProfileObserversMap profile_observers_;
90
91 // Deletes values in |profile_observers_|.
92 STLValueDeleter<ProfileObserversMap> profile_observers_deleter_;
93
94 // Creates objects for |contact_stores_|.
95 scoped_ptr<ContactStoreFactory> contact_store_factory_;
96
97 // Maps from a profile to a store for getting the profile's contacts.
98 ContactStoreMap contact_stores_;
99
100 // Deletes values in |contact_stores_|.
101 STLValueDeleter<ContactStoreMap> contact_stores_deleter_;
102
103 DISALLOW_COPY_AND_ASSIGN(ContactManager);
104 };
105
106 } // namespace contacts
107
108 #endif // CHROME_BROWSER_CHROMEOS_CONTACTS_CONTACT_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698