Revert "Reland c91b178b07b0d - Delete dead signin code (SigninGlobalError)"
[chromium-blink-merge.git] / chrome / browser / local_discovery / gcd_api_flow.h
blob6892a2c1bb8d6020531a650422f731dc70430f21
1 // Copyright 2014 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 CHROME_BROWSER_LOCAL_DISCOVERY_GCD_API_FLOW_H_
6 #define CHROME_BROWSER_LOCAL_DISCOVERY_GCD_API_FLOW_H_
8 #include <string>
10 #include "google_apis/gaia/oauth2_token_service.h"
11 #include "net/url_request/url_fetcher.h"
12 #include "net/url_request/url_request_context_getter.h"
14 namespace local_discovery {
16 // API flow for communicating with cloud print and cloud devices.
17 class GCDApiFlow {
18 public:
19 // TODO(noamsml): Better error model for this class.
20 enum Status {
21 SUCCESS,
22 ERROR_TOKEN,
23 ERROR_NETWORK,
24 ERROR_HTTP_CODE,
25 ERROR_FROM_SERVER,
26 ERROR_MALFORMED_RESPONSE
29 // Provides GCDApiFlowImpl with parameters required to make request.
30 // Parses results of requests.
31 class Request {
32 public:
33 Request();
34 virtual ~Request();
36 virtual void OnGCDAPIFlowError(Status status) = 0;
38 virtual void OnGCDAPIFlowComplete(const base::DictionaryValue& value) = 0;
40 virtual GURL GetURL() = 0;
42 virtual std::string GetOAuthScope() = 0;
44 virtual net::URLFetcher::RequestType GetRequestType();
46 virtual std::vector<std::string> GetExtraRequestHeaders() = 0;
48 // If there is no data, set upload_type and upload_data to ""
49 virtual void GetUploadData(std::string* upload_type,
50 std::string* upload_data);
52 private:
53 DISALLOW_COPY_AND_ASSIGN(Request);
56 GCDApiFlow();
57 virtual ~GCDApiFlow();
59 static scoped_ptr<GCDApiFlow> Create(
60 net::URLRequestContextGetter* request_context,
61 OAuth2TokenService* token_service,
62 const std::string& account_id);
64 virtual void Start(scoped_ptr<Request> request) = 0;
66 private:
67 DISALLOW_COPY_AND_ASSIGN(GCDApiFlow);
70 class GCDApiFlowRequest : public GCDApiFlow::Request {
71 public:
72 GCDApiFlowRequest();
73 ~GCDApiFlowRequest() override;
75 // GCDApiFlowRequest implementation
76 std::string GetOAuthScope() override;
77 std::vector<std::string> GetExtraRequestHeaders() override;
79 private:
80 DISALLOW_COPY_AND_ASSIGN(GCDApiFlowRequest);
83 class CloudPrintApiFlowRequest : public GCDApiFlow::Request {
84 public:
85 CloudPrintApiFlowRequest();
86 ~CloudPrintApiFlowRequest() override;
88 // GCDApiFlowRequest implementation
89 std::string GetOAuthScope() override;
90 std::vector<std::string> GetExtraRequestHeaders() override;
92 private:
93 DISALLOW_COPY_AND_ASSIGN(CloudPrintApiFlowRequest);
96 } // namespace local_discovery
98 #endif // CHROME_BROWSER_LOCAL_DISCOVERY_GCD_API_FLOW_H_