• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_GCD_PRIVATE_GCD_PRIVATE_API_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_GCD_PRIVATE_GCD_PRIVATE_API_H_
7 
8 #include "base/memory/scoped_ptr.h"
9 #include "chrome/browser/extensions/chrome_extension_function.h"
10 #include "chrome/browser/local_discovery/cloud_device_list_delegate.h"
11 #include "chrome/browser/local_discovery/gcd_api_flow.h"
12 #include "chrome/common/extensions/api/gcd_private.h"
13 #include "extensions/browser/browser_context_keyed_api_factory.h"
14 
15 namespace extensions {
16 
17 class GcdPrivateAPI : public BrowserContextKeyedAPI {
18  public:
19   class GCDApiFlowFactoryForTests {
20    public:
~GCDApiFlowFactoryForTests()21     virtual ~GCDApiFlowFactoryForTests() {}
22 
23     virtual scoped_ptr<local_discovery::GCDApiFlow> CreateGCDApiFlow() = 0;
24   };
25 
26   explicit GcdPrivateAPI(content::BrowserContext* context);
27   virtual ~GcdPrivateAPI();
28 
29   static void SetGCDApiFlowFactoryForTests(GCDApiFlowFactoryForTests* factory);
30 
31   // BrowserContextKeyedAPI implementation.
32   static BrowserContextKeyedAPIFactory<GcdPrivateAPI>* GetFactoryInstance();
33 
34  private:
35   friend class BrowserContextKeyedAPIFactory<GcdPrivateAPI>;
36 
37   // BrowserContextKeyedAPI implementation.
service_name()38   static const char* service_name() { return "GcdPrivateAPI"; }
39 
40   content::BrowserContext* const browser_context_;
41 };
42 
43 class GcdPrivateGetCloudDeviceListFunction
44     : public ChromeAsyncExtensionFunction,
45       public local_discovery::CloudDeviceListDelegate {
46  public:
47   DECLARE_EXTENSION_FUNCTION("gcdPrivate.getCloudDeviceList",
48                              FEEDBACKPRIVATE_GETSTRINGS)
49 
50   GcdPrivateGetCloudDeviceListFunction();
51 
52  protected:
53   virtual ~GcdPrivateGetCloudDeviceListFunction();
54 
55   // SyncExtensionFunction overrides.
56   virtual bool RunAsync() OVERRIDE;
57 
58  private:
59   // CloudDeviceListDelegate implementation
60   virtual void OnDeviceListReady(const DeviceList& devices) OVERRIDE;
61   virtual void OnDeviceListUnavailable() OVERRIDE;
62 
63   void CheckListingDone();
64 
65   int requests_succeeded_;
66   int requests_failed_;
67   DeviceList devices_;
68 
69   scoped_ptr<local_discovery::GCDApiFlow> printer_list_;
70   scoped_ptr<local_discovery::GCDApiFlow> device_list_;
71 };
72 
73 }  // namespace extensions
74 
75 #endif  // CHROME_BROWSER_EXTENSIONS_API_GCD_PRIVATE_GCD_PRIVATE_API_H_
76