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 #include "chrome/browser/chromeos/contacts/google_contact_store.h" | 5 #include "chrome/browser/chromeos/contacts/google_contact_store.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "chrome/browser/chromeos/contacts/contact.pb.h" | 12 #include "chrome/browser/chromeos/contacts/contact.pb.h" |
13 #include "chrome/browser/chromeos/contacts/contact_database.h" | 13 #include "chrome/browser/chromeos/contacts/contact_database.h" |
14 #include "chrome/browser/chromeos/contacts/contact_store_observer.h" | 14 #include "chrome/browser/chromeos/contacts/contact_store_observer.h" |
15 #include "chrome/browser/chromeos/gdata/gdata_contacts_service.h" | 15 #include "chrome/browser/chromeos/gdata/gdata_contacts_service.h" |
16 #include "chrome/browser/chromeos/gdata/gdata_system_service.h" | |
17 #include "chrome/browser/chromeos/gdata/gdata_util.h" | 16 #include "chrome/browser/chromeos/gdata/gdata_util.h" |
18 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
19 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
20 | 19 |
21 using content::BrowserThread; | 20 using content::BrowserThread; |
22 | 21 |
23 namespace contacts { | 22 namespace contacts { |
24 | 23 |
25 namespace { | 24 namespace { |
26 | 25 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 store_ = NULL; | 59 store_ = NULL; |
61 } | 60 } |
62 | 61 |
63 void GoogleContactStore::TestAPI::SetDatabase(ContactDatabaseInterface* db) { | 62 void GoogleContactStore::TestAPI::SetDatabase(ContactDatabaseInterface* db) { |
64 store_->DestroyDatabase(); | 63 store_->DestroyDatabase(); |
65 store_->db_ = db; | 64 store_->db_ = db; |
66 } | 65 } |
67 | 66 |
68 void GoogleContactStore::TestAPI::SetGDataService( | 67 void GoogleContactStore::TestAPI::SetGDataService( |
69 gdata::GDataContactsServiceInterface* service) { | 68 gdata::GDataContactsServiceInterface* service) { |
70 store_->gdata_service_for_testing_.reset(service); | 69 store_->gdata_service_.reset(service); |
71 } | 70 } |
72 | 71 |
73 void GoogleContactStore::TestAPI::DoUpdate() { | 72 void GoogleContactStore::TestAPI::DoUpdate() { |
74 store_->UpdateContacts(); | 73 store_->UpdateContacts(); |
75 } | 74 } |
76 | 75 |
77 void GoogleContactStore::TestAPI::NotifyAboutNetworkStateChange(bool online) { | 76 void GoogleContactStore::TestAPI::NotifyAboutNetworkStateChange(bool online) { |
78 net::NetworkChangeNotifier::ConnectionType type = | 77 net::NetworkChangeNotifier::ConnectionType type = |
79 online ? | 78 online ? |
80 net::NetworkChangeNotifier::CONNECTION_UNKNOWN : | 79 net::NetworkChangeNotifier::CONNECTION_UNKNOWN : |
(...skipping 17 matching lines...) Expand all Loading... |
98 | 97 |
99 GoogleContactStore::~GoogleContactStore() { | 98 GoogleContactStore::~GoogleContactStore() { |
100 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 99 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
101 weak_ptr_factory_.InvalidateWeakPtrs(); | 100 weak_ptr_factory_.InvalidateWeakPtrs(); |
102 net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this); | 101 net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this); |
103 DestroyDatabase(); | 102 DestroyDatabase(); |
104 } | 103 } |
105 | 104 |
106 void GoogleContactStore::Init() { | 105 void GoogleContactStore::Init() { |
107 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 106 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 107 |
| 108 // Create a GData service if one hasn't already been assigned for testing. |
| 109 if (!gdata_service_.get()) { |
| 110 gdata_service_.reset(new gdata::GDataContactsService(profile_)); |
| 111 gdata_service_->Initialize(); |
| 112 } |
| 113 |
108 FilePath db_path = profile_->GetPath().Append(kDatabaseDirectoryName); | 114 FilePath db_path = profile_->GetPath().Append(kDatabaseDirectoryName); |
109 VLOG(1) << "Initializing contact database \"" << db_path.value() << "\" for " | 115 VLOG(1) << "Initializing contact database \"" << db_path.value() << "\" for " |
110 << profile_->GetProfileName(); | 116 << profile_->GetProfileName(); |
111 db_->Init(db_path, | 117 db_->Init(db_path, |
112 base::Bind(&GoogleContactStore::OnDatabaseInitialized, | 118 base::Bind(&GoogleContactStore::OnDatabaseInitialized, |
113 weak_ptr_factory_.GetWeakPtr())); | 119 weak_ptr_factory_.GetWeakPtr())); |
114 } | 120 } |
115 | 121 |
116 void GoogleContactStore::AppendContacts(ContactPointers* contacts_out) { | 122 void GoogleContactStore::AppendContacts(ContactPointers* contacts_out) { |
117 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 123 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 last_contact_update_time_ + base::TimeDelta::FromMilliseconds(1); | 201 last_contact_update_time_ + base::TimeDelta::FromMilliseconds(1); |
196 } | 202 } |
197 if (min_update_time.is_null()) { | 203 if (min_update_time.is_null()) { |
198 VLOG(1) << "Downloading all contacts for " << profile_->GetProfileName(); | 204 VLOG(1) << "Downloading all contacts for " << profile_->GetProfileName(); |
199 } else { | 205 } else { |
200 VLOG(1) << "Downloading contacts updated since " | 206 VLOG(1) << "Downloading contacts updated since " |
201 << gdata::util::FormatTimeAsString(min_update_time) << " for " | 207 << gdata::util::FormatTimeAsString(min_update_time) << " for " |
202 << profile_->GetProfileName(); | 208 << profile_->GetProfileName(); |
203 } | 209 } |
204 | 210 |
205 gdata::GDataContactsServiceInterface* service = | 211 gdata_service_->DownloadContacts( |
206 gdata_service_for_testing_.get() ? | |
207 gdata_service_for_testing_.get() : | |
208 gdata::GDataSystemServiceFactory::GetForProfile(profile_)-> | |
209 contacts_service(); | |
210 DCHECK(service); | |
211 service->DownloadContacts( | |
212 base::Bind(&GoogleContactStore::OnDownloadSuccess, | 212 base::Bind(&GoogleContactStore::OnDownloadSuccess, |
213 weak_ptr_factory_.GetWeakPtr(), | 213 weak_ptr_factory_.GetWeakPtr(), |
214 min_update_time.is_null(), | 214 min_update_time.is_null(), |
215 GetCurrentTime()), | 215 GetCurrentTime()), |
216 base::Bind(&GoogleContactStore::OnDownloadFailure, | 216 base::Bind(&GoogleContactStore::OnDownloadFailure, |
217 weak_ptr_factory_.GetWeakPtr()), | 217 weak_ptr_factory_.GetWeakPtr()), |
218 min_update_time); | 218 min_update_time); |
219 } | 219 } |
220 | 220 |
221 void GoogleContactStore::ScheduleUpdate(bool last_update_was_successful) { | 221 void GoogleContactStore::ScheduleUpdate(bool last_update_was_successful) { |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 return gdata::util::IsGDataAvailable(profile); | 400 return gdata::util::IsGDataAvailable(profile); |
401 } | 401 } |
402 | 402 |
403 ContactStore* GoogleContactStoreFactory::CreateContactStore(Profile* profile) { | 403 ContactStore* GoogleContactStoreFactory::CreateContactStore(Profile* profile) { |
404 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 404 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
405 DCHECK(CanCreateContactStoreForProfile(profile)); | 405 DCHECK(CanCreateContactStoreForProfile(profile)); |
406 return new GoogleContactStore(profile); | 406 return new GoogleContactStore(profile); |
407 } | 407 } |
408 | 408 |
409 } // namespace contacts | 409 } // namespace contacts |
OLD | NEW |