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_GOOGLE_CONTACT_STORE_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_CONTACTS_GOOGLE_CONTACT_STORE_H_ |
6 #define CHROME_BROWSER_CHROMEOS_CONTACTS_GOOGLE_CONTACT_STORE_H_ | 6 #define CHROME_BROWSER_CHROMEOS_CONTACTS_GOOGLE_CONTACT_STORE_H_ |
7 | 7 |
8 #include "chrome/browser/chromeos/contacts/contact_store.h" | 8 #include "chrome/browser/chromeos/contacts/contact_store.h" |
9 | 9 |
10 #include <map> | 10 #include <map> |
11 #include <string> | 11 #include <string> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
15 #include "base/compiler_specific.h" | 15 #include "base/compiler_specific.h" |
16 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
17 #include "base/memory/scoped_vector.h" | 17 #include "base/memory/scoped_vector.h" |
18 #include "base/memory/weak_ptr.h" | 18 #include "base/memory/weak_ptr.h" |
19 #include "base/observer_list.h" | 19 #include "base/observer_list.h" |
20 #include "base/stl_util.h" | 20 #include "base/stl_util.h" |
21 #include "base/time.h" | 21 #include "base/time.h" |
22 #include "base/timer.h" | 22 #include "base/timer.h" |
23 #include "net/base/network_change_notifier.h" | |
23 | 24 |
24 class Profile; | 25 class Profile; |
25 | 26 |
26 namespace gdata { | 27 namespace gdata { |
27 class GDataContactsServiceInterface; | 28 class GDataContactsServiceInterface; |
28 } | 29 } |
29 | 30 |
30 namespace contacts { | 31 namespace contacts { |
31 | 32 |
32 class Contact; | 33 class Contact; |
33 class ContactDatabaseInterface; | 34 class ContactDatabaseInterface; |
34 class UpdateMetadata; | 35 class UpdateMetadata; |
35 | 36 |
36 // A collection of contacts from a Google account. | 37 // A collection of contacts from a Google account. |
37 class GoogleContactStore : public ContactStore { | 38 class GoogleContactStore |
39 : public ContactStore, | |
40 public net::NetworkChangeNotifier::ConnectionTypeObserver { | |
satorux1
2012/08/08 21:42:27
I didn't know about this. in gdata_sync_client.cc,
| |
38 public: | 41 public: |
39 class TestAPI { | 42 class TestAPI { |
40 public: | 43 public: |
41 explicit TestAPI(GoogleContactStore* store); | 44 explicit TestAPI(GoogleContactStore* store); |
42 ~TestAPI(); | 45 ~TestAPI(); |
43 | 46 |
44 bool update_scheduled() { return store_->update_timer_.IsRunning(); } | 47 bool update_scheduled() { return store_->update_timer_.IsRunning(); } |
45 | 48 |
46 void set_current_time(const base::Time& time) { | 49 void set_current_time(const base::Time& time) { |
47 store_->current_time_for_testing_ = time; | 50 store_->current_time_for_testing_ = time; |
48 } | 51 } |
49 | 52 |
50 // Takes ownership of |db|. Must be called before Init(). | 53 // Takes ownership of |db|. Must be called before Init(). |
51 void SetDatabase(ContactDatabaseInterface* db); | 54 void SetDatabase(ContactDatabaseInterface* db); |
52 | 55 |
53 // Takes ownership of |service|. Must be called before Init(). | 56 // Takes ownership of |service|. Must be called before Init(). |
54 void SetGDataService(gdata::GDataContactsServiceInterface* service); | 57 void SetGDataService(gdata::GDataContactsServiceInterface* service); |
55 | 58 |
56 // Triggers an update, similar to what happens when the update timer fires. | 59 // Triggers an update, similar to what happens when the update timer fires. |
57 void DoUpdate(); | 60 void DoUpdate(); |
58 | 61 |
62 // Notifies the store that the system has gone online or offline. | |
63 void NotifyAboutNetworkStateChange(bool online); | |
64 | |
59 private: | 65 private: |
60 GoogleContactStore* store_; // not owned | 66 GoogleContactStore* store_; // not owned |
61 | 67 |
62 DISALLOW_COPY_AND_ASSIGN(TestAPI); | 68 DISALLOW_COPY_AND_ASSIGN(TestAPI); |
63 }; | 69 }; |
64 | 70 |
65 explicit GoogleContactStore(Profile* profile); | 71 explicit GoogleContactStore(Profile* profile); |
66 virtual ~GoogleContactStore(); | 72 virtual ~GoogleContactStore(); |
67 | 73 |
68 // ContactStore implementation: | 74 // ContactStore implementation: |
69 virtual void Init() OVERRIDE; | 75 virtual void Init() OVERRIDE; |
70 virtual void AppendContacts(ContactPointers* contacts_out) OVERRIDE; | 76 virtual void AppendContacts(ContactPointers* contacts_out) OVERRIDE; |
71 virtual const Contact* GetContactByProviderId( | 77 virtual const Contact* GetContactByProviderId( |
72 const std::string& provider_id) OVERRIDE; | 78 const std::string& provider_id) OVERRIDE; |
73 virtual void AddObserver(ContactStoreObserver* observer) OVERRIDE; | 79 virtual void AddObserver(ContactStoreObserver* observer) OVERRIDE; |
74 virtual void RemoveObserver(ContactStoreObserver* observer) OVERRIDE; | 80 virtual void RemoveObserver(ContactStoreObserver* observer) OVERRIDE; |
75 | 81 |
82 // net::NetworkChangeNotifier::ConnectionTypeObserver implementation: | |
83 virtual void OnConnectionTypeChanged( | |
84 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE; | |
85 | |
76 private: | 86 private: |
77 // Map from a contact's Google-assigned ID to the contact itself. | 87 // Map from a contact's Google-assigned ID to the contact itself. |
78 typedef std::map<std::string, Contact*> ContactMap; | 88 typedef std::map<std::string, Contact*> ContactMap; |
79 | 89 |
80 // Returns the current time. Uses |current_time_for_testing_| instead if it's | 90 // Returns the current time. Uses |current_time_for_testing_| instead if it's |
81 // set. | 91 // set. |
82 base::Time GetCurrentTime() const; | 92 base::Time GetCurrentTime() const; |
83 | 93 |
84 // Destroys |db_| if non-NULL and resets the pointer. | 94 // Destroys |db_| if non-NULL and resets the pointer. |
85 // The underlying data is preserved on-disk. | 95 // The underlying data is preserved on-disk. |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
143 // Used to schedule calls to UpdateContacts(). | 153 // Used to schedule calls to UpdateContacts(). |
144 base::OneShotTimer<GoogleContactStore> update_timer_; | 154 base::OneShotTimer<GoogleContactStore> update_timer_; |
145 | 155 |
146 // Time at which the last successful update was started. | 156 // Time at which the last successful update was started. |
147 base::Time last_successful_update_start_time_; | 157 base::Time last_successful_update_start_time_; |
148 | 158 |
149 // Amount of time that we'll wait before retrying the next time that an update | 159 // Amount of time that we'll wait before retrying the next time that an update |
150 // fails. | 160 // fails. |
151 base::TimeDelta update_delay_on_next_failure_; | 161 base::TimeDelta update_delay_on_next_failure_; |
152 | 162 |
163 // Do we believe that it's likely that we'll be able to make network | |
164 // connections? | |
165 bool is_online_; | |
166 | |
167 // Should we call UpdateContacts() when |is_online_| becomes true? Set when | |
168 // UpdateContacts() is called while we're offline. | |
169 bool should_update_when_online_; | |
170 | |
153 // If non-null, used in place of base::Time::Now() when the current time is | 171 // If non-null, used in place of base::Time::Now() when the current time is |
154 // needed. | 172 // needed. |
155 base::Time current_time_for_testing_; | 173 base::Time current_time_for_testing_; |
156 | 174 |
157 // Note: This should remain the last member so it'll be destroyed and | 175 // Note: This should remain the last member so it'll be destroyed and |
158 // invalidate its weak pointers before any other members are destroyed. | 176 // invalidate its weak pointers before any other members are destroyed. |
159 base::WeakPtrFactory<GoogleContactStore> weak_ptr_factory_; | 177 base::WeakPtrFactory<GoogleContactStore> weak_ptr_factory_; |
160 | 178 |
161 DISALLOW_COPY_AND_ASSIGN(GoogleContactStore); | 179 DISALLOW_COPY_AND_ASSIGN(GoogleContactStore); |
162 }; | 180 }; |
163 | 181 |
164 // ContactStoreFactory implementation that returns GoogleContactStores. | 182 // ContactStoreFactory implementation that returns GoogleContactStores. |
165 class GoogleContactStoreFactory : public ContactStoreFactory { | 183 class GoogleContactStoreFactory : public ContactStoreFactory { |
166 public: | 184 public: |
167 GoogleContactStoreFactory(); | 185 GoogleContactStoreFactory(); |
168 virtual ~GoogleContactStoreFactory(); | 186 virtual ~GoogleContactStoreFactory(); |
169 | 187 |
170 // ContactStoreFactory implementation: | 188 // ContactStoreFactory implementation: |
171 virtual bool CanCreateContactStoreForProfile(Profile* profile) OVERRIDE; | 189 virtual bool CanCreateContactStoreForProfile(Profile* profile) OVERRIDE; |
172 virtual ContactStore* CreateContactStore(Profile* profile) OVERRIDE; | 190 virtual ContactStore* CreateContactStore(Profile* profile) OVERRIDE; |
173 | 191 |
174 private: | 192 private: |
175 DISALLOW_COPY_AND_ASSIGN(GoogleContactStoreFactory); | 193 DISALLOW_COPY_AND_ASSIGN(GoogleContactStoreFactory); |
176 }; | 194 }; |
177 | 195 |
178 } // namespace contacts | 196 } // namespace contacts |
179 | 197 |
180 #endif // CHROME_BROWSER_CHROMEOS_CONTACTS_GOOGLE_CONTACT_STORE_H_ | 198 #endif // CHROME_BROWSER_CHROMEOS_CONTACTS_GOOGLE_CONTACT_STORE_H_ |
OLD | NEW |