summaryrefslogtreecommitdiffstats
path: root/components/suggestions
diff options
context:
space:
mode:
authortreib <treib@chromium.org>2015-12-22 09:33:47 -0800
committerCommit bot <commit-bot@chromium.org>2015-12-22 17:34:39 +0000
commitdc0ee77e63cafdd3377421c409a121404339ec66 (patch)
tree6d9fff11fe993cc25f2ec6f9ee98fed2b9831d94 /components/suggestions
parent2484f745164cd3254654fadf9811735eb823d14c (diff)
downloadchromium_src-dc0ee77e63cafdd3377421c409a121404339ec66.zip
chromium_src-dc0ee77e63cafdd3377421c409a121404339ec66.tar.gz
chromium_src-dc0ee77e63cafdd3377421c409a121404339ec66.tar.bz2
SuggestionsService: Temporarily disable OAuth2 authentication
BUG=555443 Review URL: https://codereview.chromium.org/1544773002 Cr-Commit-Position: refs/heads/master@{#366606}
Diffstat (limited to 'components/suggestions')
-rw-r--r--components/suggestions/suggestions_service.cc17
-rw-r--r--components/suggestions/suggestions_service.h6
-rw-r--r--components/suggestions/suggestions_service_unittest.cc14
3 files changed, 30 insertions, 7 deletions
diff --git a/components/suggestions/suggestions_service.cc b/components/suggestions/suggestions_service.cc
index 54e29ed..1f8c984 100644
--- a/components/suggestions/suggestions_service.cc
+++ b/components/suggestions/suggestions_service.cc
@@ -94,7 +94,7 @@ const char kPingURL[] =
"https://www.google.com/chromesuggestions/click?q=%lld&cd=%d";
const base::Feature kOAuth2AuthenticationFeature {
- "SuggestionsServiceOAuth2", base::FEATURE_ENABLED_BY_DEFAULT
+ "SuggestionsServiceOAuth2", base::FEATURE_DISABLED_BY_DEFAULT
};
} // namespace
@@ -322,7 +322,7 @@ void SuggestionsService::IssueRequestIfNoneOngoing(const GURL& url) {
if (pending_request_.get()) {
return;
}
- if (base::FeatureList::IsEnabled(kOAuth2AuthenticationFeature)) {
+ if (UseOAuth2()) {
// If there is an ongoing token request, also wait for that.
if (token_fetcher_->HasPendingRequest()) {
return;
@@ -336,11 +336,15 @@ void SuggestionsService::IssueRequestIfNoneOngoing(const GURL& url) {
}
}
+// static
+bool SuggestionsService::UseOAuth2() {
+ return base::FeatureList::IsEnabled(kOAuth2AuthenticationFeature);
+}
+
void SuggestionsService::IssueSuggestionsRequest(
const GURL& url,
const std::string& access_token) {
- if (base::FeatureList::IsEnabled(kOAuth2AuthenticationFeature) &&
- access_token.empty()) {
+ if (UseOAuth2() && access_token.empty()) {
UpdateBlacklistDelay(false);
ScheduleBlacklistUpload();
return;
@@ -357,7 +361,7 @@ scoped_ptr<net::URLFetcher> SuggestionsService::CreateSuggestionsRequest(
data_use_measurement::DataUseUserData::AttachToFetcher(
request.get(), data_use_measurement::DataUseUserData::SUGGESTIONS);
int load_flags = net::LOAD_DISABLE_CACHE;
- if (base::FeatureList::IsEnabled(kOAuth2AuthenticationFeature)) {
+ if (UseOAuth2()) {
load_flags |= net::LOAD_DO_NOT_SEND_COOKIES | net::LOAD_DO_NOT_SAVE_COOKIES;
}
request->SetLoadFlags(load_flags);
@@ -367,8 +371,7 @@ scoped_ptr<net::URLFetcher> SuggestionsService::CreateSuggestionsRequest(
variations::AppendVariationHeaders(request->GetOriginalURL(), false, false,
&headers);
request->SetExtraRequestHeaders(headers.ToString());
- if (base::FeatureList::IsEnabled(kOAuth2AuthenticationFeature) &&
- !access_token.empty()) {
+ if (UseOAuth2() && !access_token.empty()) {
request->AddExtraRequestHeader(
base::StringPrintf(kAuthorizationHeaderFormat, access_token.c_str()));
}
diff --git a/components/suggestions/suggestions_service.h b/components/suggestions/suggestions_service.h
index 0a2619c..076ca89 100644
--- a/components/suggestions/suggestions_service.h
+++ b/components/suggestions/suggestions_service.h
@@ -120,6 +120,8 @@ class SuggestionsService : public KeyedService, public net::URLFetcherDelegate {
private:
friend class SuggestionsServiceTest;
+ FRIEND_TEST_ALL_PREFIXES(SuggestionsServiceTest,
+ FetchSuggestionsDataNoAccessToken);
FRIEND_TEST_ALL_PREFIXES(SuggestionsServiceTest, BlacklistURL);
FRIEND_TEST_ALL_PREFIXES(SuggestionsServiceTest, BlacklistURLRequestFails);
FRIEND_TEST_ALL_PREFIXES(SuggestionsServiceTest, ClearBlacklist);
@@ -127,6 +129,10 @@ class SuggestionsService : public KeyedService, public net::URLFetcherDelegate {
FRIEND_TEST_ALL_PREFIXES(SuggestionsServiceTest, UndoBlacklistURLFailsHelper);
FRIEND_TEST_ALL_PREFIXES(SuggestionsServiceTest, UpdateBlacklistDelay);
+ // Returns whether OAuth2 authentication is enabled. If false, cookies are
+ // used for authentication.
+ static bool UseOAuth2();
+
// Issues a network request for suggestions (fetch, blacklist, or clear
// blacklist, depending on |url|). |access_token| is used only if OAuth2
// authentication is enabled.
diff --git a/components/suggestions/suggestions_service_unittest.cc b/components/suggestions/suggestions_service_unittest.cc
index f82a8c6..15b006f 100644
--- a/components/suggestions/suggestions_service_unittest.cc
+++ b/components/suggestions/suggestions_service_unittest.cc
@@ -6,8 +6,10 @@
#include <map>
#include <sstream>
+#include <utility>
#include "base/bind.h"
+#include "base/feature_list.h"
#include "base/memory/scoped_ptr.h"
#include "components/signin/core/browser/fake_profile_oauth2_token_service.h"
#include "components/suggestions/blacklist_store.h"
@@ -215,6 +217,16 @@ class SuggestionsServiceTest : public testing::Test {
~SuggestionsServiceTest() override {}
+ void SetOAuth2FeatureEnabled(bool enabled) {
+ base::FeatureList::ClearInstanceForTesting();
+ scoped_ptr<base::FeatureList> feature_list(new base::FeatureList);
+ if (enabled) {
+ feature_list->InitializeFromCommandLine(
+ "SuggestionsServiceOAuth2", std::string());
+ }
+ base::FeatureList::SetInstance(std::move(feature_list));
+ }
+
void SetUp() override {
request_context_ =
new net::TestURLRequestContextGetter(io_message_loop_.task_runner());
@@ -370,6 +382,8 @@ TEST_F(SuggestionsServiceTest, FetchSuggestionsDataSyncDisabled) {
}
TEST_F(SuggestionsServiceTest, FetchSuggestionsDataNoAccessToken) {
+ SetOAuth2FeatureEnabled(true);
+
token_service_.RevokeCredentials(kAccountId);
scoped_ptr<SuggestionsService> suggestions_service(