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

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

Issue 695253002: chrome.gcdPrivate allows app to choose pairing method. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Mon Nov 3 17:47:42 PST 2014 Created 6 years, 1 month 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
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 "base/memory/scoped_vector.h"
12 #include "chrome/browser/local_discovery/privet_url_fetcher.h" 13 #include "chrome/browser/local_discovery/privet_url_fetcher.h"
13 #include "chrome/common/extensions/api/gcd_private.h" 14 #include "chrome/common/extensions/api/gcd_private.h"
14 15
15 namespace base { 16 namespace base {
16 class DictionaryValue; 17 class DictionaryValue;
17 } 18 }
18 19
19 namespace local_discovery { 20 namespace local_discovery {
20 21
21 class PrivetHTTPClient; 22 class PrivetHTTPClient;
22 23
23 // Manages secure communication between browser and local Privet device. 24 // Manages secure communication between browser and local Privet device.
24 class PrivetV3Session { 25 class PrivetV3Session {
25 private: 26 private:
26 class FetcherDelegate; 27 class FetcherDelegate;
27 28
28 public: 29 public:
29 // Delegate to be implemented by client code. 30 typedef extensions::api::gcd_private::PairingType PairingType;
30 class Delegate { 31 typedef extensions::api::gcd_private::Status Result;
31 public:
32 virtual ~Delegate();
33 32
34 // Called when client code should prompt user to check |confirmation_code|. 33 typedef base::Callback<
35 virtual void OnSetupConfirmationNeeded( 34 void(Result result, const std::vector<PairingType>& types)> InitCallback;
36 const std::string& confirmation_code,
37 extensions::api::gcd_private::ConfirmationType confirmation_type) = 0;
38 35
39 virtual void OnSessionStatus( 36 typedef base::Callback<void(Result result)> ResultCallback;
40 extensions::api::gcd_private::Status status) = 0; 37 typedef base::Callback<void(Result result,
41 }; 38 const base::DictionaryValue& response)>
39 MessageCallback;
42 40
41 explicit PrivetV3Session(scoped_ptr<PrivetHTTPClient> client);
42 ~PrivetV3Session();
43
44 // Initialized session.
45 void Init(const InitCallback& callback);
46
47 void StartPairing(PairingType pairing_type, const ResultCallback& callback);
48
49 void ConfirmCode(const std::string& code, const ResultCallback& callback);
50
51 // Create a single /privet/v3/session/call request.
52 void SendMessage(const std::string& api,
53 const base::DictionaryValue& input,
54 const MessageCallback& callback);
55
56 private:
43 // Represents request in progress using secure session. 57 // Represents request in progress using secure session.
44 class Request { 58 class Request {
45 public: 59 public:
46 Request(); 60 Request();
47 virtual ~Request(); 61 virtual ~Request();
48 62
49 virtual std::string GetName() = 0;
50 virtual const base::DictionaryValue& GetInput() = 0;
51 virtual void OnError() = 0; 63 virtual void OnError() = 0;
52 virtual void OnParsedJson(const base::DictionaryValue& value, 64 virtual void OnParsedJson(const base::DictionaryValue& value,
53 bool has_error) = 0; 65 bool has_error) = 0;
54 66
55 private: 67 private:
56 friend class PrivetV3Session; 68 friend class PrivetV3Session;
57 scoped_ptr<FetcherDelegate> fetcher_delegate_; 69 scoped_ptr<FetcherDelegate> fetcher_delegate_;
58 }; 70 };
59 71
60 PrivetV3Session(scoped_ptr<PrivetHTTPClient> client, Delegate* delegate); 72 void RunCallback(const base::Closure& callback);
61 ~PrivetV3Session(); 73 void DeleteFetcher(const FetcherDelegate* fetcher);
62 74
63 // Establishes a session, will call |OnSetupConfirmationNeeded| and then
64 // |OnSessionEstablished|.
65 void Start();
66
67 void ConfirmCode(const std::string& code);
68
69 // Create a single /privet/v3/session/call request.
70 void StartRequest(Request* request);
71
72 private:
73 void ConfirmFakeCode();
74
75 Delegate* delegate_;
76 scoped_ptr<PrivetHTTPClient> client_; 75 scoped_ptr<PrivetHTTPClient> client_;
77 bool code_confirmed_; 76 bool code_confirmed_;
77 ScopedVector<FetcherDelegate> fetchers_;
78 base::WeakPtrFactory<PrivetV3Session> weak_ptr_factory_; 78 base::WeakPtrFactory<PrivetV3Session> weak_ptr_factory_;
79 DISALLOW_COPY_AND_ASSIGN(PrivetV3Session); 79 DISALLOW_COPY_AND_ASSIGN(PrivetV3Session);
80 }; 80 };
81 81
82 } // namespace local_discovery 82 } // namespace local_discovery
83 83
84 #endif // CHROME_BROWSER_LOCAL_DISCOVERY_PRIVETV3_SESSION_H_ 84 #endif // CHROME_BROWSER_LOCAL_DISCOVERY_PRIVETV3_SESSION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698