easy_unlock_toggle_flow.h revision 6e8cce623b6e4fe0c9e4af605d675dd9d0338c38
16e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved.
26e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
36e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)// found in the LICENSE file.
46e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
56e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#ifndef CHROME_BROWSER_SIGNIN_EASY_UNLOCK_TOGGLE_FLOW_H_
66e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#define CHROME_BROWSER_SIGNIN_EASY_UNLOCK_TOGGLE_FLOW_H_
76e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
86e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include <string>
96e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include <vector>
106e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
116e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "base/callback.h"
126e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "base/macros.h"
136e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "base/memory/scoped_ptr.h"
146e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "google_apis/gaia/google_service_auth_error.h"
156e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "google_apis/gaia/oauth2_mint_token_flow.h"
166e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "google_apis/gaia/oauth2_token_service.h"
176e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
186e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)class Profile;
196e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
206e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)class EasyUnlockToggleFlow : public OAuth2TokenService::Consumer,
216e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)                             public OAuth2MintTokenFlow::Delegate {
226e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) public:
236e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // Callback to indicate whether the call succeeds or not.
246e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  typedef base::Callback<void(bool)> ToggleFlowCallback;
256e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
266e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  EasyUnlockToggleFlow(Profile* profile,
276e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)                       const std::string& phone_public_key,
286e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)                       bool toggle_enable,
296e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)                       const ToggleFlowCallback& callback);
306e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  virtual ~EasyUnlockToggleFlow();
316e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
326e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  void Start();
336e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
346e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // OAuth2TokenService::Consumer
356e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  virtual void OnGetTokenSuccess(const OAuth2TokenService::Request* request,
366e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)                                 const std::string& access_token,
376e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)                                 const base::Time& expiration_time) OVERRIDE;
386e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  virtual void OnGetTokenFailure(const OAuth2TokenService::Request* request,
396e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)                                 const GoogleServiceAuthError& error) OVERRIDE;
406e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
416e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // OAuth2MintTokenFlow::Delegate
426e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  virtual void OnMintTokenSuccess(const std::string& access_token,
436e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)                                  int time_to_live) OVERRIDE;
446e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  virtual void OnMintTokenFailure(
456e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)      const GoogleServiceAuthError& error) OVERRIDE;
466e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  virtual void OnIssueAdviceSuccess(
476e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)      const IssueAdviceInfo& issue_advice) OVERRIDE;
486e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
496e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) private:
506e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // Derived OAuth2ApiCallFlow class to make toggle api call after access token
516e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // is available.
526e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  class ToggleApiCall;
536e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
546e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // Callbacks from ToggleApiCall
556e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  void ReportToggleApiCallResult(bool success);
566e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
576e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  Profile* profile_;
586e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  const std::string phone_public_key_;
596e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  const bool toggle_enable_;
606e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  ToggleFlowCallback callback_;
616e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
626e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  scoped_ptr<OAuth2TokenService::Request> token_request_;
636e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  scoped_ptr<OAuth2MintTokenFlow> mint_token_flow_;
646e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  scoped_ptr<ToggleApiCall> toggle_api_call_;
656e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
666e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(EasyUnlockToggleFlow);
676e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)};
686e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
696e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#endif  // CHROME_BROWSER_SIGNIN_EASY_UNLOCK_TOGGLE_FLOW_H_
70