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/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 // daylight saving time shenanigans or minor skew in the system clock. | 43 // daylight saving time shenanigans or minor skew in the system clock. |
44 const int kForceFullUpdateDays = 29; | 44 const int kForceFullUpdateDays = 29; |
45 | 45 |
46 // When an update fails, we initially wait this many seconds before retrying. | 46 // When an update fails, we initially wait this many seconds before retrying. |
47 // The delay increases exponentially in response to repeated failures. | 47 // The delay increases exponentially in response to repeated failures. |
48 const int kUpdateFailureInitialRetrySec = 5; | 48 const int kUpdateFailureInitialRetrySec = 5; |
49 | 49 |
50 // Amount by which |update_delay_on_next_failure_| is multiplied on failure. | 50 // Amount by which |update_delay_on_next_failure_| is multiplied on failure. |
51 const int kUpdateFailureBackoffFactor = 2; | 51 const int kUpdateFailureBackoffFactor = 2; |
52 | 52 |
| 53 // OAuth2 scope for the Contacts API. |
| 54 const char kContactsScope[] = "https://www.google.com/m8/feeds/"; |
| 55 |
53 } // namespace | 56 } // namespace |
54 | 57 |
55 GoogleContactStore::TestAPI::TestAPI(GoogleContactStore* store) | 58 GoogleContactStore::TestAPI::TestAPI(GoogleContactStore* store) |
56 : store_(store) { | 59 : store_(store) { |
57 DCHECK(store); | 60 DCHECK(store); |
58 } | 61 } |
59 | 62 |
60 GoogleContactStore::TestAPI::~TestAPI() { | 63 GoogleContactStore::TestAPI::~TestAPI() { |
61 store_ = NULL; | 64 store_ = NULL; |
62 } | 65 } |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 weak_ptr_factory_.InvalidateWeakPtrs(); | 116 weak_ptr_factory_.InvalidateWeakPtrs(); |
114 net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this); | 117 net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this); |
115 DestroyDatabase(); | 118 DestroyDatabase(); |
116 } | 119 } |
117 | 120 |
118 void GoogleContactStore::Init() { | 121 void GoogleContactStore::Init() { |
119 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 122 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
120 | 123 |
121 // Create a GData service if one hasn't already been assigned for testing. | 124 // Create a GData service if one hasn't already been assigned for testing. |
122 if (!gdata_service_.get()) { | 125 if (!gdata_service_.get()) { |
| 126 std::vector<std::string> scopes; |
| 127 scopes.push_back(kContactsScope); |
| 128 |
123 gdata_service_.reset(new GDataContactsService( | 129 gdata_service_.reset(new GDataContactsService( |
124 url_request_context_getter_, profile_)); | 130 url_request_context_getter_, |
125 gdata_service_->Initialize(); | 131 new google_apis::AuthService( |
| 132 profile_, url_request_context_getter_, scopes))); |
126 } | 133 } |
127 | 134 |
128 base::FilePath db_path = profile_->GetPath().Append(kDatabaseDirectoryName); | 135 base::FilePath db_path = profile_->GetPath().Append(kDatabaseDirectoryName); |
129 VLOG(1) << "Initializing contact database \"" << db_path.value() << "\" for " | 136 VLOG(1) << "Initializing contact database \"" << db_path.value() << "\" for " |
130 << profile_->GetProfileName(); | 137 << profile_->GetProfileName(); |
131 db_->Init(db_path, | 138 db_->Init(db_path, |
132 base::Bind(&GoogleContactStore::OnDatabaseInitialized, | 139 base::Bind(&GoogleContactStore::OnDatabaseInitialized, |
133 weak_ptr_factory_.GetWeakPtr())); | 140 weak_ptr_factory_.GetWeakPtr())); |
134 } | 141 } |
135 | 142 |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 } | 414 } |
408 | 415 |
409 ContactStore* GoogleContactStoreFactory::CreateContactStore(Profile* profile) { | 416 ContactStore* GoogleContactStoreFactory::CreateContactStore(Profile* profile) { |
410 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 417 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
411 DCHECK(CanCreateContactStoreForProfile(profile)); | 418 DCHECK(CanCreateContactStoreForProfile(profile)); |
412 return new GoogleContactStore( | 419 return new GoogleContactStore( |
413 g_browser_process->system_request_context(), profile); | 420 g_browser_process->system_request_context(), profile); |
414 } | 421 } |
415 | 422 |
416 } // namespace contacts | 423 } // namespace contacts |
OLD | NEW |