Upstream version 9.38.204.0
[platform/framework/web/crosswalk.git] / src / xwalk / tizen / browser / media / browser_mediaplayer_manager.h
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Copyright (c) 2013 Intel Corporation. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5
6 #ifndef XWALK_TIZEN_BROWSER_MEDIA_BROWSER_MEDIAPLAYER_MANAGER_H_
7 #define XWALK_TIZEN_BROWSER_MEDIA_BROWSER_MEDIAPLAYER_MANAGER_H_
8
9 #include "base/memory/scoped_ptr.h"
10 #include "base/memory/scoped_vector.h"
11 #include "content/public/browser/web_contents_observer.h"
12 #include "url/gurl.h"
13 #include "xwalk/tizen/browser/media/murphy_resource_manager.h"
14 #include "xwalk/tizen/browser/media/murphy_resource.h"
15
16 namespace tizen {
17
18 // This class manages all MurphyResource objects in the browser process. It
19 // receives control operations from the render process, and forwards them to
20 // corresponding MurphyResource object. Callbacks from MurphyResource objects
21 // are converted to IPCs and then sent to the render process.
22 class CONTENT_EXPORT BrowserMediaPlayerManager {
23  public:
24   virtual ~BrowserMediaPlayerManager();
25
26   // Returns a new instance.
27   static BrowserMediaPlayerManager* Create(
28       content::RenderFrameHost* render_frame_host,
29       MurphyResourceManager* resource_manager);
30
31   virtual MurphyResource* GetMurphyResource(
32       MediaPlayerID player_id);
33
34   void ResourceNotifyCallback(mrp_res_resource_state_t state,
35       MediaPlayerID player_id);
36
37   int RoutingID();
38
39   // Helper function to send messages to RenderFrameObserver.
40   bool Send(IPC::Message* msg);
41
42   // Message handlers.
43   virtual void OnInitialize(MediaPlayerID player_id,
44       int process_id, const GURL& url);
45   virtual void OnDestroyPlayer(MediaPlayerID player_id);
46   virtual void OnPause(MediaPlayerID player_id);
47   virtual void OnStart(MediaPlayerID player_id);
48
49  protected:
50   explicit BrowserMediaPlayerManager(
51       content::RenderFrameHost* render_frame_host,
52       MurphyResourceManager* resource_manager);
53
54  private:
55   // Adds a murphy resource for the given player to the list.
56   void AddMurphyResource(MurphyResource* resource);
57
58   // Removes the murphy resource of given |player_id|.
59   void RemoveMurphyResource(MediaPlayerID player_id);
60
61   content::RenderFrameHost* const render_frame_host_;
62
63   MurphyResourceManager* resource_manager_;
64   ScopedVector<MurphyResource> murphy_resources_;
65
66   DISALLOW_COPY_AND_ASSIGN(BrowserMediaPlayerManager);
67 };
68
69 }  // namespace tizen
70
71 #endif  // XWALK_TIZEN_BROWSER_MEDIA_BROWSER_MEDIAPLAYER_MANAGER_H_