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

Side by Side Diff: chrome/browser/chromeos/contacts/google_contact_store.cc

Issue 11620007: Switch from OnIPAddressChanged and OnConnectionTypeChange to OnNetworkChanged Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 11 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 #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"
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 73
74 void GoogleContactStore::TestAPI::DoUpdate() { 74 void GoogleContactStore::TestAPI::DoUpdate() {
75 store_->UpdateContacts(); 75 store_->UpdateContacts();
76 } 76 }
77 77
78 void GoogleContactStore::TestAPI::NotifyAboutNetworkStateChange(bool online) { 78 void GoogleContactStore::TestAPI::NotifyAboutNetworkStateChange(bool online) {
79 net::NetworkChangeNotifier::ConnectionType type = 79 net::NetworkChangeNotifier::ConnectionType type =
80 online ? 80 online ?
81 net::NetworkChangeNotifier::CONNECTION_UNKNOWN : 81 net::NetworkChangeNotifier::CONNECTION_UNKNOWN :
82 net::NetworkChangeNotifier::CONNECTION_NONE; 82 net::NetworkChangeNotifier::CONNECTION_NONE;
83 store_->OnConnectionTypeChanged(type); 83 store_->OnNetworkChanged(type);
84 } 84 }
85 85
86 scoped_ptr<ContactPointers> GoogleContactStore::TestAPI::GetLoadedContacts() { 86 scoped_ptr<ContactPointers> GoogleContactStore::TestAPI::GetLoadedContacts() {
87 scoped_ptr<ContactPointers> contacts(new ContactPointers); 87 scoped_ptr<ContactPointers> contacts(new ContactPointers);
88 for (ContactMap::const_iterator it = store_->contacts_.begin(); 88 for (ContactMap::const_iterator it = store_->contacts_.begin();
89 it != store_->contacts_.end(); ++it) { 89 it != store_->contacts_.end(); ++it) {
90 contacts->push_back(it->second); 90 contacts->push_back(it->second);
91 } 91 }
92 return contacts.Pass(); 92 return contacts.Pass();
93 } 93 }
94 94
95 GoogleContactStore::GoogleContactStore( 95 GoogleContactStore::GoogleContactStore(
96 net::URLRequestContextGetter* url_request_context_getter, 96 net::URLRequestContextGetter* url_request_context_getter,
97 Profile* profile) 97 Profile* profile)
98 : url_request_context_getter_(url_request_context_getter), 98 : url_request_context_getter_(url_request_context_getter),
99 profile_(profile), 99 profile_(profile),
100 db_(new ContactDatabase), 100 db_(new ContactDatabase),
101 update_delay_on_next_failure_( 101 update_delay_on_next_failure_(
102 base::TimeDelta::FromSeconds(kUpdateFailureInitialRetrySec)), 102 base::TimeDelta::FromSeconds(kUpdateFailureInitialRetrySec)),
103 is_online_(true), 103 is_online_(true),
104 should_update_when_online_(false), 104 should_update_when_online_(false),
105 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { 105 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {
106 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 106 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
107 net::NetworkChangeNotifier::AddConnectionTypeObserver(this); 107 net::NetworkChangeNotifier::AddNetworkChangeObserver(this);
108 is_online_ = !net::NetworkChangeNotifier::IsOffline(); 108 is_online_ = !net::NetworkChangeNotifier::IsOffline();
109 } 109 }
110 110
111 GoogleContactStore::~GoogleContactStore() { 111 GoogleContactStore::~GoogleContactStore() {
112 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 112 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
113 weak_ptr_factory_.InvalidateWeakPtrs(); 113 weak_ptr_factory_.InvalidateWeakPtrs();
114 net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this); 114 net::NetworkChangeNotifier::RemoveNetworkChangeObserver(this);
115 DestroyDatabase(); 115 DestroyDatabase();
116 } 116 }
117 117
118 void GoogleContactStore::Init() { 118 void GoogleContactStore::Init() {
119 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 119 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
120 120
121 // Create a GData service if one hasn't already been assigned for testing. 121 // Create a GData service if one hasn't already been assigned for testing.
122 if (!gdata_service_.get()) { 122 if (!gdata_service_.get()) {
123 gdata_service_.reset(new GDataContactsService( 123 gdata_service_.reset(new GDataContactsService(
124 url_request_context_getter_, profile_)); 124 url_request_context_getter_, profile_));
(...skipping 29 matching lines...) Expand all
154 DCHECK(observer); 154 DCHECK(observer);
155 observers_.AddObserver(observer); 155 observers_.AddObserver(observer);
156 } 156 }
157 157
158 void GoogleContactStore::RemoveObserver(ContactStoreObserver* observer) { 158 void GoogleContactStore::RemoveObserver(ContactStoreObserver* observer) {
159 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 159 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
160 DCHECK(observer); 160 DCHECK(observer);
161 observers_.RemoveObserver(observer); 161 observers_.RemoveObserver(observer);
162 } 162 }
163 163
164 void GoogleContactStore::OnConnectionTypeChanged( 164 void GoogleContactStore::OnNetworkChanged(
165 net::NetworkChangeNotifier::ConnectionType type) { 165 net::NetworkChangeNotifier::ConnectionType type) {
166 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 166 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
167 bool was_online = is_online_; 167 bool was_online = is_online_;
168 is_online_ = (type != net::NetworkChangeNotifier::CONNECTION_NONE); 168 is_online_ = (type != net::NetworkChangeNotifier::CONNECTION_NONE);
169 if (!was_online && is_online_ && should_update_when_online_) { 169 if (!was_online && is_online_ && should_update_when_online_) {
szym 2013/01/20 06:52:08 The logic here is: "if it's a change from offline
Daniel Erat 2013/01/20 14:21:14 I think that this is okay; I assume that it'll jus
170 should_update_when_online_ = false; 170 should_update_when_online_ = false;
171 UpdateContacts(); 171 UpdateContacts();
172 } 172 }
173 } 173 }
174 174
175 base::Time GoogleContactStore::GetCurrentTime() const { 175 base::Time GoogleContactStore::GetCurrentTime() const {
176 return !current_time_for_testing_.is_null() ? 176 return !current_time_for_testing_.is_null() ?
177 current_time_for_testing_ : 177 current_time_for_testing_ :
178 base::Time::Now(); 178 base::Time::Now();
179 } 179 }
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 } 409 }
410 410
411 ContactStore* GoogleContactStoreFactory::CreateContactStore(Profile* profile) { 411 ContactStore* GoogleContactStoreFactory::CreateContactStore(Profile* profile) {
412 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 412 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
413 DCHECK(CanCreateContactStoreForProfile(profile)); 413 DCHECK(CanCreateContactStoreForProfile(profile));
414 return new GoogleContactStore( 414 return new GoogleContactStore(
415 g_browser_process->system_request_context(), profile); 415 g_browser_process->system_request_context(), profile);
416 } 416 }
417 417
418 } // namespace contacts 418 } // namespace contacts
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698