1 // Copyright (c) 2011 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_REMOTING_DIRECTORY_ADD_REQUEST_H_ 6 #define CHROME_BROWSER_REMOTING_DIRECTORY_ADD_REQUEST_H_ 7 8 #include <string> 9 10 #include "base/callback.h" 11 #include "base/memory/scoped_ptr.h" 12 #include "chrome/common/remoting/chromoting_host_info.h" 13 #include "chrome/common/net/url_fetcher.h" 14 #include "googleurl/src/gurl.h" 15 16 namespace remoting { 17 18 // A class implements REST API insert call for the Chromoting directory service. 19 class DirectoryAddRequest : public URLFetcher::Delegate { 20 public: 21 enum Result { 22 // Host was added successfully. 23 SUCCESS, 24 // Invalid authentication token. 25 ERROR_AUTH, 26 // Server rejected request because it was invalid (e.g. specified 27 // public key is invalid). 28 ERROR_INVALID_REQUEST, 29 // Host is already registered. 30 ERROR_EXISTS, 31 // Internal server error. 32 ERROR_SERVER, 33 // Timeout expired. 34 ERROR_TIMEOUT_EXPIRED, 35 // Some other error, e.g. network failure. 36 ERROR_OTHER, 37 }; 38 39 // Callback called when request is finished. The second parameter 40 // contains error message in case of an error. The error message may 41 // not be localized, and should be used for logging, but not shown 42 // to the user. 43 typedef Callback2<Result, const std::string&>::Type DoneCallback; 44 45 explicit DirectoryAddRequest(net::URLRequestContextGetter* getter); 46 ~DirectoryAddRequest(); 47 48 // Add this computer as a host. Use the token for 49 // authentication. |done_callback| is called when the request is 50 // finished. Request can be cancelled by destroying this object. 51 void AddHost(const remoting::ChromotingHostInfo& host_info, 52 const std::string& auth_token, 53 DoneCallback* done_callback); 54 55 // URLFetcher::Delegate implementation. 56 virtual void OnURLFetchComplete(const URLFetcher* source, 57 const GURL& url, 58 const net::URLRequestStatus& status, 59 int response_code, 60 const ResponseCookies& cookies, 61 const std::string& data); 62 63 private: 64 friend class DirectoryAddRequestTest; 65 66 net::URLRequestContextGetter* getter_; 67 scoped_ptr<DoneCallback> done_callback_; 68 scoped_ptr<URLFetcher> fetcher_; 69 70 DISALLOW_COPY_AND_ASSIGN(DirectoryAddRequest); 71 }; 72 73 } // namespace remoting 74 75 #endif // CHROME_BROWSER_REMOTING_DIRECTORY_ADD_REQUEST_H_ 76