OLD | NEW |
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 #include "chrome/browser/local_discovery/privet_url_fetcher.h" |
| 13 #include "chrome/common/extensions/api/gcd_private.h" |
13 | 14 |
14 namespace base { | 15 namespace base { |
15 class DictionaryValue; | 16 class DictionaryValue; |
16 } | 17 } |
17 | 18 |
18 namespace local_discovery { | 19 namespace local_discovery { |
19 | 20 |
20 class PrivetHTTPClient; | 21 class PrivetHTTPClient; |
21 | 22 |
22 // Manages secure communication between browser and local Privet device. | 23 // Manages secure communication between browser and local Privet device. |
23 class PrivetV3Session { | 24 class PrivetV3Session { |
24 private: | 25 private: |
25 class FetcherDelegate; | 26 class FetcherDelegate; |
26 | 27 |
27 public: | 28 public: |
28 // Delegate to be implemented by client code. | 29 // Delegate to be implemented by client code. |
29 class Delegate { | 30 class Delegate { |
30 public: | 31 public: |
31 virtual ~Delegate(); | 32 virtual ~Delegate(); |
32 | 33 |
33 // Called when client code should prompt user to check |confirmation_code|. | 34 // Called when client code should prompt user to check |confirmation_code|. |
34 virtual void OnSetupConfirmationNeeded( | 35 virtual void OnSetupConfirmationNeeded( |
35 const std::string& confirmation_code) = 0; | 36 const std::string& confirmation_code, |
| 37 extensions::api::gcd_private::ConfirmationType confirmation_type) = 0; |
36 | 38 |
37 // Called when session successfully establish and client code my call | 39 virtual void OnSessionStatus( |
38 // |CreateRequest| method. | 40 extensions::api::gcd_private::Status status) = 0; |
39 virtual void OnSessionEstablished() = 0; | |
40 | |
41 // Called when session setup fails. | |
42 virtual void OnCannotEstablishSession() = 0; | |
43 }; | 41 }; |
44 | 42 |
45 // Represents request in progress using secure session. | 43 // Represents request in progress using secure session. |
46 class Request { | 44 class Request { |
47 public: | 45 public: |
48 Request(); | 46 Request(); |
49 virtual ~Request(); | 47 virtual ~Request(); |
50 | 48 |
51 virtual std::string GetName() = 0; | 49 virtual std::string GetName() = 0; |
52 virtual const base::DictionaryValue& GetInput() = 0; | 50 virtual const base::DictionaryValue& GetInput() = 0; |
53 virtual void OnError(PrivetURLFetcher::ErrorType error) = 0; | 51 virtual void OnError(PrivetURLFetcher::ErrorType error) = 0; |
54 virtual void OnParsedJson(const base::DictionaryValue& value, | 52 virtual void OnParsedJson(const base::DictionaryValue& value, |
55 bool has_error) = 0; | 53 bool has_error) = 0; |
56 | 54 |
57 private: | 55 private: |
58 friend class PrivetV3Session; | 56 friend class PrivetV3Session; |
59 scoped_ptr<FetcherDelegate> fetcher_delegate_; | 57 scoped_ptr<FetcherDelegate> fetcher_delegate_; |
60 }; | 58 }; |
61 | 59 |
62 PrivetV3Session(scoped_ptr<PrivetHTTPClient> client, Delegate* delegate); | 60 PrivetV3Session(scoped_ptr<PrivetHTTPClient> client, Delegate* delegate); |
63 ~PrivetV3Session(); | 61 ~PrivetV3Session(); |
64 | 62 |
65 // Establishes a session, will call |OnSetupConfirmationNeeded| and then | 63 // Establishes a session, will call |OnSetupConfirmationNeeded| and then |
66 // |OnSessionEstablished|. | 64 // |OnSessionEstablished|. |
67 void Start(); | 65 void Start(); |
68 | 66 |
69 void ConfirmCode(); | 67 void ConfirmCode(const std::string& code); |
70 | 68 |
71 // Create a single /privet/v3/session/call request. | 69 // Create a single /privet/v3/session/call request. |
72 void StartRequest(Request* request); | 70 void StartRequest(Request* request); |
73 | 71 |
74 private: | 72 private: |
75 void ConfirmFakeCode(); | 73 void ConfirmFakeCode(); |
76 | 74 |
77 Delegate* delegate_; | 75 Delegate* delegate_; |
78 scoped_ptr<PrivetHTTPClient> client_; | 76 scoped_ptr<PrivetHTTPClient> client_; |
79 bool code_confirmed_; | 77 bool code_confirmed_; |
80 base::WeakPtrFactory<PrivetV3Session> weak_ptr_factory_; | 78 base::WeakPtrFactory<PrivetV3Session> weak_ptr_factory_; |
81 DISALLOW_COPY_AND_ASSIGN(PrivetV3Session); | 79 DISALLOW_COPY_AND_ASSIGN(PrivetV3Session); |
82 }; | 80 }; |
83 | 81 |
84 } // namespace local_discovery | 82 } // namespace local_discovery |
85 | 83 |
86 #endif // CHROME_BROWSER_LOCAL_DISCOVERY_PRIVETV3_SESSION_H_ | 84 #endif // CHROME_BROWSER_LOCAL_DISCOVERY_PRIVETV3_SESSION_H_ |
OLD | NEW |