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.
5 #ifndef CHROME_BROWSER_LOCAL_DISCOVERY_PRIVETV3_SESSION_H_
6 #define CHROME_BROWSER_LOCAL_DISCOVERY_PRIVETV3_SESSION_H_
10 #include "base/callback.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "chrome/browser/local_discovery/privet_url_fetcher.h"
13 #include "chrome/common/extensions/api/gcd_private.h"
16 class DictionaryValue
;
19 namespace local_discovery
{
21 class PrivetHTTPClient
;
23 // Manages secure communication between browser and local Privet device.
24 class PrivetV3Session
{
26 class FetcherDelegate
;
29 // Delegate to be implemented by client code.
34 // Called when client code should prompt user to check |confirmation_code|.
35 virtual void OnSetupConfirmationNeeded(
36 const std::string
& confirmation_code
,
37 extensions::api::gcd_private::ConfirmationType confirmation_type
) = 0;
39 virtual void OnSessionStatus(
40 extensions::api::gcd_private::Status status
) = 0;
43 // Represents request in progress using secure session.
49 virtual std::string
GetName() = 0;
50 virtual const base::DictionaryValue
& GetInput() = 0;
51 virtual void OnError(PrivetURLFetcher::ErrorType error
) = 0;
52 virtual void OnParsedJson(const base::DictionaryValue
& value
,
56 friend class PrivetV3Session
;
57 scoped_ptr
<FetcherDelegate
> fetcher_delegate_
;
60 PrivetV3Session(scoped_ptr
<PrivetHTTPClient
> client
, Delegate
* delegate
);
63 // Establishes a session, will call |OnSetupConfirmationNeeded| and then
64 // |OnSessionEstablished|.
67 void ConfirmCode(const std::string
& code
);
69 // Create a single /privet/v3/session/call request.
70 void StartRequest(Request
* request
);
73 void ConfirmFakeCode();
76 scoped_ptr
<PrivetHTTPClient
> client_
;
78 base::WeakPtrFactory
<PrivetV3Session
> weak_ptr_factory_
;
79 DISALLOW_COPY_AND_ASSIGN(PrivetV3Session
);
82 } // namespace local_discovery
84 #endif // CHROME_BROWSER_LOCAL_DISCOVERY_PRIVETV3_SESSION_H_