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"
15 class DictionaryValue
;
18 namespace local_discovery
{
20 class PrivetHTTPClient
;
22 // Manages secure communication between browser and local Privet device.
23 class PrivetV3Session
{
25 class FetcherDelegate
;
28 // Delegate to be implemented by client code.
33 // Called when client code should prompt user to check |confirmation_code|.
34 virtual void OnSetupConfirmationNeeded(
35 const std::string
& confirmation_code
) = 0;
37 // Called when session successfully establish and client code my call
38 // |CreateRequest| method.
39 virtual void OnSessionEstablished() = 0;
41 // Called when session setup fails.
42 virtual void OnCannotEstablishSession() = 0;
45 // Represents request in progress using secure session.
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
,
58 friend class PrivetV3Session
;
59 scoped_ptr
<FetcherDelegate
> fetcher_delegate_
;
62 PrivetV3Session(scoped_ptr
<PrivetHTTPClient
> client
, Delegate
* delegate
);
65 // Establishes a session, will call |OnSetupConfirmationNeeded| and then
66 // |OnSessionEstablished|.
71 // Create a single /privet/v3/session/call request.
72 void StartRequest(Request
* request
);
75 void ConfirmFakeCode();
78 scoped_ptr
<PrivetHTTPClient
> client_
;
80 base::WeakPtrFactory
<PrivetV3Session
> weak_ptr_factory_
;
81 DISALLOW_COPY_AND_ASSIGN(PrivetV3Session
);
84 } // namespace local_discovery
86 #endif // CHROME_BROWSER_LOCAL_DISCOVERY_PRIVETV3_SESSION_H_