summaryrefslogtreecommitdiffstats
path: root/chrome/browser/chromeos/contacts
diff options
context:
space:
mode:
authorkinaba@chromium.org <kinaba@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-07-17 17:22:48 +0000
committerkinaba@chromium.org <kinaba@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-07-17 17:22:48 +0000
commit729216215054fe4b08839ae46cf0e481e1423eb9 (patch)
tree069092f0048ea3f86d93bdc89755f4e56e573869 /chrome/browser/chromeos/contacts
parent6af7258ad10b23fb59182aad210ead6a56176755 (diff)
downloadchromium_src-729216215054fe4b08839ae46cf0e481e1423eb9.zip
chromium_src-729216215054fe4b08839ae46cf0e481e1423eb9.tar.gz
chromium_src-729216215054fe4b08839ae46cf0e481e1423eb9.tar.bz2
Change google_api::RequestSender to take an AuthService instead of a Profile.
This way, we can plug-in a dummy instance of AuthService in tests, and then * We can remove TestingProfile completely from c/b/google_apis/. * Several for_testing() methods can be removed. * Switching the internals of AuthService to OAuth2TokenService (162157) gets more smooth, since tests for request classes are completely separated from AuthService. BUG=162157 Review URL: https://chromiumcodereview.appspot.com/19511002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@212079 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/chromeos/contacts')
-rw-r--r--chrome/browser/chromeos/contacts/gdata_contacts_service.cc19
-rw-r--r--chrome/browser/chromeos/contacts/gdata_contacts_service.h9
-rw-r--r--chrome/browser/chromeos/contacts/gdata_contacts_service_stub.cc3
-rw-r--r--chrome/browser/chromeos/contacts/gdata_contacts_service_stub.h1
-rw-r--r--chrome/browser/chromeos/contacts/gdata_contacts_service_unittest.cc11
-rw-r--r--chrome/browser/chromeos/contacts/google_contact_store.cc11
6 files changed, 15 insertions, 39 deletions
diff --git a/chrome/browser/chromeos/contacts/gdata_contacts_service.cc b/chrome/browser/chromeos/contacts/gdata_contacts_service.cc
index d95f66d..baffae3 100644
--- a/chrome/browser/chromeos/contacts/gdata_contacts_service.cc
+++ b/chrome/browser/chromeos/contacts/gdata_contacts_service.cc
@@ -146,9 +146,6 @@ const char kLinkETagField[] = "gd$etag";
const char kLinkRelPhotoValue[] =
"http://schemas.google.com/contacts/2008/rel#photo";
-// OAuth2 scope for the Contacts API.
-const char kContactsScope[] = "https://www.google.com/m8/feeds/";
-
// Returns a string containing a pretty-printed JSON representation of |value|.
std::string PrettyPrintValue(const base::Value& value) {
std::string out;
@@ -851,17 +848,14 @@ class GDataContactsService::DownloadContactsRequest {
GDataContactsService::GDataContactsService(
net::URLRequestContextGetter* url_request_context_getter,
- Profile* profile)
+ google_apis::AuthServiceInterface* auth_service)
: max_photo_downloads_per_second_(kMaxPhotoDownloadsPerSecond),
photo_download_timer_interval_(base::TimeDelta::FromSeconds(1)) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- std::vector<std::string> scopes;
- scopes.push_back(kContactsScope);
sender_.reset(new google_apis::RequestSender(
- profile,
+ auth_service,
url_request_context_getter,
content::BrowserThread::GetBlockingPool(),
- scopes,
"" /* custom_user_agent */));
}
@@ -871,15 +865,6 @@ GDataContactsService::~GDataContactsService() {
requests_.clear();
}
-google_apis::AuthService* GDataContactsService::auth_service_for_testing() {
- return sender_->auth_service();
-}
-
-void GDataContactsService::Initialize() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- sender_->Initialize();
-}
-
void GDataContactsService::DownloadContacts(SuccessCallback success_callback,
FailureCallback failure_callback,
const base::Time& min_update_time) {
diff --git a/chrome/browser/chromeos/contacts/gdata_contacts_service.h b/chrome/browser/chromeos/contacts/gdata_contacts_service.h
index 36b61d1..d41fa25 100644
--- a/chrome/browser/chromeos/contacts/gdata_contacts_service.h
+++ b/chrome/browser/chromeos/contacts/gdata_contacts_service.h
@@ -23,7 +23,7 @@ class Value;
} // namespace base
namespace google_apis {
-class AuthService;
+class AuthServiceInterface;
class RequestSender;
} // namespace google_apis
@@ -45,8 +45,6 @@ class GDataContactsServiceInterface {
virtual ~GDataContactsServiceInterface() {}
- virtual void Initialize() = 0;
-
// Downloads all contacts changed at or after |min_update_time| and invokes
// the appropriate callback asynchronously on the UI thread when complete. If
// min_update_time.is_null() is true, all contacts will be returned.
@@ -68,11 +66,9 @@ class GDataContactsService : public GDataContactsServiceInterface {
GDataContactsService(
net::URLRequestContextGetter* url_request_context_getter,
- Profile* profile);
+ google_apis::AuthServiceInterface* auth_service);
virtual ~GDataContactsService();
- google_apis::AuthService* auth_service_for_testing();
-
const std::string& cached_my_contacts_group_id_for_testing() const {
return cached_my_contacts_group_id_;
}
@@ -97,7 +93,6 @@ class GDataContactsService : public GDataContactsServiceInterface {
}
// Overridden from GDataContactsServiceInterface:
- virtual void Initialize() OVERRIDE;
virtual void DownloadContacts(SuccessCallback success_callback,
FailureCallback failure_callback,
const base::Time& min_update_time) OVERRIDE;
diff --git a/chrome/browser/chromeos/contacts/gdata_contacts_service_stub.cc b/chrome/browser/chromeos/contacts/gdata_contacts_service_stub.cc
index eccd252..bc29536 100644
--- a/chrome/browser/chromeos/contacts/gdata_contacts_service_stub.cc
+++ b/chrome/browser/chromeos/contacts/gdata_contacts_service_stub.cc
@@ -31,9 +31,6 @@ void GDataContactsServiceStub::SetContacts(
expected_min_update_time_ = expected_min_update_time;
}
-void GDataContactsServiceStub::Initialize() {
-}
-
void GDataContactsServiceStub::DownloadContacts(
SuccessCallback success_callback,
FailureCallback failure_callback,
diff --git a/chrome/browser/chromeos/contacts/gdata_contacts_service_stub.h b/chrome/browser/chromeos/contacts/gdata_contacts_service_stub.h
index 0be0213..7db2381 100644
--- a/chrome/browser/chromeos/contacts/gdata_contacts_service_stub.h
+++ b/chrome/browser/chromeos/contacts/gdata_contacts_service_stub.h
@@ -39,7 +39,6 @@ class GDataContactsServiceStub : public GDataContactsServiceInterface {
const base::Time& expected_min_update_time);
// Overridden from GDataContactsServiceInterface:
- virtual void Initialize() OVERRIDE;
virtual void DownloadContacts(SuccessCallback success_callback,
FailureCallback failure_callback,
const base::Time& min_update_time) OVERRIDE;
diff --git a/chrome/browser/chromeos/contacts/gdata_contacts_service_unittest.cc b/chrome/browser/chromeos/contacts/gdata_contacts_service_unittest.cc
index ac43ff8..51ba956 100644
--- a/chrome/browser/chromeos/contacts/gdata_contacts_service_unittest.cc
+++ b/chrome/browser/chromeos/contacts/gdata_contacts_service_unittest.cc
@@ -11,13 +11,11 @@
#include "base/time/time.h"
#include "chrome/browser/chromeos/contacts/contact.pb.h"
#include "chrome/browser/chromeos/contacts/contact_test_util.h"
-#include "chrome/browser/google_apis/auth_service.h"
+#include "chrome/browser/google_apis/dummy_auth_service.h"
#include "chrome/browser/google_apis/test_util.h"
#include "chrome/browser/google_apis/time_util.h"
-#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/test/base/in_process_browser_test.h"
-#include "chrome/test/base/testing_profile.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/test/test_browser_thread.h"
#include "content/public/test/test_utils.h"
@@ -78,7 +76,6 @@ class GDataContactsServiceTest : public testing::Test {
virtual void SetUp() OVERRIDE {
io_thread_.StartIOThread();
- profile_.reset(new TestingProfile);
request_context_getter_ = new net::TestURLRequestContextGetter(
content::BrowserThread::GetMessageLoopProxyForThread(
content::BrowserThread::IO));
@@ -92,10 +89,7 @@ class GDataContactsServiceTest : public testing::Test {
base::Bind(&GDataContactsServiceTest::HandleDownloadRequest,
base::Unretained(this)));
service_.reset(new GDataContactsService(request_context_getter_.get(),
- profile_.get()));
- service_->Initialize();
- service_->auth_service_for_testing()->set_access_token_for_testing(
- kTestGDataAuthToken);
+ new google_apis::DummyAuthService));
service_->set_rewrite_photo_url_callback_for_testing(
base::Bind(&GDataContactsServiceTest::RewritePhotoUrl,
base::Unretained(this)));
@@ -176,7 +170,6 @@ class GDataContactsServiceTest : public testing::Test {
base::MessageLoopForUI message_loop_;
content::TestBrowserThread ui_thread_;
content::TestBrowserThread io_thread_;
- scoped_ptr<TestingProfile> profile_;
scoped_refptr<net::TestURLRequestContextGetter> request_context_getter_;
// Was the last download successful? Used to pass the result back from
diff --git a/chrome/browser/chromeos/contacts/google_contact_store.cc b/chrome/browser/chromeos/contacts/google_contact_store.cc
index f5765bf9d..d788ff6 100644
--- a/chrome/browser/chromeos/contacts/google_contact_store.cc
+++ b/chrome/browser/chromeos/contacts/google_contact_store.cc
@@ -50,6 +50,9 @@ const int kUpdateFailureInitialRetrySec = 5;
// Amount by which |update_delay_on_next_failure_| is multiplied on failure.
const int kUpdateFailureBackoffFactor = 2;
+// OAuth2 scope for the Contacts API.
+const char kContactsScope[] = "https://www.google.com/m8/feeds/";
+
} // namespace
GoogleContactStore::TestAPI::TestAPI(GoogleContactStore* store)
@@ -120,9 +123,13 @@ void GoogleContactStore::Init() {
// Create a GData service if one hasn't already been assigned for testing.
if (!gdata_service_.get()) {
+ std::vector<std::string> scopes;
+ scopes.push_back(kContactsScope);
+
gdata_service_.reset(new GDataContactsService(
- url_request_context_getter_, profile_));
- gdata_service_->Initialize();
+ url_request_context_getter_,
+ new google_apis::AuthService(
+ profile_, url_request_context_getter_, scopes)));
}
base::FilePath db_path = profile_->GetPath().Append(kDatabaseDirectoryName);