| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_LOCAL_DISCOVERY_GCD_API_FLOW_H_ | |
| 6 #define CHROME_BROWSER_LOCAL_DISCOVERY_GCD_API_FLOW_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 | |
| 10 #include "base/macros.h" | |
| 11 #include "google_apis/gaia/oauth2_token_service.h" | |
| 12 #include "net/url_request/url_fetcher.h" | |
| 13 #include "net/url_request/url_request_context_getter.h" | |
| 14 | |
| 15 namespace local_discovery { | |
| 16 | |
| 17 // API flow for communicating with cloud print and cloud devices. | |
| 18 class GCDApiFlow { | |
| 19 public: | |
| 20 // TODO(noamsml): Better error model for this class. | |
| 21 enum Status { | |
| 22 SUCCESS, | |
| 23 ERROR_TOKEN, | |
| 24 ERROR_NETWORK, | |
| 25 ERROR_HTTP_CODE, | |
| 26 ERROR_FROM_SERVER, | |
| 27 ERROR_MALFORMED_RESPONSE | |
| 28 }; | |
| 29 | |
| 30 // Provides GCDApiFlowImpl with parameters required to make request. | |
| 31 // Parses results of requests. | |
| 32 class Request { | |
| 33 public: | |
| 34 Request(); | |
| 35 virtual ~Request(); | |
| 36 | |
| 37 virtual void OnGCDAPIFlowError(Status status) = 0; | |
| 38 | |
| 39 virtual void OnGCDAPIFlowComplete(const base::DictionaryValue& value) = 0; | |
| 40 | |
| 41 virtual GURL GetURL() = 0; | |
| 42 | |
| 43 virtual std::string GetOAuthScope() = 0; | |
| 44 | |
| 45 virtual net::URLFetcher::RequestType GetRequestType(); | |
| 46 | |
| 47 virtual std::vector<std::string> GetExtraRequestHeaders() = 0; | |
| 48 | |
| 49 // If there is no data, set upload_type and upload_data to "" | |
| 50 virtual void GetUploadData(std::string* upload_type, | |
| 51 std::string* upload_data); | |
| 52 | |
| 53 private: | |
| 54 DISALLOW_COPY_AND_ASSIGN(Request); | |
| 55 }; | |
| 56 | |
| 57 GCDApiFlow(); | |
| 58 virtual ~GCDApiFlow(); | |
| 59 | |
| 60 static scoped_ptr<GCDApiFlow> Create( | |
| 61 net::URLRequestContextGetter* request_context, | |
| 62 OAuth2TokenService* token_service, | |
| 63 const std::string& account_id); | |
| 64 | |
| 65 virtual void Start(scoped_ptr<Request> request) = 0; | |
| 66 | |
| 67 private: | |
| 68 DISALLOW_COPY_AND_ASSIGN(GCDApiFlow); | |
| 69 }; | |
| 70 | |
| 71 class GCDApiFlowRequest : public GCDApiFlow::Request { | |
| 72 public: | |
| 73 GCDApiFlowRequest(); | |
| 74 ~GCDApiFlowRequest() override; | |
| 75 | |
| 76 // GCDApiFlowRequest implementation | |
| 77 std::string GetOAuthScope() override; | |
| 78 std::vector<std::string> GetExtraRequestHeaders() override; | |
| 79 | |
| 80 private: | |
| 81 DISALLOW_COPY_AND_ASSIGN(GCDApiFlowRequest); | |
| 82 }; | |
| 83 | |
| 84 class CloudPrintApiFlowRequest : public GCDApiFlow::Request { | |
| 85 public: | |
| 86 CloudPrintApiFlowRequest(); | |
| 87 ~CloudPrintApiFlowRequest() override; | |
| 88 | |
| 89 // GCDApiFlowRequest implementation | |
| 90 std::string GetOAuthScope() override; | |
| 91 std::vector<std::string> GetExtraRequestHeaders() override; | |
| 92 | |
| 93 private: | |
| 94 DISALLOW_COPY_AND_ASSIGN(CloudPrintApiFlowRequest); | |
| 95 }; | |
| 96 | |
| 97 } // namespace local_discovery | |
| 98 | |
| 99 #endif // CHROME_BROWSER_LOCAL_DISCOVERY_GCD_API_FLOW_H_ | |
| OLD | NEW |