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

Unified Diff: chrome/browser/supervised_user/permission_request_creator_apiary.cc

Issue 614053002: Supervised Users: Add tests for PermissionRequestCreatorApiary. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/supervised_user/permission_request_creator_apiary.cc
diff --git a/chrome/browser/supervised_user/permission_request_creator_apiary.cc b/chrome/browser/supervised_user/permission_request_creator_apiary.cc
index d6ec4e801ab32b9d200d562cbf90030eb309a79d..f4cf110369af3fd539872ccc7f13386a4e7cd655 100644
--- a/chrome/browser/supervised_user/permission_request_creator_apiary.cc
+++ b/chrome/browser/supervised_user/permission_request_creator_apiary.cc
@@ -36,7 +36,9 @@ const char kState[] = "PENDING";
static const char kAuthorizationHeaderFormat[] = "Authorization: Bearer %s";
struct PermissionRequestCreatorApiary::Request {
- Request(const GURL& url_requested, const base::Closure& callback);
+ Request(const GURL& url_requested,
+ const base::Closure& callback,
+ int url_fetcher_id);
~Request();
GURL url_requested;
@@ -44,47 +46,58 @@ struct PermissionRequestCreatorApiary::Request {
scoped_ptr<OAuth2TokenService::Request> access_token_request;
std::string access_token;
bool access_token_expired;
+ int url_fetcher_id;
scoped_ptr<net::URLFetcher> url_fetcher;
};
PermissionRequestCreatorApiary::Request::Request(const GURL& url_requested,
- const base::Closure& callback)
+ const base::Closure& callback,
+ int url_fetcher_id)
: url_requested(url_requested),
callback(callback),
- access_token_expired(false) {
+ access_token_expired(false),
+ url_fetcher_id(url_fetcher_id) {
}
PermissionRequestCreatorApiary::Request::~Request() {}
PermissionRequestCreatorApiary::PermissionRequestCreatorApiary(
+ const GURL& api_url,
OAuth2TokenService* oauth2_token_service,
scoped_ptr<SupervisedUserSigninManagerWrapper> signin_wrapper,
net::URLRequestContextGetter* context)
: OAuth2TokenService::Consumer("permissions_creator"),
+ url_(api_url),
oauth2_token_service_(oauth2_token_service),
signin_wrapper_(signin_wrapper.Pass()),
- context_(context) {}
+ context_(context),
+ url_fetcher_id_(0) {
+ DCHECK(url_.is_valid());
+}
PermissionRequestCreatorApiary::~PermissionRequestCreatorApiary() {}
// static
scoped_ptr<PermissionRequestCreator>
-PermissionRequestCreatorApiary::CreateWithProfile(Profile* profile) {
+PermissionRequestCreatorApiary::CreateWithProfile(const GURL& api_url,
+ Profile* profile) {
ProfileOAuth2TokenService* token_service =
ProfileOAuth2TokenServiceFactory::GetForProfile(profile);
SigninManagerBase* signin = SigninManagerFactory::GetForProfile(profile);
scoped_ptr<SupervisedUserSigninManagerWrapper> signin_wrapper(
new SupervisedUserSigninManagerWrapper(profile, signin));
scoped_ptr<PermissionRequestCreator> creator(
- new PermissionRequestCreatorApiary(
- token_service, signin_wrapper.Pass(), profile->GetRequestContext()));
+ new PermissionRequestCreatorApiary(api_url,
+ token_service,
+ signin_wrapper.Pass(),
+ profile->GetRequestContext()));
return creator.Pass();
}
void PermissionRequestCreatorApiary::CreatePermissionRequest(
const GURL& url_requested,
const base::Closure& callback) {
- requests_.push_back(new Request(url_requested, callback));
+ requests_.push_back(new Request(url_requested, callback, url_fetcher_id_));
StartFetching(requests_.back());
}
@@ -117,11 +130,9 @@ void PermissionRequestCreatorApiary::OnGetTokenSuccess(
}
DCHECK(it != requests_.end());
(*it)->access_token = access_token;
- GURL url(CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
- switches::kPermissionRequestApiUrl));
- const int id = 0;
- (*it)->url_fetcher.reset(URLFetcher::Create(id, url, URLFetcher::POST, this));
+ (*it)->url_fetcher.reset(
+ URLFetcher::Create((*it)->url_fetcher_id, url_, URLFetcher::POST, this));
(*it)->url_fetcher->SetRequestContext(context_);
(*it)->url_fetcher->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES |

Powered by Google App Engine
This is Rietveld 408576698