Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(51)

Side by Side Diff: chrome/browser/local_discovery/privetv3_session.h

Issue 383023002: Partial setup flow with unittest. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_LOCAL_DISCOVERY_PRIVETV3_SESSION_H_ 5 #ifndef CHROME_BROWSER_LOCAL_DISCOVERY_PRIVETV3_SESSION_H_
6 #define CHROME_BROWSER_LOCAL_DISCOVERY_PRIVETV3_SESSION_H_ 6 #define CHROME_BROWSER_LOCAL_DISCOVERY_PRIVETV3_SESSION_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "chrome/browser/local_discovery/privet_url_fetcher.h"
12 13
13 namespace base { 14 namespace base {
14 class DictionaryValue; 15 class DictionaryValue;
15 } 16 }
16 17
17 namespace local_discovery { 18 namespace local_discovery {
18 19
19 class PrivetHTTPClient; 20 class PrivetHTTPClient;
20 21
21 // Manages secure communication between browser and local Privet device. 22 // Manages secure communication between browser and local Privet device.
22 class PrivetV3Session { 23 class PrivetV3Session {
24 private:
25 class FetcherDelegate;
26
23 public: 27 public:
24 typedef base::Callback<
25 void(bool success, const base::DictionaryValue& response)>
26 RequestCallback;
27
28 // Delegate to be implemented by client code. 28 // Delegate to be implemented by client code.
29 class Delegate { 29 class Delegate {
30 public: 30 public:
31 typedef base::Callback<void(bool confirm)> ConfirmationCallback;
32
33 virtual ~Delegate(); 31 virtual ~Delegate();
34 32
35 // Called when client code should prompt user to check |confirmation_code|. 33 // Called when client code should prompt user to check |confirmation_code|.
36 virtual void OnSetupConfirmationNeeded( 34 virtual void OnSetupConfirmationNeeded(
37 const std::string& confirmation_code, 35 const std::string& confirmation_code) = 0;
38 const ConfirmationCallback& callback) = 0;
39 36
40 // Called when session successfully establish and client code my call 37 // Called when session successfully establish and client code my call
41 // |CreateRequest| method. 38 // |CreateRequest| method.
42 virtual void OnSessionEstablished() = 0; 39 virtual void OnSessionEstablished() = 0;
43 40
44 // Called when session setup fails. 41 // Called when session setup fails.
45 virtual void OnCannotEstablishSession() = 0; 42 virtual void OnCannotEstablishSession() = 0;
46 }; 43 };
47 44
48 // Represents request in progress using secure session. 45 // Represents request in progress using secure session.
49 class Request { 46 class Request {
50 public: 47 public:
48 Request();
51 virtual ~Request(); 49 virtual ~Request();
52 virtual void Start() = 0; 50
51 virtual std::string GetName() = 0;
52 virtual const base::DictionaryValue& GetInput() = 0;
53 virtual void OnError(PrivetURLFetcher::ErrorType error) = 0;
54 virtual void OnParsedJson(const base::DictionaryValue& value,
55 bool has_error) = 0;
56
57 private:
58 friend class PrivetV3Session;
59 scoped_ptr<FetcherDelegate> fetcher_delegate_;
53 }; 60 };
54 61
55 PrivetV3Session(scoped_ptr<PrivetHTTPClient> client, Delegate* delegate); 62 PrivetV3Session(scoped_ptr<PrivetHTTPClient> client, Delegate* delegate);
56 ~PrivetV3Session(); 63 ~PrivetV3Session();
57 64
58 // Establishes a session, will call |OnSetupConfirmationNeeded| and then 65 // Establishes a session, will call |OnSetupConfirmationNeeded| and then
59 // |OnSessionEstablished|. 66 // |OnSessionEstablished|.
60 void Start(); 67 void Start();
61 68
69 void ConfirmCode();
70
62 // Create a single /privet/v3/session/call request. 71 // Create a single /privet/v3/session/call request.
63 // Must be called only after receiving |OnSessionEstablished|. 72 void StartRequest(Request* request);
64 scoped_ptr<Request> CreateRequest(const std::string& api_name,
65 const base::DictionaryValue& request,
66 const RequestCallback& callback);
67 73
68 private: 74 private:
75 Delegate* delegate_;
76 scoped_ptr<PrivetHTTPClient> client_;
77 bool code_confirmed_;
78 base::WeakPtrFactory<PrivetV3Session> weak_ptr_factory_;
69 DISALLOW_COPY_AND_ASSIGN(PrivetV3Session); 79 DISALLOW_COPY_AND_ASSIGN(PrivetV3Session);
70 }; 80 };
71 81
72 } // namespace local_discovery 82 } // namespace local_discovery
73 83
74 #endif // CHROME_BROWSER_LOCAL_DISCOVERY_PRIVETV3_SESSION_H_ 84 #endif // CHROME_BROWSER_LOCAL_DISCOVERY_PRIVETV3_SESSION_H_
OLDNEW
« no previous file with comments | « chrome/browser/local_discovery/privet_url_fetcher.cc ('k') | chrome/browser/local_discovery/privetv3_session.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698