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

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

Issue 10896031: contacts: Add ContactManagerInterface::GetWeakPtr(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: apply review feedback Created 8 years, 3 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
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 #ifndef CHROME_BROWSER_CHROMEOS_CONTACTS_CONTACT_MANAGER_H_ 5 #ifndef CHROME_BROWSER_CHROMEOS_CONTACTS_CONTACT_MANAGER_H_
6 #define CHROME_BROWSER_CHROMEOS_CONTACTS_CONTACT_MANAGER_H_ 6 #define CHROME_BROWSER_CHROMEOS_CONTACTS_CONTACT_MANAGER_H_
7 7
8 #include <map> 8 #include <map>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/weak_ptr.h"
14 #include "base/observer_list.h" 15 #include "base/observer_list.h"
15 #include "base/stl_util.h" 16 #include "base/stl_util.h"
16 #include "chrome/browser/chromeos/contacts/contact_store_observer.h" 17 #include "chrome/browser/chromeos/contacts/contact_store_observer.h"
17 #include "content/public/browser/notification_observer.h" 18 #include "content/public/browser/notification_observer.h"
18 #include "content/public/browser/notification_registrar.h" 19 #include "content/public/browser/notification_registrar.h"
19 20
20 class Profile; 21 class Profile;
21 22
22 namespace contacts { 23 namespace contacts {
23 24
24 class Contact; 25 class Contact;
25 typedef std::vector<const Contact*> ContactPointers; 26 typedef std::vector<const Contact*> ContactPointers;
26 27
27 class ContactManagerObserver; 28 class ContactManagerObserver;
28 class ContactStore; 29 class ContactStore;
29 class ContactStoreFactory; 30 class ContactStoreFactory;
30 31
31 // Class that exposes contacts to rest of the browser. 32 // Class that exposes contacts to rest of the browser.
32 class ContactManagerInterface { 33 class ContactManagerInterface {
33 public: 34 public:
34 ContactManagerInterface() {} 35 ContactManagerInterface() {}
35 virtual ~ContactManagerInterface() {} 36 virtual ~ContactManagerInterface() {}
36 37
38 // Returns a weak pointer tied to the lifetime of this object.
39 virtual base::WeakPtr<ContactManagerInterface> GetWeakPtr() = 0;
40
37 // Adds or removes an observer for changes to |profile|'s contacts. 41 // Adds or removes an observer for changes to |profile|'s contacts.
38 virtual void AddObserver(ContactManagerObserver* observer, 42 virtual void AddObserver(ContactManagerObserver* observer,
39 Profile* profile) = 0; 43 Profile* profile) = 0;
40 virtual void RemoveObserver(ContactManagerObserver* observer, 44 virtual void RemoveObserver(ContactManagerObserver* observer,
41 Profile* profile) = 0; 45 Profile* profile) = 0;
42 46
43 // Returns pointers to all currently-loaded contacts for |profile|. The 47 // Returns pointers to all currently-loaded contacts for |profile|. The
44 // returned Contact objects may not persist indefinitely; the caller must not 48 // returned Contact objects may not persist indefinitely; the caller must not
45 // refer to them again after unblocking the UI thread. 49 // refer to them again after unblocking the UI thread.
46 virtual scoped_ptr<ContactPointers> GetAllContacts(Profile* profile) = 0; 50 virtual scoped_ptr<ContactPointers> GetAllContacts(Profile* profile) = 0;
(...skipping 17 matching lines...) Expand all
64 ContactManager(); 68 ContactManager();
65 virtual ~ContactManager(); 69 virtual ~ContactManager();
66 70
67 // Swaps in a new factory to use for creating ContactStores. 71 // Swaps in a new factory to use for creating ContactStores.
68 // Must be called before any stores have been created. 72 // Must be called before any stores have been created.
69 void SetContactStoreForTesting(scoped_ptr<ContactStoreFactory> factory); 73 void SetContactStoreForTesting(scoped_ptr<ContactStoreFactory> factory);
70 74
71 void Init(); 75 void Init();
72 76
73 // ContactManagerInterface overrides: 77 // ContactManagerInterface overrides:
78 virtual base::WeakPtr<ContactManagerInterface> GetWeakPtr() OVERRIDE;
74 virtual void AddObserver(ContactManagerObserver* observer, 79 virtual void AddObserver(ContactManagerObserver* observer,
75 Profile* profile) OVERRIDE; 80 Profile* profile) OVERRIDE;
76 virtual void RemoveObserver(ContactManagerObserver* observer, 81 virtual void RemoveObserver(ContactManagerObserver* observer,
77 Profile* profile) OVERRIDE; 82 Profile* profile) OVERRIDE;
78 virtual scoped_ptr<ContactPointers> GetAllContacts(Profile* profile) OVERRIDE; 83 virtual scoped_ptr<ContactPointers> GetAllContacts(Profile* profile) OVERRIDE;
79 virtual const Contact* GetContactById(Profile* profile, 84 virtual const Contact* GetContactById(Profile* profile,
80 const std::string& contact_id) OVERRIDE; 85 const std::string& contact_id) OVERRIDE;
81 86
82 // ContactStoreObserver overrides: 87 // ContactStoreObserver overrides:
83 virtual void OnContactsUpdated(ContactStore* store) OVERRIDE; 88 virtual void OnContactsUpdated(ContactStore* store) OVERRIDE;
(...skipping 27 matching lines...) Expand all
111 116
112 // Creates objects for |contact_stores_|. 117 // Creates objects for |contact_stores_|.
113 scoped_ptr<ContactStoreFactory> contact_store_factory_; 118 scoped_ptr<ContactStoreFactory> contact_store_factory_;
114 119
115 // Maps from a profile to a store for getting the profile's contacts. 120 // Maps from a profile to a store for getting the profile's contacts.
116 ContactStoreMap contact_stores_; 121 ContactStoreMap contact_stores_;
117 122
118 // Deletes values in |contact_stores_|. 123 // Deletes values in |contact_stores_|.
119 STLValueDeleter<ContactStoreMap> contact_stores_deleter_; 124 STLValueDeleter<ContactStoreMap> contact_stores_deleter_;
120 125
126 // Note: This should remain the last member so it'll be destroyed and
127 // invalidate its weak pointers before any other members are destroyed.
128 base::WeakPtrFactory<ContactManagerInterface> weak_ptr_factory_;
129
121 DISALLOW_COPY_AND_ASSIGN(ContactManager); 130 DISALLOW_COPY_AND_ASSIGN(ContactManager);
122 }; 131 };
123 132
124 } // namespace contacts 133 } // namespace contacts
125 134
126 #endif // CHROME_BROWSER_CHROMEOS_CONTACTS_CONTACT_MANAGER_H_ 135 #endif // CHROME_BROWSER_CHROMEOS_CONTACTS_CONTACT_MANAGER_H_
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/contacts/contact_database_unittest.cc ('k') | chrome/browser/chromeos/contacts/contact_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698