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_PRIVETV3_SESSION_H_ 6 #define CHROME_BROWSER_LOCAL_DISCOVERY_PRIVETV3_SESSION_H_ 7 8 #include <string> 9 10 #include "base/callback.h" 11 #include "base/memory/scoped_ptr.h" 12 13 namespace base { 14 class DictionaryValue; 15 } 16 17 namespace local_discovery { 18 19 class PrivetV3HTTPClient; 20 21 // Manages secure communication between browser and local Privet device. 22 class PrivetV3Session { 23 public: 24 typedef base::Callback< 25 void(bool success, const base::DictionaryValue& response)> 26 RequestCallback; 27 28 // Delegate to be implemented by client code. 29 class Delegate { 30 public: 31 typedef base::Callback<void(bool confirm)> ConfirmationCallback; 32 33 virtual ~Delegate(); 34 35 // Called when client code should prompt user to check |confirmation_code|. 36 virtual void OnSetupConfirmationNeeded( 37 const std::string& confirmation_code, 38 const ConfirmationCallback& callback) = 0; 39 40 // Called when session successfully establish and client code my call 41 // |CreateRequest| method. 42 virtual void OnSessionEstablished() = 0; 43 44 // Called when session setup fails. 45 virtual void OnCannotEstablishSession() = 0; 46 }; 47 48 // Represents request in progress using secure session. 49 class Request { 50 public: 51 virtual ~Request(); 52 virtual void Start() = 0; 53 }; 54 55 PrivetV3Session(scoped_ptr<PrivetV3HTTPClient> client, Delegate* delegate); 56 ~PrivetV3Session(); 57 58 // Establishes a session, will call |OnSetupConfirmationNeeded| and then 59 // |OnSessionEstablished|. 60 void Start(); 61 62 // Create a single /privet/v3/session/call request. 63 // Must be called only after receiving |OnSessionEstablished|. 64 scoped_ptr<Request> CreateRequest(const std::string& api_name, 65 const base::DictionaryValue& request, 66 const RequestCallback& callback); 67 68 private: 69 DISALLOW_COPY_AND_ASSIGN(PrivetV3Session); 70 }; 71 72 } // namespace local_discovery 73 74 #endif // CHROME_BROWSER_LOCAL_DISCOVERY_PRIVETV3_SESSION_H_ 75