[chromedriver] Don't evaluate document.readyState if we already know it is loading.
[chromium-blink-merge.git] / google_apis / gaia / oauth2_access_token_fetcher_immediate_error.h
blob0408debd9f207a3f1537e73c78cc0043dedb4fd2
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef GOOGLE_APIS_GAIA_OAUTH2_ACCESS_TOKEN_FETCHER_IMMEDIATE_ERROR_H_
6 #define GOOGLE_APIS_GAIA_OAUTH2_ACCESS_TOKEN_FETCHER_IMMEDIATE_ERROR_H_
8 #include "base/memory/ref_counted.h"
9 #include "google_apis/gaia/google_service_auth_error.h"
10 #include "google_apis/gaia/oauth2_access_token_consumer.h"
11 #include "google_apis/gaia/oauth2_access_token_fetcher.h"
13 // This is an implementation of the OAuth2 fetcher that immediately returns
14 // an error. This is useful as a replacement to a real fetcher when a
15 // immediate error has previously been seen.
17 // This class should be used on a single thread, but it can be whichever thread
18 // that you like.
19 // Also, do not reuse the same instance. Once Start() is called, the instance
20 // should not be reused.
22 // Usage:
23 // * Create an instance with a consumer.
24 // * Call Start()
25 // * The consumer passed in the constructor will be called on the same
26 // thread Start was called with the results.
28 // This class can handle one request at a time. To parallelize requests,
29 // create multiple instances.
30 class OAuth2AccessTokenFetcherImmediateError : public OAuth2AccessTokenFetcher {
31 public:
32 OAuth2AccessTokenFetcherImmediateError(OAuth2AccessTokenConsumer* consumer,
33 const GoogleServiceAuthError& error);
34 ~OAuth2AccessTokenFetcherImmediateError() override;
36 void Start(const std::string& client_id,
37 const std::string& client_secret,
38 const std::vector<std::string>& scopes) override;
40 void CancelRequest() override;
42 private:
43 class FailCaller : public base::RefCounted<FailCaller> {
44 public:
45 FailCaller(OAuth2AccessTokenFetcherImmediateError* fetcher);
47 void run();
48 void detach();
50 private:
51 friend class base::RefCounted<FailCaller>;
52 ~FailCaller();
54 OAuth2AccessTokenFetcherImmediateError* fetcher_;
57 void Fail();
59 scoped_refptr<FailCaller> failer_;
60 GoogleServiceAuthError immediate_error_;
61 DISALLOW_COPY_AND_ASSIGN(OAuth2AccessTokenFetcherImmediateError);
64 #endif // GOOGLE_APIS_GAIA_OAUTH2_ACCESS_TOKEN_FETCHER_IMMEDIATE_ERROR_H_