Update mojo surfaces bindings and mojo/cc/ glue
[chromium-blink-merge.git] / chrome / browser / local_discovery / privetv3_session.h
blobb6631a27a12b37a206678333f8a1ef2c73385d94
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_
8 #include <string>
10 #include "base/callback.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "chrome/browser/local_discovery/privet_url_fetcher.h"
14 namespace base {
15 class DictionaryValue;
18 namespace local_discovery {
20 class PrivetHTTPClient;
22 // Manages secure communication between browser and local Privet device.
23 class PrivetV3Session {
24 private:
25 class FetcherDelegate;
27 public:
28 // Delegate to be implemented by client code.
29 class Delegate {
30 public:
31 virtual ~Delegate();
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.
46 class Request {
47 public:
48 Request();
49 virtual ~Request();
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;
57 private:
58 friend class PrivetV3Session;
59 scoped_ptr<FetcherDelegate> fetcher_delegate_;
62 PrivetV3Session(scoped_ptr<PrivetHTTPClient> client, Delegate* delegate);
63 ~PrivetV3Session();
65 // Establishes a session, will call |OnSetupConfirmationNeeded| and then
66 // |OnSessionEstablished|.
67 void Start();
69 void ConfirmCode();
71 // Create a single /privet/v3/session/call request.
72 void StartRequest(Request* request);
74 private:
75 void ConfirmFakeCode();
77 Delegate* delegate_;
78 scoped_ptr<PrivetHTTPClient> client_;
79 bool code_confirmed_;
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_