Add GCMChannelStatusSyncer to schedule requests and enable/disable GCM
[chromium-blink-merge.git] / chrome / browser / local_discovery / privetv3_session.h
blob91771b105f5f4f301c56da4f367bc054af8d832a
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"
13 #include "chrome/common/extensions/api/gcd_private.h"
15 namespace base {
16 class DictionaryValue;
19 namespace local_discovery {
21 class PrivetHTTPClient;
23 // Manages secure communication between browser and local Privet device.
24 class PrivetV3Session {
25 private:
26 class FetcherDelegate;
28 public:
29 // Delegate to be implemented by client code.
30 class Delegate {
31 public:
32 virtual ~Delegate();
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.
44 class Request {
45 public:
46 Request();
47 virtual ~Request();
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,
53 bool has_error) = 0;
55 private:
56 friend class PrivetV3Session;
57 scoped_ptr<FetcherDelegate> fetcher_delegate_;
60 PrivetV3Session(scoped_ptr<PrivetHTTPClient> client, Delegate* delegate);
61 ~PrivetV3Session();
63 // Establishes a session, will call |OnSetupConfirmationNeeded| and then
64 // |OnSessionEstablished|.
65 void Start();
67 void ConfirmCode(const std::string& code);
69 // Create a single /privet/v3/session/call request.
70 void StartRequest(Request* request);
72 private:
73 void ConfirmFakeCode();
75 Delegate* delegate_;
76 scoped_ptr<PrivetHTTPClient> client_;
77 bool code_confirmed_;
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_