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 #ifndef CHROME_BROWSER_CHROMEOS_CONTACTS_CONTACT_DATABASE_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_CONTACTS_CONTACT_DATABASE_H_ |
6 #define CHROME_BROWSER_CHROMEOS_CONTACTS_CONTACT_DATABASE_H_ | 6 #define CHROME_BROWSER_CHROMEOS_CONTACTS_CONTACT_DATABASE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 24 matching lines...) Expand all Loading... |
35 class ContactDatabaseInterface { | 35 class ContactDatabaseInterface { |
36 public: | 36 public: |
37 typedef std::vector<std::string> ContactIds; | 37 typedef std::vector<std::string> ContactIds; |
38 typedef base::Callback<void(bool success)> InitCallback; | 38 typedef base::Callback<void(bool success)> InitCallback; |
39 typedef base::Callback<void(bool success)> SaveCallback; | 39 typedef base::Callback<void(bool success)> SaveCallback; |
40 typedef base::Callback<void(bool success, | 40 typedef base::Callback<void(bool success, |
41 scoped_ptr<ScopedVector<Contact> >, | 41 scoped_ptr<ScopedVector<Contact> >, |
42 scoped_ptr<UpdateMetadata>)> | 42 scoped_ptr<UpdateMetadata>)> |
43 LoadCallback; | 43 LoadCallback; |
44 | 44 |
45 ContactDatabaseInterface() {} | |
46 | |
47 // Asynchronously destroys the object after all in-progress file operations | 45 // Asynchronously destroys the object after all in-progress file operations |
48 // have completed. | 46 // have completed. |
49 virtual void DestroyOnUIThread() {} | 47 virtual void DestroyOnUIThread() {} |
50 | 48 |
51 // Asynchronously initializes the object. |callback| will be invoked on the | 49 // Asynchronously initializes the object. |callback| will be invoked on the |
52 // UI thread when complete. | 50 // UI thread when complete. |
53 virtual void Init(const FilePath& database_dir, InitCallback callback) = 0; | 51 virtual void Init(const FilePath& database_dir, InitCallback callback) = 0; |
54 | 52 |
55 // Asynchronously saves |contacts_to_save| and |metadata| to the database and | 53 // Asynchronously saves |contacts_to_save| and |metadata| to the database and |
56 // removes contacts with IDs contained in |contact_ids_to_delete|. If | 54 // removes contacts with IDs contained in |contact_ids_to_delete|. If |
57 // |is_full_update| is true, all existing contacts in the database not present | 55 // |is_full_update| is true, all existing contacts in the database not present |
58 // in |contacts_to_save| will be removed. |callback| will be invoked on the | 56 // in |contacts_to_save| will be removed. |callback| will be invoked on the |
59 // UI thread when complete. The caller must not make changes to the | 57 // UI thread when complete. The caller must not make changes to the |
60 // underlying passed-in Contact objects until the callback has been invoked. | 58 // underlying passed-in Contact objects until the callback has been invoked. |
61 virtual void SaveContacts(scoped_ptr<ContactPointers> contacts_to_save, | 59 virtual void SaveContacts(scoped_ptr<ContactPointers> contacts_to_save, |
62 scoped_ptr<ContactIds> contact_ids_to_delete, | 60 scoped_ptr<ContactIds> contact_ids_to_delete, |
63 scoped_ptr<UpdateMetadata> metadata, | 61 scoped_ptr<UpdateMetadata> metadata, |
64 bool is_full_update, | 62 bool is_full_update, |
65 SaveCallback callback) = 0; | 63 SaveCallback callback) = 0; |
66 | 64 |
67 // Asynchronously loads all contacts from the database and invokes |callback| | 65 // Asynchronously loads all contacts from the database and invokes |callback| |
68 // when complete. | 66 // when complete. |
69 virtual void LoadContacts(LoadCallback callback) = 0; | 67 virtual void LoadContacts(LoadCallback callback) = 0; |
70 | 68 |
71 protected: | 69 protected: |
72 virtual ~ContactDatabaseInterface() {} | 70 virtual ~ContactDatabaseInterface() {} |
73 | |
74 private: | |
75 DISALLOW_COPY_AND_ASSIGN(ContactDatabaseInterface); | |
76 }; | 71 }; |
77 | 72 |
78 class ContactDatabase : public ContactDatabaseInterface { | 73 class ContactDatabase : public ContactDatabaseInterface { |
79 public: | 74 public: |
80 ContactDatabase(); | 75 ContactDatabase(); |
81 | 76 |
82 // ContactDatabaseInterface implementation. | 77 // ContactDatabaseInterface implementation. |
83 virtual void DestroyOnUIThread() OVERRIDE; | 78 virtual void DestroyOnUIThread() OVERRIDE; |
84 virtual void Init(const FilePath& database_dir, | 79 virtual void Init(const FilePath& database_dir, |
85 InitCallback callback) OVERRIDE; | 80 InitCallback callback) OVERRIDE; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 // Note: This should remain the last member so it'll be destroyed and | 129 // Note: This should remain the last member so it'll be destroyed and |
135 // invalidate its weak pointers before any other members are destroyed. | 130 // invalidate its weak pointers before any other members are destroyed. |
136 base::WeakPtrFactory<ContactDatabase> weak_ptr_factory_; | 131 base::WeakPtrFactory<ContactDatabase> weak_ptr_factory_; |
137 | 132 |
138 DISALLOW_COPY_AND_ASSIGN(ContactDatabase); | 133 DISALLOW_COPY_AND_ASSIGN(ContactDatabase); |
139 }; | 134 }; |
140 | 135 |
141 } // namespace contacts | 136 } // namespace contacts |
142 | 137 |
143 #endif // CHROME_BROWSER_CHROMEOS_CONTACTS_CONTACT_DATABASE_H_ | 138 #endif // CHROME_BROWSER_CHROMEOS_CONTACTS_CONTACT_DATABASE_H_ |
OLD | NEW |