Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / extensions / api / streams_private / streams_private_api.h
1 // Copyright (c) 2012 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_STREAMS_PRIVATE_STREAMS_PRIVATE_API_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_STREAMS_PRIVATE_STREAMS_PRIVATE_API_H_
7
8 #include <map>
9 #include <string>
10
11 #include "base/scoped_observer.h"
12 #include "extensions/browser/browser_context_keyed_api_factory.h"
13 #include "extensions/browser/extension_function.h"
14 #include "extensions/browser/extension_registry_observer.h"
15
16 namespace content {
17 class BrowserContext;
18 class StreamHandle;
19 }
20
21 namespace extensions {
22 class ExtensionRegistry;
23
24 class StreamsPrivateAPI : public BrowserContextKeyedAPI,
25                           public ExtensionRegistryObserver {
26  public:
27   // Convenience method to get the StreamsPrivateAPI for a BrowserContext.
28   static StreamsPrivateAPI* Get(content::BrowserContext* context);
29
30   explicit StreamsPrivateAPI(content::BrowserContext* context);
31   virtual ~StreamsPrivateAPI();
32
33   void ExecuteMimeTypeHandler(const std::string& extension_id,
34                               content::WebContents* web_contents,
35                               scoped_ptr<content::StreamHandle> stream,
36                               int64 expected_content_size);
37
38   // BrowserContextKeyedAPI implementation.
39   static BrowserContextKeyedAPIFactory<StreamsPrivateAPI>* GetFactoryInstance();
40
41  private:
42   friend class BrowserContextKeyedAPIFactory<StreamsPrivateAPI>;
43   typedef std::map<std::string,
44                    std::map<GURL,
45                             linked_ptr<content::StreamHandle> > > StreamMap;
46
47   // ExtensionRegistryObserver implementation.
48   virtual void OnExtensionUnloaded(
49       content::BrowserContext* browser_context,
50       const Extension* extension,
51       UnloadedExtensionInfo::Reason reason) OVERRIDE;
52
53   // BrowserContextKeyedAPI implementation.
54   static const char* service_name() {
55     return "StreamsPrivateAPI";
56   }
57   static const bool kServiceIsNULLWhileTesting = true;
58   static const bool kServiceRedirectedInIncognito = true;
59
60   content::BrowserContext* const browser_context_;
61   StreamMap streams_;
62   base::WeakPtrFactory<StreamsPrivateAPI> weak_ptr_factory_;
63
64   // Listen to extension unloaded notifications.
65   ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
66       extension_registry_observer_;
67 };
68
69 }  // namespace extensions
70
71 #endif  // CHROME_BROWSER_EXTENSIONS_API_STREAMS_PRIVATE_STREAMS_PRIVATE_API_H_